1 from .common
import InfoExtractor
4 compat_urllib_parse_urlencode
,
14 class FlickrIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.|secure\.)?flickr\.com/photos/[\w\-_@]+/(?P<id>\d+)'
17 'url': 'http://www.flickr.com/photos/forestwander-nature-pictures/5645318632/in/photostream/',
18 'md5': '164fe3fa6c22e18d448d4d5af2330f31',
22 '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.',
23 'title': 'Dark Hollow Waterfalls',
25 'timestamp': 1303528740,
26 'upload_date': '20110423',
27 'uploader_id': '10922353@N03',
28 'uploader': 'Forest Wander',
29 'uploader_url': 'https://www.flickr.com/photos/forestwander-nature-pictures/',
33 'license': 'Attribution-ShareAlike',
36 _API_BASE_URL
= 'https://api.flickr.com/services/rest?'
37 # https://help.yahoo.com/kb/flickr/SLN25525.html
39 '0': 'All Rights Reserved',
40 '1': 'Attribution-NonCommercial-ShareAlike',
41 '2': 'Attribution-NonCommercial',
42 '3': 'Attribution-NonCommercial-NoDerivs',
44 '5': 'Attribution-ShareAlike',
45 '6': 'Attribution-NoDerivs',
46 '7': 'No known copyright restrictions',
47 '8': 'United States government work',
48 '9': 'Public Domain Dedication (CC0)',
49 '10': 'Public Domain Work',
52 def _call_api(self
, method
, video_id
, api_key
, note
, secret
=None):
55 'method': 'flickr.%s' % method
,
61 query
['secret'] = secret
62 data
= self
._download
_json
(self
._API
_BASE
_URL
+ compat_urllib_parse_urlencode(query
), video_id
, note
)
63 if data
['stat'] != 'ok':
64 raise ExtractorError(data
['message'])
67 def _real_extract(self
, url
):
68 video_id
= self
._match
_id
(url
)
70 api_key
= self
._download
_json
(
71 'https://www.flickr.com/hermes_error_beacon.gne', video_id
,
72 'Downloading api key')['site_key']
74 video_info
= self
._call
_api
(
75 'photos.getInfo', video_id
, api_key
, 'Downloading video info')['photo']
76 if video_info
['media'] == 'video':
77 streams
= self
._call
_api
(
78 'video.getStreamInfo', video_id
, api_key
,
79 'Downloading streams info', video_info
['secret'])['streams']
81 preference
= qualities(
82 ['288p', 'iphone_wifi', '100', '300', '700', '360p', 'appletv', '720p', '1080p', 'orig'])
85 for stream
in streams
['stream']:
86 stream_type
= compat_str(stream
.get('type'))
88 'format_id': stream_type
,
89 'url': stream
['_content'],
90 'quality': preference(stream_type
),
93 owner
= video_info
.get('owner', {})
94 uploader_id
= owner
.get('nsid')
95 uploader_path
= owner
.get('path_alias') or uploader_id
96 uploader_url
= format_field(uploader_path
, None, 'https://www.flickr.com/photos/%s/')
100 'title': video_info
['title']['_content'],
101 'description': video_info
.get('description', {}).get('_content'),
103 'timestamp': int_or_none(video_info
.get('dateuploaded')),
104 'duration': int_or_none(video_info
.get('video', {}).get('duration')),
105 'uploader_id': uploader_id
,
106 'uploader': owner
.get('realname'),
107 'uploader_url': uploader_url
,
108 'comment_count': int_or_none(video_info
.get('comments', {}).get('_content')),
109 'view_count': int_or_none(video_info
.get('views')),
110 'tags': [tag
.get('_content') for tag
in video_info
.get('tags', {}).get('tag', [])],
111 'license': self
._LICENSES
.get(video_info
.get('license')),
114 raise ExtractorError('not a video', expected
=True)