YouTube integration.
[gpodder.git] / src / gpodder / resolver.py
blob4458afbce91dd010367eddd49698b98210a0e512
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
22 # TODO:
24 # * Channel covers.
25 # * Support for Vimeo, maybe blip.tv and others.
27 import re
28 from gpodder.liblogger import log
29 from gpodder.util import proxy_request
31 rr = {}
33 def get_real_download_url(url, proxy=None):
34 if 'youtube-episode' not in rr:
35 rr['youtube-episode'] = re.compile('http://(?:[a-z]+\.)?youtube\.com/v/.*\.swf', re.IGNORECASE)
37 if rr['youtube-episode'].match(url):
38 req = proxy_request(url, proxy)
40 if 'location' in req.msg:
41 id, tag = (None, None)
43 for part in req.msg['location'].split('&'):
44 if part.startswith('video_id='):
45 id = part[9:]
46 elif part.startswith('t='):
47 tag = part[2:]
49 if id is not None and tag is not None:
50 next = 'http://www.youtube.com/get_video?video_id='+ id +'&t='+ tag +'&fmt=18'
51 log('YouTube link resolved: %s => %s', url, next)
52 return next
54 return url
56 def get_real_channel_url(url):
57 r = re.compile('http://(?:[a-z]+\.)?youtube\.com/user/([a-z0-9]+)', re.IGNORECASE)
58 m = r.match(url)
60 if m is not None:
61 next = 'http://www.youtube.com/rss/user/'+ m.group(1) +'/videos.rss'
62 log('YouTube link resolved: %s => %s', url, next)
63 return next
65 r = re.compile('http://(?:[a-z]+\.)?youtube\.com/profile?user=([a-z0-9]+)', re.IGNORECASE)
66 m = r.match(url)
68 if m is not None:
69 next = 'http://www.youtube.com/rss/user/'+ m.group(1) +'/videos.rss'
70 log('YouTube link resolved: %s => %s', url, next)
71 return next
73 return url