]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/imgur.py
3 from .common
import InfoExtractor
12 class ImgurIE(InfoExtractor
):
13 _VALID_URL
= r
'https?://(?:i\.)?imgur\.com/(?!(?:a|gallery|(?:t(?:opic)?|r)/[^/]+)/)(?P<id>[a-zA-Z0-9]+)'
16 'url': 'https://i.imgur.com/A61SaA1.gifv',
20 'title': 're:Imgur GIF$|MRW gifv is up and running without any bugs$',
23 'url': 'https://imgur.com/A61SaA1',
24 'only_matching': True,
26 'url': 'https://i.imgur.com/crGpqCV.mp4',
27 'only_matching': True,
30 'url': 'https://i.imgur.com/jxBXAMC.gifv',
31 'only_matching': True,
34 def _real_extract(self
, url
):
35 video_id
= self
._match
_id
(url
)
36 webpage
= self
._download
_webpage
(
37 'https://i.imgur.com/{id}.gifv'.format(id=video_id
), video_id
)
39 width
= int_or_none(self
._og
_search
_property
(
40 'video:width', webpage
, default
=None))
41 height
= int_or_none(self
._og
_search
_property
(
42 'video:height', webpage
, default
=None))
44 video_elements
= self
._search
_regex
(
45 r
'(?s)<div class="video-elements">(.*?)</div>',
46 webpage
, 'video elements', default
=None)
47 if not video_elements
:
49 'No sources found for video %s. Maybe an image?' % video_id
,
53 for m
in re
.finditer(r
'<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)"', video_elements
):
55 'format_id': m
.group('type').partition('/')[2],
56 'url': self
._proto
_relative
_url
(m
.group('src')),
57 'ext': mimetype2ext(m
.group('type')),
61 'User-Agent': 'yt-dlp (like wget)',
65 gif_json
= self
._search
_regex
(
66 r
'(?s)var\s+videoItem\s*=\s*(\{.*?\})',
67 webpage
, 'GIF code', fatal
=False)
69 gifd
= self
._parse
_json
(
70 gif_json
, video_id
, transform_source
=js_to_json
)
73 'preference': -10, # gifs are worse than videos
80 'url': self
._proto
_relative
_url
(gifd
['gifUrl']),
81 'filesize': gifd
.get('size'),
83 'User-Agent': 'yt-dlp (like wget)',
87 self
._sort
_formats
(formats
)
92 'title': self
._og
_search
_title
(webpage
, default
=video_id
),
96 class ImgurGalleryIE(InfoExtractor
):
97 IE_NAME
= 'imgur:gallery'
98 _VALID_URL
= r
'https?://(?:i\.)?imgur\.com/(?:gallery|(?:t(?:opic)?|r)/[^/]+)/(?P<id>[a-zA-Z0-9]+)'
101 'url': 'http://imgur.com/gallery/Q95ko',
104 'title': 'Adding faces make every GIF better',
106 'playlist_count': 25,
108 'url': 'http://imgur.com/topic/Aww/ll5Vk',
109 'only_matching': True,
111 'url': 'https://imgur.com/gallery/YcAQlkx',
115 'title': 'Classic Steve Carell gif...cracks me up everytime....damn the repost downvotes....',
118 'url': 'http://imgur.com/topic/Funny/N8rOudd',
119 'only_matching': True,
121 'url': 'http://imgur.com/r/aww/VQcQPhM',
122 'only_matching': True,
125 def _real_extract(self
, url
):
126 gallery_id
= self
._match
_id
(url
)
128 data
= self
._download
_json
(
129 'https://imgur.com/gallery/%s.json' % gallery_id
,
130 gallery_id
)['data']['image']
132 if data
.get('is_album'):
134 self
.url_result('http://imgur.com/%s' % image
['hash'], ImgurIE
.ie_key(), image
['hash'])
135 for image
in data
['album_images']['images'] if image
.get('hash')]
136 return self
.playlist_result(entries
, gallery_id
, data
.get('title'), data
.get('description'))
138 return self
.url_result('http://imgur.com/%s' % gallery_id
, ImgurIE
.ie_key(), gallery_id
)
141 class ImgurAlbumIE(ImgurGalleryIE
):
142 IE_NAME
= 'imgur:album'
143 _VALID_URL
= r
'https?://(?:i\.)?imgur\.com/a/(?P<id>[a-zA-Z0-9]+)'
146 'url': 'http://imgur.com/a/j6Orj',
149 'title': 'A Literary Analysis of "Star Wars: The Force Awakens"',
151 'playlist_count': 12,