2 # -*- coding: utf-8 -*-
4 # taken from gPodder :)
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
):
16 r
= re
.compile('http://(?:[a-z]+\.)?youtube\.com/v/(.*)\.swf', re
.IGNORECASE
).match(url
)
20 r
= re
.compile('http://(?:[a-z]+\.)?youtube\.com/watch\?v=([^&]*)', re
.IGNORECASE
).match(url
)
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
)]
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
)