1 from __future__
import unicode_literals
3 from .common
import InfoExtractor
6 compat_urllib_parse_urlencode
,
16 class FlickrIE(InfoExtractor
):
17 _VALID_URL
= r
'https?://(?:www\.|secure\.)?flickr\.com/photos/[\w\-_@]+/(?P<id>\d+)'
19 'url': 'http://www.flickr.com/photos/forestwander-nature-pictures/5645318632/in/photostream/',
20 'md5': '164fe3fa6c22e18d448d4d5af2330f31',
24 '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.',
25 'title': 'Dark Hollow Waterfalls',
27 'timestamp': 1303528740,
28 'upload_date': '20110423',
29 'uploader_id': '10922353@N03',
30 'uploader': 'Forest Wander',
31 'uploader_url': 'https://www.flickr.com/photos/forestwander-nature-pictures/',
35 'license': 'Attribution-ShareAlike',
38 _API_BASE_URL
= 'https://api.flickr.com/services/rest?'
39 # https://help.yahoo.com/kb/flickr/SLN25525.html
41 '0': 'All Rights Reserved',
42 '1': 'Attribution-NonCommercial-ShareAlike',
43 '2': 'Attribution-NonCommercial',
44 '3': 'Attribution-NonCommercial-NoDerivs',
46 '5': 'Attribution-ShareAlike',
47 '6': 'Attribution-NoDerivs',
48 '7': 'No known copyright restrictions',
49 '8': 'United States government work',
50 '9': 'Public Domain Dedication (CC0)',
51 '10': 'Public Domain Work',
54 def _call_api(self
, method
, video_id
, api_key
, note
, secret
=None):
57 'method': 'flickr.%s' % method
,
63 query
['secret'] = secret
64 data
= self
._download
_json
(self
._API
_BASE
_URL
+ compat_urllib_parse_urlencode(query
), video_id
, note
)
65 if data
['stat'] != 'ok':
66 raise ExtractorError(data
['message'])
69 def _real_extract(self
, url
):
70 video_id
= self
._match
_id
(url
)
72 api_key
= self
._download
_json
(
73 'https://www.flickr.com/hermes_error_beacon.gne', video_id
,
74 'Downloading api key')['site_key']
76 video_info
= self
._call
_api
(
77 'photos.getInfo', video_id
, api_key
, 'Downloading video info')['photo']
78 if video_info
['media'] == 'video':
79 streams
= self
._call
_api
(
80 'video.getStreamInfo', video_id
, api_key
,
81 'Downloading streams info', video_info
['secret'])['streams']
83 preference
= qualities(
84 ['288p', 'iphone_wifi', '100', '300', '700', '360p', 'appletv', '720p', '1080p', 'orig'])
87 for stream
in streams
['stream']:
88 stream_type
= compat_str(stream
.get('type'))
90 'format_id': stream_type
,
91 'url': stream
['_content'],
92 'quality': preference(stream_type
),
94 self
._sort
_formats
(formats
)
96 owner
= video_info
.get('owner', {})
97 uploader_id
= owner
.get('nsid')
98 uploader_path
= owner
.get('path_alias') or uploader_id
99 uploader_url
= format_field(uploader_path
, template
='https://www.flickr.com/photos/%s/')
103 'title': video_info
['title']['_content'],
104 'description': video_info
.get('description', {}).get('_content'),
106 'timestamp': int_or_none(video_info
.get('dateuploaded')),
107 'duration': int_or_none(video_info
.get('video', {}).get('duration')),
108 'uploader_id': uploader_id
,
109 'uploader': owner
.get('realname'),
110 'uploader_url': uploader_url
,
111 'comment_count': int_or_none(video_info
.get('comments', {}).get('_content')),
112 'view_count': int_or_none(video_info
.get('views')),
113 'tags': [tag
.get('_content') for tag
in video_info
.get('tags', {}).get('tag', [])],
114 'license': self
._LICENSES
.get(video_info
.get('license')),
117 raise ExtractorError('not a video', expected
=True)