|
|
|
|
@ -18,28 +18,33 @@ def youtube_logger(mfrom,msg): |
|
|
|
|
if brathuhn.room_nick in unicode(mfrom): |
|
|
|
|
return |
|
|
|
|
groups=re.findall(URL,unicode(msg.getBody())) |
|
|
|
|
if groups: |
|
|
|
|
for g in groups: |
|
|
|
|
url = g[0] |
|
|
|
|
addr = g[2] |
|
|
|
|
protocol = g[1] |
|
|
|
|
file = g[4] |
|
|
|
|
if addr in ['youtube.com','www.youtube.com','youtu.be']: |
|
|
|
|
yt_service = gdata.youtube.service.YouTubeService() |
|
|
|
|
id = get_id_from_url(url) |
|
|
|
|
print "youtube link",id |
|
|
|
|
entry = yt_service.GetYouTubeVideoEntry(video_id=id) |
|
|
|
|
sec = int(entry.media.duration.seconds) |
|
|
|
|
duration = "%02d:%02d:%02d" % (sec/3600, (sec%3600)/60, (sec%3600)%60) |
|
|
|
|
txt = "%s posted a youtube video: %s\nTitle: %s\nCategory: %s\nTags: %s\nDuration: %s\nViews: %s\nRating: %s" % (mfrom.getResource(), |
|
|
|
|
entry.media.player.url, |
|
|
|
|
entry.media.title.text, |
|
|
|
|
entry.media.category[0].text, |
|
|
|
|
entry.media.keywords.text, |
|
|
|
|
duration, |
|
|
|
|
entry.statistics.view_count, |
|
|
|
|
entry.rating.average) |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,txt,'groupchat') |
|
|
|
|
|
|
|
|
|
tmp = {} |
|
|
|
|
for g in groups: |
|
|
|
|
url = g[0] |
|
|
|
|
addr = g[2] |
|
|
|
|
protocol = g[1] |
|
|
|
|
file = g[4] |
|
|
|
|
if protocol in ['http','https'] and addr in ['youtube.com','www.youtube.com','youtu.be']: |
|
|
|
|
yt_service = gdata.youtube.service.YouTubeService() |
|
|
|
|
id = get_id_from_url(url) |
|
|
|
|
# prevent doubles |
|
|
|
|
if id in tmp: |
|
|
|
|
continue |
|
|
|
|
tmp[id]=True |
|
|
|
|
print "youtube link",id |
|
|
|
|
entry = yt_service.GetYouTubeVideoEntry(video_id=id) |
|
|
|
|
sec = int(entry.media.duration.seconds) |
|
|
|
|
duration = "%02d:%02d:%02d" % (sec/3600, (sec%3600)/60, (sec%3600)%60) |
|
|
|
|
txt = "%s posted a youtube video: %s\nTitle: %s\nCategory: %s\nTags: %s\nDuration: %s\nViews: %s\nRating: %s" % (mfrom.getResource(), |
|
|
|
|
entry.media.player.url, |
|
|
|
|
entry.media.title.text, |
|
|
|
|
entry.media.category[0].text, |
|
|
|
|
entry.media.keywords.text, |
|
|
|
|
duration, |
|
|
|
|
entry.statistics.view_count, |
|
|
|
|
entry.rating.average) |
|
|
|
|
brathuhn.sendMsg(brathuhn.ROOM,txt,'groupchat') |
|
|
|
|
brathuhn.addGroupListener(youtube_logger) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|