]>
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/(?!(?:a|gallery|(?:t(?:opic)?|r)/[^/]+)/)(?P<id>[a-zA-Z0-9]+)'
18 'url': 'https://i.imgur.com/A61SaA1.gifv',
22 'title': 're:Imgur GIF$|MRW gifv is up and running without any bugs$',
25 'url': 'https://imgur.com/A61SaA1',
26 'only_matching': True,
28 'url': 'https://i.imgur.com/crGpqCV.mp4',
29 'only_matching': True,
32 def _real_extract(self
, url
):
33 video_id
= self
._match
_id
(url
)
34 webpage
= self
._download
_webpage
(
35 'https://i.imgur.com/{id}.gifv'.format(id=video_id
), video_id
)
37 width
= int_or_none(self
._og
_search
_property
(
38 'video:width', webpage
, default
=None))
39 height
= int_or_none(self
._og
_search
_property
(
40 'video:height', webpage
, default
=None))
42 video_elements
= self
._search
_regex
(
43 r
'(?s)<div class="video-elements">(.*?)</div>',
44 webpage
, 'video elements', default
=None)
45 if not video_elements
:
47 'No sources found for video %s. Maybe an image?' % video_id
,
51 for m
in re
.finditer(r
'<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)"', video_elements
):
53 'format_id': m
.group('type').partition('/')[2],
54 'url': self
._proto
_relative
_url
(m
.group('src')),
55 'ext': mimetype2ext(m
.group('type')),
59 'User-Agent': 'youtube-dl (like wget)',
63 gif_json
= self
._search
_regex
(
64 r
'(?s)var\s+videoItem\s*=\s*(\{.*?\})',
65 webpage
, 'GIF code', fatal
=False)
67 gifd
= self
._parse
_json
(
68 gif_json
, video_id
, transform_source
=js_to_json
)
78 'url': self
._proto
_relative
_url
(gifd
['gifUrl']),
79 'filesize': gifd
.get('size'),
81 'User-Agent': 'youtube-dl (like wget)',
85 self
._sort
_formats
(formats
)
90 'title': self
._og
_search
_title
(webpage
),
94 class ImgurGalleryIE(InfoExtractor
):
95 IE_NAME
= 'imgur:gallery'
96 _VALID_URL
= r
'https?://(?:i\.)?imgur\.com/(?:gallery|(?:t(?:opic)?|r)/[^/]+)/(?P<id>[a-zA-Z0-9]+)'
99 'url': 'http://imgur.com/gallery/Q95ko',
102 'title': 'Adding faces make every GIF better',
104 'playlist_count': 25,
106 'url': 'http://imgur.com/topic/Aww/ll5Vk',
107 'only_matching': True,
109 'url': 'https://imgur.com/gallery/YcAQlkx',
113 'title': 'Classic Steve Carell gif...cracks me up everytime....damn the repost downvotes....',
116 'url': 'http://imgur.com/topic/Funny/N8rOudd',
117 'only_matching': True,
119 'url': 'http://imgur.com/r/aww/VQcQPhM',
120 'only_matching': True,
123 def _real_extract(self
, url
):
124 gallery_id
= self
._match
_id
(url
)
126 data
= self
._download
_json
(
127 'https://imgur.com/gallery/%s.json' % gallery_id
,
128 gallery_id
)['data']['image']
130 if data
.get('is_album'):
132 self
.url_result('http://imgur.com/%s' % image
['hash'], ImgurIE
.ie_key(), image
['hash'])
133 for image
in data
['album_images']['images'] if image
.get('hash')]
134 return self
.playlist_result(entries
, gallery_id
, data
.get('title'), data
.get('description'))
136 return self
.url_result('http://imgur.com/%s' % gallery_id
, ImgurIE
.ie_key(), gallery_id
)
139 class ImgurAlbumIE(ImgurGalleryIE
):
140 IE_NAME
= 'imgur:album'
141 _VALID_URL
= r
'https?://(?:i\.)?imgur\.com/a/(?P<id>[a-zA-Z0-9]+)'
144 'url': 'http://imgur.com/a/j6Orj',
147 'title': 'A Literary Analysis of "Star Wars: The Force Awakens"',
149 'playlist_count': 12,