]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/flickr.py
Initiate release.
[youtubedl] / youtube_dl / extractor / flickr.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 ExtractorError,
8 unescapeHTML,
9 )
10
11
12 class FlickrIE(InfoExtractor):
13 """Information Extractor for Flickr videos"""
14 _VALID_URL = r'(?:https?://)?(?:www\.|secure\.)?flickr\.com/photos/(?P<uploader_id>[\w\-_@]+)/(?P<id>\d+).*'
15 _TEST = {
16 'url': 'http://www.flickr.com/photos/forestwander-nature-pictures/5645318632/in/photostream/',
17 'file': '5645318632.mp4',
18 'md5': '6fdc01adbc89d72fc9c4f15b4a4ba87b',
19 'info_dict': {
20 "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.",
21 "uploader_id": "forestwander-nature-pictures",
22 "title": "Dark Hollow Waterfalls"
23 }
24 }
25
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
28
29 video_id = mobj.group('id')
30 video_uploader_id = mobj.group('uploader_id')
31 webpage_url = 'http://www.flickr.com/photos/' + video_uploader_id + '/' + video_id
32 webpage = self._download_webpage(webpage_url, video_id)
33
34 secret = self._search_regex(r"photo_secret: '(\w+)'", webpage, 'secret')
35
36 first_url = 'https://secure.flickr.com/apps/video/video_mtl_xml.gne?v=x&photo_id=' + video_id + '&secret=' + secret + '&bitrate=700&target=_self'
37 first_xml = self._download_webpage(first_url, video_id, 'Downloading first data webpage')
38
39 node_id = self._html_search_regex(r'<Item id="id">(\d+-\d+)</Item>',
40 first_xml, 'node_id')
41
42 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'
43 second_xml = self._download_webpage(second_url, video_id, 'Downloading second data webpage')
44
45 self.report_extraction(video_id)
46
47 mobj = re.search(r'<STREAM APP="(.+?)" FULLPATH="(.+?)"', second_xml)
48 if mobj is None:
49 raise ExtractorError('Unable to extract video url')
50 video_url = mobj.group(1) + unescapeHTML(mobj.group(2))
51
52 return [{
53 'id': video_id,
54 'url': video_url,
55 'ext': 'mp4',
56 'title': self._og_search_title(webpage),
57 'description': self._og_search_description(webpage),
58 'thumbnail': self._og_search_thumbnail(webpage),
59 'uploader_id': video_uploader_id,
60 }]