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_url(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_url(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)