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]{6,})'
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.'
45 def _real_extract(self, url):
46 video_id = self._match_id(url)
47 webpage = self._download_webpage(
48 compat_urlparse.urljoin(url, video_id), video_id)
50 width = int_or_none(self._search_regex(
51 r'<param name="width" value="([0-9]+)"',
52 webpage, 'width', fatal=False))
53 height = int_or_none(self._search_regex(
54 r'<param name="height" value="([0-9]+)"',
55 webpage, 'height', fatal=False))
57 video_elements = self._search_regex(
58 r'(?s)<div class="video-elements">(.*?)</div>',
59 webpage, 'video elements', default=None)
60 if not video_elements:
62 'No sources found for video %s. Maybe an image?' % video_id,
66 for m in re.finditer(r'<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)"', video_elements):
68 'format_id': m.group('type').partition('/')[2],
69 'url': self._proto_relative_url(m.group('src')),
70 'ext': mimetype2ext(m.group('type')),
75 'User-Agent': 'youtube-dl (like wget)',
79 gif_json = self._search_regex(
80 r'(?s)var\s+videoItem\s*=\s*(\{.*?\})',
81 webpage, 'GIF code', fatal=False)
83 gifd = self._parse_json(
84 gif_json, video_id, transform_source=js_to_json)
94 'url': self._proto_relative_url(gifd['gifUrl']),
95 'filesize': gifd.get('size'),
97 'User-Agent': 'youtube-dl (like wget)',
101 self._sort_formats(formats)
106 'description': self._og_search_description(webpage),
107 'title': self._og_search_title(webpage),
111 class ImgurAlbumIE(InfoExtractor):
112 _VALID_URL = r'https?://(?:i\.)?imgur\.com/(gallery/)?(?P<id>[a-zA-Z0-9]{5})(?![a-zA-Z0-9])'
115 'url': 'http://imgur.com/gallery/Q95ko',
119 'playlist_count': 25,
122 def _real_extract(self, url):
123 album_id = self._match_id(url)
125 album_img_data = self._download_json(
126 'http://imgur.com/gallery/%s/album_images/hit.json?all=true' % album_id, album_id)['data']
128 if len(album_img_data) == 0:
129 return self.url_result('http://imgur.com/%s' % album_id)
131 album_images = album_img_data['images']
133 self.url_result('http://imgur.com/%s' % image['hash'])
134 for image in album_images if image.get('hash')]
136 return self.playlist_result(entries, album_id)