[imgur] add support

This commit is contained in:
Mort Yao 2015-12-31 11:20:37 +01:00
parent 89c11a2a7c
commit ef966931a3
3 changed files with 74 additions and 0 deletions

View File

@ -26,6 +26,7 @@ SITES = {
'heavy-music' : 'heavymusic',
'iask' : 'sina',
'ifeng' : 'ifeng',
'imgur' : 'imgur',
'in' : 'alive',
'instagram' : 'instagram',
'interest' : 'interest',

View File

@ -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 *

View File

@ -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