]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imgur.py 
70c8ca64e6346d86ef5ecea02722597829db1316
   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/(?!gallery)(?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
),  102  class  ImgurAlbumIE ( InfoExtractor
):  103      _VALID_URL 
=  r
'https?://(?:i\.)?imgur\.com/gallery/(?P<id>[a-zA-Z0-9]+)'  106          'url' :  'http://imgur.com/gallery/Q95ko' ,  110          'playlist_count' :  25 ,  113      def  _real_extract ( self
,  url
):  114          album_id 
=  self
._ match
_ id
( url
)  116          album_images 
=  self
._ download
_ json
(  117              'http://imgur.com/gallery/ %s /album_images/hit.json?all=true'  %  album_id
,  118              album_id
)[ 'data' ][ 'images' ]  121              self
. url_result ( 'http://imgur.com/ %s '  %  image
[ 'hash' ])  122              for  image 
in  album_images 
if  image
. get ( 'hash' )]  124          return  self
. playlist_result ( entries
,  album_id
)