diff --git a/src/you_get/common.py b/src/you_get/common.py index 5880c152..fd956408 100755 --- a/src/you_get/common.py +++ b/src/you_get/common.py @@ -26,6 +26,7 @@ SITES = { 'heavy-music' : 'heavymusic', 'iask' : 'sina', 'ifeng' : 'ifeng', + 'imgur' : 'imgur', 'in' : 'alive', 'instagram' : 'instagram', 'interest' : 'interest', diff --git a/src/you_get/extractors/__init__.py b/src/you_get/extractors/__init__.py index b4b2a1a6..380c5736 100755 --- a/src/you_get/extractors/__init__.py +++ b/src/you_get/extractors/__init__.py @@ -21,6 +21,7 @@ from .funshion import * from .google import * from .heavymusic import * from .ifeng import * +from .imgur import * from .instagram import * from .interest import * from .iqilu import * diff --git a/src/you_get/extractors/imgur.py b/src/you_get/extractors/imgur.py new file mode 100644 index 00000000..80d68ce8 --- /dev/null +++ b/src/you_get/extractors/imgur.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +from ..common import * +from ..extractor import VideoExtractor +from .universal import * + +class Imgur(VideoExtractor): + name = "Imgur" + + stream_types = [ + {'id': 'original'}, + {'id': 'thumbnail'}, + ] + + def prepare(self, **kwargs): + if re.search(r'imgur\.com/a/', self.url): + # album + content = get_content(self.url) + album = json.loads(match1(content, r'album\s*:\s*({.*}),')) + count = album['album_images']['count'] + images = album['album_images']['images'] + ext = images[0]['ext'] + self.streams = { + 'original': { + 'src': ['http://i.imgur.com/%s%s' % (i['hash'], ext) + for i in images], + 'size': sum([i['size'] for i in images]), + 'container': ext[1:] + }, + 'thumbnail': { + 'src': ['http://i.imgur.com/%ss%s' % (i['hash'], '.jpg') + for i in images], + 'container': 'jpg' + } + } + self.title = album['title'] + + elif re.search(r'i\.imgur\.com/', self.url): + # direct image + universal_download(self.url, + output_dir=kwargs['output_dir'], + merge=kwargs['merge'], + info_only=kwargs['info_only']) + exit(0) # FIXME! + + else: + # gallery image + content = get_content(self.url) + image = json.loads(match1(content, r'image\s*:\s*({.*}),')) + ext = image['ext'] + self.streams = { + 'original': { + 'src': ['http://i.imgur.com/%s%s' % (image['hash'], ext)], + 'size': image['size'], + 'container': ext[1:] + }, + 'thumbnail': { + 'src': ['http://i.imgur.com/%ss%s' % (image['hash'], '.jpg')], + 'container': 'jpg' + } + } + self.title = image['title'] + + def extract(self, **kwargs): + if 'stream_id' in kwargs and kwargs['stream_id']: + i = kwargs['stream_id'] + if 'size' not in self.streams[i]: + self.streams[i]['size'] = urls_size(self.streams[i]['src']) + +site = Imgur() +download = site.download_by_url +download_playlist = site.download_by_url