Merge lp:~stefanor/ibid/youtube into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Jonathan Hitchcock
Approved revision: not available
Merged at revision: 775
Proposed branch: lp:~stefanor/ibid/youtube
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: 44 lines (+28/-1)
1 file modified
ibid/plugins/google.py (+28/-1)
To merge this branch: bzr merge lp:~stefanor/ibid/youtube
Reviewer Review Type Date Requested Status
Jonathan Hitchcock Approve
Michael Gorven Approve
Review via email: mp+15516@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Gorven (mgorven) wrote :

Took me a couple seconds to work out why it was in the 'google' plugin :-)
 review approve

review: Approve
Revision history for this message
Jonathan Hitchcock (vhata) wrote :

It probably shouldn't reeeeeeaaaally be in the google plugin. We do need to reorder these. But this is great for now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/google.py'
2--- ibid/plugins/google.py 2009-10-16 16:18:42 +0000
3+++ ibid/plugins/google.py 2009-12-01 22:25:22 +0000
4@@ -1,7 +1,8 @@
5 from cgi import parse_qs
6 from httplib import BadStatusLine
7+import re
8 from urllib import quote
9-from urllib2 import urlopen, Request
10+from urllib2 import build_opener, urlopen, HTTPCookieProcessor, Request
11 from urlparse import urlparse
12
13 from BeautifulSoup import BeautifulSoup
14@@ -126,4 +127,30 @@
15 else:
16 event.addresponse(u'Are you making up words again?')
17
18+# This Plugin uses code from youtube-dl
19+# Copyright (c) 2006-2008 Ricardo Garcia Gonzalez
20+# Released under MIT Licence
21+
22+help['youtube'] = u'Determine the title and a download URL for a Youtube Video'
23+class Youtube(Processor):
24+ u'<Youtube URL>'
25+
26+ feature = 'youtube'
27+
28+ @match(r'^(?:youtube(?:\.com)?\s+)?'
29+ r'(?:http://)?(?:\w+\.)?youtube\.com/'
30+ r'(?:v/|(?:watch(?:\.php)?)?\?(?:.+&)?v=)'
31+ r'([0-9A-Za-z_-]+)(?(1)[&/].*)?$')
32+ def youtube(self, event, id):
33+ url = 'http://www.youtube.com/watch?v=' + id
34+ opener = build_opener(HTTPCookieProcessor())
35+ opener.addheaders = [('User-Agent', default_user_agent)]
36+ video_webpage = opener.open(url).read()
37+ title = re.search(r'<title>YouTube - ([^<]*)</title>', video_webpage, re.M | re.I).group(1)
38+ t = re.search(r', "t": "([^"]+)"', video_webpage).group(1)
39+ event.addresponse(u'%(title)s: %(url)s', {
40+ 'title': title,
41+ 'url': 'http://www.youtube.com/get_video?video_id=%s&t=%s' % (id, t),
42+ })
43+
44 # vi: set et sta sw=4 ts=4:

Subscribers

People subscribed via source and target branches