]>
Commit | Line | Data |
---|---|---|
fabfe17d PH |
1 | from __future__ import unicode_literals |
2 | ||
1ac4004f PH |
3 | import re |
4 | ||
5 | from .common import InfoExtractor | |
6 | from ..utils import ( | |
7 | ExtractorError, | |
c04c3e33 | 8 | find_xpath_attr, |
5c2266df | 9 | sanitized_Request, |
1ac4004f PH |
10 | ) |
11 | ||
12 | ||
13 | class FlickrIE(InfoExtractor): | |
cc746841 | 14 | _VALID_URL = r'https?://(?:www\.|secure\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*' |
6f5ac90c | 15 | _TEST = { |
fabfe17d | 16 | 'url': 'http://www.flickr.com/photos/forestwander-nature-pictures/5645318632/in/photostream/', |
fabfe17d PH |
17 | 'md5': '6fdc01adbc89d72fc9c4f15b4a4ba87b', |
18 | 'info_dict': { | |
cc746841 PH |
19 | 'id': '5645318632', |
20 | 'ext': 'mp4', | |
5f6a1245 JW |
21 | "description": "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.", |
22 | "uploader_id": "forestwander-nature-pictures", | |
fabfe17d | 23 | "title": "Dark Hollow Waterfalls" |
6f5ac90c PH |
24 | } |
25 | } | |
1ac4004f PH |
26 | |
27 | def _real_extract(self, url): | |
28 | mobj = re.match(self._VALID_URL, url) | |
29 | ||
30 | video_id = mobj.group('id') | |
31 | video_uploader_id = mobj.group('uploader_id') | |
32 | webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id | |
5c2266df | 33 | req = sanitized_Request(webpage_url) |
f8e51f60 JMF |
34 | req.add_header( |
35 | 'User-Agent', | |
36 | # it needs a more recent version | |
37 | 'Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20150101 Firefox/38.0 (Chrome)') | |
38 | webpage = self._download_webpage(req, video_id) | |
39 | ||
40 | secret = self._search_regex(r'secret"\s*:\s*"(\w+)"', webpage, 'secret') | |
1ac4004f PH |
41 | |
42 | first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self' | |
c04c3e33 | 43 | first_xml = self._download_xml(first_url, video_id, 'Downloading first data webpage') |
1ac4004f | 44 | |
c04c3e33 JMF |
45 | node_id = find_xpath_attr( |
46 | first_xml, './/{http://video.yahoo.com/YEP/1.0/}Item', 'id', | |
47 | 'id').text | |
1ac4004f PH |
48 | |
49 | 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' | |
c04c3e33 | 50 | second_xml = self._download_xml(second_url, video_id, 'Downloading second data webpage') |
1ac4004f PH |
51 | |
52 | self.report_extraction(video_id) | |
53 | ||
c04c3e33 JMF |
54 | stream = second_xml.find('.//STREAM') |
55 | if stream is None: | |
fabfe17d | 56 | raise ExtractorError('Unable to extract video url') |
c04c3e33 | 57 | video_url = stream.attrib['APP'] + stream.attrib['FULLPATH'] |
1ac4004f | 58 | |
cc746841 PH |
59 | return { |
60 | 'id': video_id, | |
61 | 'url': video_url, | |
62 | 'ext': 'mp4', | |
63 | 'title': self._og_search_title(webpage), | |
46720279 | 64 | 'description': self._og_search_description(webpage), |
cc746841 | 65 | 'thumbnail': self._og_search_thumbnail(webpage), |
1ac4004f | 66 | 'uploader_id': video_uploader_id, |
cc746841 | 67 | } |