]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/flickr.py
1 from __future__
import unicode_literals
3 from . common
import InfoExtractor
4 from .. compat
import compat_urllib_parse
12 class FlickrIE ( InfoExtractor
):
13 _VALID_URL
= r
'https?://(?:www\.|secure\.)?flickr\.com/photos/[\w\-_@]+/(?P<id>\d+)'
15 'url' : 'http://www.flickr.com/photos/forestwander-nature-pictures/5645318632/in/photostream/' ,
16 'md5' : '164fe3fa6c22e18d448d4d5af2330f31' ,
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 'title' : 'Dark Hollow Waterfalls' ,
23 'timestamp' : 1303528740 ,
24 'upload_date' : '20110423' ,
25 'uploader_id' : '10922353@N03' ,
26 'uploader' : 'Forest Wander' ,
33 _API_BASE_URL
= 'https://api.flickr.com/services/rest?'
35 def _call_api ( self
, method
, video_id
, api_key
, note
, secret
= None ):
38 'method' : 'flickr. %s ' % method
,
44 query
[ 'secret' ] = secret
45 data
= self
._ download
_ json
( self
._ API
_ BASE
_U RL
+ compat_urllib_parse
. urlencode ( query
), video_id
, note
)
46 if data
[ 'stat' ] != 'ok' :
47 raise ExtractorError ( data
[ 'message' ])
50 def _real_extract ( self
, url
):
51 video_id
= self
._ match
_ id
( url
)
53 api_key
= self
._ download
_ json
(
54 'https://www.flickr.com/hermes_error_beacon.gne' , video_id
,
55 'Downloading api key' )[ 'site_key' ]
57 video_info
= self
._ call
_ api
(
58 'photos.getInfo' , video_id
, api_key
, 'Downloading video info' )[ 'photo' ]
59 if video_info
[ 'media' ] == 'video' :
60 streams
= self
._ call
_ api
(
61 'video.getStreamInfo' , video_id
, api_key
,
62 'Downloading streams info' , video_info
[ 'secret' ])[ 'streams' ]
64 preference
= qualities (
65 [ '288p' , 'iphone_wifi' , '100' , '300' , '700' , '360p' , 'appletv' , '720p' , '1080p' , 'orig' ])
68 for stream
in streams
[ 'stream' ]:
69 stream_type
= str ( stream
. get ( 'type' ))
71 'format_id' : stream_type
,
72 'url' : stream
[ '_content' ],
73 'preference' : preference ( stream_type
),
75 self
._ sort
_ formats
( formats
)
77 owner
= video_info
. get ( 'owner' , {})
81 'title' : video_info
[ 'title' ][ '_content' ],
82 'description' : video_info
. get ( 'description' , {}). get ( '_content' ),
84 'timestamp' : int_or_none ( video_info
. get ( 'dateuploaded' )),
85 'duration' : int_or_none ( video_info
. get ( 'video' , {}). get ( 'duration' )),
86 'uploader_id' : owner
. get ( 'nsid' ),
87 'uploader' : owner
. get ( 'realname' ),
88 'comment_count' : int_or_none ( video_info
. get ( 'comments' , {}). get ( '_content' )),
89 'view_count' : int_or_none ( video_info
. get ( 'views' )),
90 'tags' : [ tag
. get ( '_content' ) for tag
in video_info
. get ( 'tags' , {}). get ( 'tag' , [])]
93 raise ExtractorError ( 'not a video' , expected
= True )