5 from .common import InfoExtractor
11 class PhotobucketIE(InfoExtractor):
12 """Information extractor for photobucket.com."""
14 # TODO: the original _VALID_URL was:
15 # r'(?:http://)?(?:[a-z0-9]+\.)?photobucket\.com/.*[\?\&]current=(.*\.flv)'
16 # Check if it's necessary to keep the old extracion process
17 _VALID_URL = r'(?:http://)?(?:[a-z0-9]+\.)?photobucket\.com/.*(([\?\&]current=)|_)(?P<id>.*)\.(?P<ext>(flv)|(mp4))'
18 IE_NAME = u'photobucket'
20 u'url': u'http://media.photobucket.com/user/rachaneronas/media/TiredofLinkBuildingTryBacklinkMyDomaincom_zpsc0c3b9fa.mp4.html?filters[term]=search&filters[primary]=videos&filters[secondary]=images&sort=1&o=0',
21 u'file': u'zpsc0c3b9fa.mp4',
22 u'md5': u'7dabfb92b0a31f6c16cebc0f8e60ff99',
24 u"upload_date": u"20130504",
25 u"uploader": u"rachaneronas",
26 u"title": u"Tired of Link Building? Try BacklinkMyDomain.com!"
30 def _real_extract(self, url):
32 mobj = re.match(self._VALID_URL, url)
34 raise ExtractorError(u'Invalid URL: %s' % url)
36 video_id = mobj.group('id')
38 video_extension = mobj.group('ext')
40 # Retrieve video webpage to extract further information
41 webpage = self._download_webpage(url, video_id)
43 # Extract URL, uploader, and title from webpage
44 self.report_extraction(video_id)
45 # We try first by looking the javascript code:
46 mobj = re.search(r'Pb\.Data\.Shared\.put\(Pb\.Data\.Shared\.MEDIA, (?P<json>.*?)\);', webpage)
48 info = json.loads(mobj.group('json'))
51 'url': info[u'downloadUrl'],
52 'uploader': info[u'username'],
53 'upload_date': datetime.date.fromtimestamp(info[u'creationDate']).strftime('%Y%m%d'),
54 'title': info[u'title'],
55 'ext': video_extension,
56 'thumbnail': info[u'thumbUrl'],
59 # We try looking in other parts of the webpage
60 video_url = self._search_regex(r'<link rel="video_src" href=".*\?file=([^"]+)" />',
61 webpage, u'video URL')
63 mobj = re.search(r'<title>(.*) video by (.*) - Photobucket</title>', webpage)
65 raise ExtractorError(u'Unable to extract title')
66 video_title = mobj.group(1).decode('utf-8')
67 video_uploader = mobj.group(2).decode('utf-8')
70 'id': video_id.decode('utf-8'),
71 'url': video_url.decode('utf-8'),
72 'uploader': video_uploader,
75 'ext': video_extension.decode('utf-8'),