1 from __future__ import unicode_literals
5 from .common import InfoExtractor
13 class ImgurIE(InfoExtractor):
14 _VALID_URL = r'https?://i\.imgur\.com/(?P<id>[a-zA-Z0-9]+)\.(?:mp4|gifv)'
17 'url': 'https://i.imgur.com/A61SaA1.gifv',
21 'title': 'MRW gifv is up and running without any bugs',
22 'description': 'The Internet\'s visual storytelling community. Explore, share, and discuss the best visual stories the Internet has to offer.',
26 def _real_extract(self, url):
27 video_id = self._match_id(url)
28 webpage = self._download_webpage(url, video_id)
30 width = int_or_none(self._search_regex(
31 r'<param name="width" value="([0-9]+)"',
32 webpage, 'width', fatal=False))
33 height = int_or_none(self._search_regex(
34 r'<param name="height" value="([0-9]+)"',
35 webpage, 'height', fatal=False))
38 video_elements = self._search_regex(
39 r'(?s)<div class="video-elements">(.*?)</div>',
40 webpage, 'video elements')
42 for m in re.finditer(r'<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)"', video_elements):
44 'format_id': m.group('type').partition('/')[2],
45 'url': self._proto_relative_url(m.group('src')),
46 'ext': mimetype2ext(m.group('type')),
51 'User-Agent': 'youtube-dl (like wget)',
55 gif_json = self._search_regex(
56 r'(?s)var\s+videoItem\s*=\s*(\{.*?\})',
57 webpage, 'GIF code', fatal=False)
59 gifd = self._parse_json(
60 gif_json, video_id, transform_source=js_to_json)
70 'url': self._proto_relative_url(gifd['gifUrl']),
71 'filesize': gifd.get('size'),
73 'User-Agent': 'youtube-dl (like wget)',
77 self._sort_formats(formats)
82 'description': self._og_search_description(webpage),
83 'title': self._og_search_title(webpage),