]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imgur.py
d23489dcff4464c1294d9c6f5dca30aa480ad3a8
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|topic/[^/]+)/)?(?P<id>[a-zA-Z0-9]{6,})(?:[/?#&]+|\.[a-z]+)?$'
19 'url': 'https://i.imgur.com/A61SaA1.gifv',
23 'title': 're:Imgur GIF$|MRW gifv is up and running without any bugs$',
24 'description': 'Imgur: The most awesome images on the Internet.',
27 'url': 'https://imgur.com/A61SaA1',
31 'title': 're:Imgur GIF$|MRW gifv is up and running without any bugs$',
32 'description': 'Imgur: The most awesome images on the Internet.',
35 'url': 'https://imgur.com/gallery/YcAQlkx',
39 'title': 'Classic Steve Carell gif...cracks me up everytime....damn the repost downvotes....',
40 'description': 'Imgur: The most awesome images on the Internet.'
44 'url': 'http://imgur.com/topic/Funny/N8rOudd',
45 'only_matching': True,
48 def _real_extract(self
, url
):
49 video_id
= self
._match
_id
(url
)
50 webpage
= self
._download
_webpage
(
51 compat_urlparse
.urljoin(url
, video_id
), video_id
)
53 width
= int_or_none(self
._og
_search
_property
(
54 'video:width', webpage
, default
=None))
55 height
= int_or_none(self
._og
_search
_property
(
56 'video:height', webpage
, default
=None))
58 video_elements
= self
._search
_regex
(
59 r
'(?s)<div class="video-elements">(.*?)</div>',
60 webpage
, 'video elements', default
=None)
61 if not video_elements
:
63 'No sources found for video %s. Maybe an image?' % video_id
,
67 for m
in re
.finditer(r
'<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)"', video_elements
):
69 'format_id': m
.group('type').partition('/')[2],
70 'url': self
._proto
_relative
_url
(m
.group('src')),
71 'ext': mimetype2ext(m
.group('type')),
76 'User-Agent': 'youtube-dl (like wget)',
80 gif_json
= self
._search
_regex
(
81 r
'(?s)var\s+videoItem\s*=\s*(\{.*?\})',
82 webpage
, 'GIF code', fatal
=False)
84 gifd
= self
._parse
_json
(
85 gif_json
, video_id
, transform_source
=js_to_json
)
95 'url': self
._proto
_relative
_url
(gifd
['gifUrl']),
96 'filesize': gifd
.get('size'),
98 'User-Agent': 'youtube-dl (like wget)',
102 self
._sort
_formats
(formats
)
107 'description': self
._og
_search
_description
(webpage
),
108 'title': self
._og
_search
_title
(webpage
),
112 class ImgurAlbumIE(InfoExtractor
):
113 _VALID_URL
= r
'https?://(?:i\.)?imgur\.com/(?:(?:a|gallery|topic/[^/]+)/)?(?P<id>[a-zA-Z0-9]{5})(?:[/?#&]+)?$'
116 'url': 'http://imgur.com/gallery/Q95ko',
120 'playlist_count': 25,
122 'url': 'http://imgur.com/a/j6Orj',
123 'only_matching': True,
125 'url': 'http://imgur.com/topic/Aww/ll5Vk',
126 'only_matching': True,
129 def _real_extract(self
, url
):
130 album_id
= self
._match
_id
(url
)
132 album_images
= self
._download
_json
(
133 'http://imgur.com/gallery/%s/album_images/hit.json?all=true' % album_id
,
134 album_id
, fatal
=False)
137 data
= album_images
.get('data')
138 if data
and isinstance(data
, dict):
139 images
= data
.get('images')
140 if images
and isinstance(images
, list):
142 self
.url_result('http://imgur.com/%s' % image
['hash'])
143 for image
in images
if image
.get('hash')]
144 return self
.playlist_result(entries
, album_id
)
146 # Fallback to single video
147 return self
.url_result('http://imgur.com/%s' % album_id
, ImgurIE
.ie_key())