]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imgur.py
d692ea79ab493174038c9649445e6a592a86687c
1 from __future__
import unicode_literals
5 from . common
import InfoExtractor
6 from .. compat
import compat_urlparse
15 class ImgurIE ( InfoExtractor
):
16 _VALID_URL
= r
'https?://(?:i\.)?imgur\.com/(?P<id>[a-zA-Z0-9]+)'
19 'url' : 'https://i.imgur.com/A61SaA1.gifv' ,
23 'title' : 're:Imgur GIF$|MRW gifv is up and running without any bugs$' ,
24 '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\.$' ,
27 'url' : 'https://imgur.com/A61SaA1' ,
31 'title' : 're:Imgur GIF$|MRW gifv is up and running without any bugs$' ,
32 '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\.$' ,
36 def _real_extract ( self
, url
):
37 video_id
= self
._ match
_ id
( url
)
38 webpage
= self
._ download
_ webpage
(
39 compat_urlparse
. urljoin ( url
, video_id
), video_id
)
41 width
= int_or_none ( self
._ search
_ regex
(
42 r
'<param name="width" value="([0-9]+)"' ,
43 webpage
, 'width' , fatal
= False ))
44 height
= int_or_none ( self
._ search
_ regex
(
45 r
'<param name="height" value="([0-9]+)"' ,
46 webpage
, 'height' , fatal
= False ))
48 video_elements
= self
._ search
_ regex
(
49 r
'(?s)<div class="video-elements">(.*?)</div>' ,
50 webpage
, 'video elements' , default
= None )
51 if not video_elements
:
53 'No sources found for video %s . Maybe an image?' % video_id
,
57 for m
in re
. finditer ( r
'<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)"' , video_elements
):
59 'format_id' : m
. group ( 'type' ). partition ( '/' )[ 2 ],
60 'url' : self
._ proto
_ relative
_u rl
( m
. group ( 'src' )),
61 'ext' : mimetype2ext ( m
. group ( 'type' )),
66 'User-Agent' : 'youtube-dl (like wget)' ,
70 gif_json
= self
._ search
_ regex
(
71 r
'(?s)var\s+videoItem\s*=\s*(\{.*?\})' ,
72 webpage
, 'GIF code' , fatal
= False )
74 gifd
= self
._ parse
_ json
(
75 gif_json
, video_id
, transform_source
= js_to_json
)
85 'url' : self
._ proto
_ relative
_u rl
( gifd
[ 'gifUrl' ]),
86 'filesize' : gifd
. get ( 'size' ),
88 'User-Agent' : 'youtube-dl (like wget)' ,
92 self
._ sort
_ formats
( formats
)
97 'description' : self
._ og
_ search
_ description
( webpage
),
98 'title' : self
._ og
_ search
_ title
( webpage
),