]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imgur.py
1 from __future__
import unicode_literals
5 from . common
import InfoExtractor
14 class ImgurIE ( InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:i\.)?imgur\.com/(?P<id>[a-zA-Z0-9]+)(?:\.mp4|\.gifv)?'
18 'url' : 'https://i.imgur.com/A61SaA1.gifv' ,
22 'title' : 're:Imgur GIF$|MRW gifv is up and running without any bugs$' ,
23 'description' : 're:The origin of the Internet \' s most viral images$|The Internet \' s visual storytelling community\. Explore, share, and discuss the best visual stories the Internet has to offer\.$' ,
26 'url' : 'https://imgur.com/A61SaA1' ,
30 'title' : 're:Imgur GIF$|MRW gifv is up and running without any bugs$' ,
31 'description' : 're:The origin of the Internet \' s most viral images$|The Internet \' s visual storytelling community\. Explore, share, and discuss the best visual stories the Internet has to offer\.$' ,
35 def _real_extract ( self
, url
):
36 video_id
= self
._ match
_ id
( url
)
37 webpage
= self
._ download
_ webpage
( url
, video_id
)
39 width
= int_or_none ( self
._ search
_ regex
(
40 r
'<param name="width" value="([0-9]+)"' ,
41 webpage
, 'width' , fatal
= False ))
42 height
= int_or_none ( self
._ search
_ regex
(
43 r
'<param name="height" value="([0-9]+)"' ,
44 webpage
, 'height' , fatal
= False ))
46 video_elements
= self
._ search
_ regex
(
47 r
'(?s)<div class="video-elements">(.*?)</div>' ,
48 webpage
, 'video elements' , default
= None )
49 if not video_elements
:
51 'No sources found for video %s . Maybe an image?' % video_id
,
55 for m
in re
. finditer ( r
'<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)"' , video_elements
):
57 'format_id' : m
. group ( 'type' ). partition ( '/' )[ 2 ],
58 'url' : self
._ proto
_ relative
_u rl
( m
. group ( 'src' )),
59 'ext' : mimetype2ext ( m
. group ( 'type' )),
64 'User-Agent' : 'youtube-dl (like wget)' ,
68 gif_json
= self
._ search
_ regex
(
69 r
'(?s)var\s+videoItem\s*=\s*(\{.*?\})' ,
70 webpage
, 'GIF code' , fatal
= False )
72 gifd
= self
._ parse
_ json
(
73 gif_json
, video_id
, transform_source
= js_to_json
)
83 'url' : self
._ proto
_ relative
_u rl
( gifd
[ 'gifUrl' ]),
84 'filesize' : gifd
. get ( 'size' ),
86 'User-Agent' : 'youtube-dl (like wget)' ,
90 self
._ sort
_ formats
( formats
)
95 'description' : self
._ og
_ search
_ description
( webpage
),
96 'title' : self
._ og
_ search
_ title
( webpage
),