Remove unused license preamble
[mygpo.git] / mygpo / data / youtube.py
blobe6d7645b3f1c3fa1c45271a20937d905d814f62c
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
4 # taken from gPodder :)
6 import re
7 import urllib.request, urllib.parse, urllib.error
9 def is_video_link(url):
10 return (get_youtube_id(url) is not None)
12 def get_youtube_id(url):
13 if url is None:
14 return None
16 r = re.compile('http://(?:[a-z]+\.)?youtube\.com/v/(.*)\.swf', re.IGNORECASE).match(url)
17 if r is not None:
18 return r.group(1)
20 r = re.compile('http://(?:[a-z]+\.)?youtube\.com/watch\?v=([^&]*)', re.IGNORECASE).match(url)
21 if r is not None:
22 return r.group(1)
24 return None
27 def get_real_cover(url):
28 rs = [re.compile('http://www\\.youtube\\.com/rss/user/([^/]+)/videos\\.rss', re.IGNORECASE),
29 re.compile('http://www\\.youtube\\.com/profile_videos\\?user=([^\&]+)', re.IGNORECASE)]
31 for r in rs:
32 m = r.match(url)
33 if m is None:
34 continue
35 username = m.group(1)
36 api_url = 'http://gdata.youtube.com/feeds/api/users/%s?v=2' % username
37 data = urllib.request.urlopen(api_url).read()
38 match = re.search('<media:thumbnail url=[\'"]([^\'"]+)[\'"]/>', data)
39 if match is not None:
40 return match.group(1)
42 return None