1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2008 Thomas Perl and the gPodder Team
6 # gPodder is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # gPodder is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # resolver.py -- YouTube and related magic
20 # Justin Forest <justin.forest@gmail.com> 2008-10-13
25 # * Support for Vimeo, maybe blip.tv and others.
29 from gpodder
.liblogger
import log
30 from gpodder
.util
import proxy_request
34 def get_real_download_url(url
, proxy
=None):
35 if 'youtube-episode' not in rr
:
36 rr
['youtube-episode'] = re
.compile('http://(?:[a-z]+\.)?youtube\.com/v/.*\.swf', re
.IGNORECASE
)
38 if rr
['youtube-episode'].match(url
):
39 req
= proxy_request(url
, proxy
)
41 if 'location' in req
.msg
:
42 id, tag
= (None, None)
44 for part
in req
.msg
['location'].split('&'):
45 if part
.startswith('video_id='):
47 elif part
.startswith('t='):
50 if id is not None and tag
is not None:
51 next
= 'http://www.youtube.com/get_video?video_id='+ id +'&t='+ tag
+'&fmt=18'
52 log('YouTube link resolved: %s => %s', url
, next
)
57 def get_real_channel_url(url
):
58 r
= re
.compile('http://(?:[a-z]+\.)?youtube\.com/user/([a-z0-9]+)', re
.IGNORECASE
)
62 next
= 'http://www.youtube.com/rss/user/'+ m
.group(1) +'/videos.rss'
63 log('YouTube link resolved: %s => %s', url
, next
)
66 r
= re
.compile('http://(?:[a-z]+\.)?youtube\.com/profile?user=([a-z0-9]+)', re
.IGNORECASE
)
70 next
= 'http://www.youtube.com/rss/user/'+ m
.group(1) +'/videos.rss'
71 log('YouTube link resolved: %s => %s', url
, next
)
76 def get_real_cover(url
):
79 r
= re
.compile('http://www\.youtube\.com/rss/user/([a-z0-9]+)/videos\.rss', re
.IGNORECASE
)
83 data
= urllib2
.urlopen('http://www.youtube.com/user/'+ m
.group(1)).read()
84 data
= data
[data
.find('id="user-profile-image"'):]
85 data
= data
[data
.find('src="') + 5:]
87 next
= data
[:data
.find('"')]
89 if next
.strip() == '':
92 log('YouTube userpic for %s is: %s', url
, next
)