]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/flickr.py
Merge tag 'upstream/2013.07.10'
[youtubedl] / youtube_dl / extractor / flickr.py
1 import re
2
3 from .common import InfoExtractor
4 from ..utils import (
5 ExtractorError,
6 unescapeHTML,
7 )
8
9
10 class FlickrIE(InfoExtractor):
11 """Information Extractor for Flickr videos"""
12 _VALID_URL = r'(?:https?://)?(?:www\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
13 _TEST = {
14 u'url': u'http://www.flickr.com/photos/forestwander-nature-pictures/5645318632/in/photostream/',
15 u'file': u'5645318632.mp4',
16 u'md5': u'6fdc01adbc89d72fc9c4f15b4a4ba87b',
17 u'info_dict': {
18 u"description": u"Waterfalls in the Springtime at Dark Hollow Waterfalls. These are located just off of Skyline Drive in Virginia. They are only about 6/10 of a mile hike but it is a pretty steep hill and a good climb back up.",
19 u"uploader_id": u"forestwander-nature-pictures",
20 u"title": u"Dark Hollow Waterfalls"
21 }
22 }
23
24 def _real_extract(self, url):
25 mobj = re.match(self._VALID_URL, url)
26
27 video_id = mobj.group('id')
28 video_uploader_id = mobj.group('uploader_id')
29 webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
30 webpage = self._download_webpage(webpage_url, video_id)
31
32 secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, u'secret')
33
34 first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
35 first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
36
37 node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
38 first_xml, u'node_id')
39
40 second_url = 'https://secure.flickr.com/video_playlist.gne?node_id=' + node_id + '&tech=flash&mode=playlist&bitrate=700&secret=' + secret + '&rd=video.yahoo.com&noad=1'
41 second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
42
43 self.report_extraction(video_id)
44
45 mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
46 if mobj is None:
47 raise ExtractorError(u'Unable to extract video url')
48 video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
49
50 video_title = self._html_search_regex(r'<meta property="og:title" content=(?:"([^"]+)"|\'([^\']+)\')',
51 webpage, u'video title')
52
53 video_description = self._html_search_regex(r'<meta property="og:description" content=(?:"([^"]+)"|\'([^\']+)\')',
54 webpage, u'description', fatal=False)
55
56 thumbnail = self._html_search_regex(r'<meta property="og:image" content=(?:"([^"]+)"|\'([^\']+)\')',
57 webpage, u'thumbnail', fatal=False)
58
59 return [{
60 'id': video_id,
61 'url': video_url,
62 'ext': 'mp4',
63 'title': video_title,
64 'description': video_description,
65 'thumbnail': thumbnail,
66 'uploader_id': video_uploader_id,
67 }]