mirror of https://github.com/blackjack4494/yt-dlc
parent
ca75235d3d
commit
f52e66505a
@ -1,115 +1,90 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..utils import (
|
||||||
|
int_or_none,
|
||||||
|
float_or_none,
|
||||||
|
qualities,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class GfycatIE(InfoExtractor):
|
class GfycatIE(InfoExtractor):
|
||||||
_VALID_URL = r'https?://(?:www\.)?gfycat\.com/(?P<id>[^/?#]+)'
|
_VALID_URL = r'https?://(?:www\.)?gfycat\.com/(?P<id>[^/?#]+)'
|
||||||
_TESTS = [
|
_TEST = {
|
||||||
{
|
'url': 'http://gfycat.com/DeadlyDecisiveGermanpinscher',
|
||||||
'url': 'http://gfycat.com/DeadlyDecisiveGermanpinscher',
|
'info_dict': {
|
||||||
'info_dict': {
|
'id': 'DeadlyDecisiveGermanpinscher',
|
||||||
'id': 'DeadlyDecisiveGermanpinscher',
|
'ext': 'mp4',
|
||||||
'title': 'Ghost in the Shell',
|
'title': 'Ghost in the Shell',
|
||||||
'ext': 'mp4',
|
'timestamp': 1410656006,
|
||||||
'upload_date': '20140913'
|
'upload_date': '20140914',
|
||||||
}
|
'uploader': 'anonymous',
|
||||||
},{
|
'duration': 10.4,
|
||||||
'url': 'http://gfycat.com/pleasinghilariouskusimanse',
|
'view_count': int,
|
||||||
'info_dict': {
|
'like_count': int,
|
||||||
'id': 'pleasinghilariouskusimanse',
|
'dislike_count': int,
|
||||||
'title': 'PleasingHilariousKusimanse',
|
'categories': list,
|
||||||
'ext': 'webm',
|
'age_limit': 0,
|
||||||
'upload_date': '20150412'
|
}
|
||||||
},
|
}
|
||||||
'params': {
|
|
||||||
'format': 'webm',
|
|
||||||
},
|
|
||||||
},{
|
|
||||||
'url': 'http://gfycat.com/requiredunkemptbuzzard',
|
|
||||||
'info_dict': {
|
|
||||||
'id': 'requiredunkemptbuzzard',
|
|
||||||
'title': 'Headshot!',
|
|
||||||
'ext': 'gif',
|
|
||||||
'upload_date': '20150129'
|
|
||||||
},
|
|
||||||
'params': {
|
|
||||||
'format': 'gif',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
json = self._download_json("http://gfycat.com/cajax/get/" + video_id, video_id, 'Downloading video info')['gfyItem']
|
|
||||||
|
|
||||||
# Title
|
gfy = self._download_json(
|
||||||
# Use user title first, else fallback to url formated name
|
'http://gfycat.com/cajax/get/%s' % video_id,
|
||||||
if json['title']:
|
video_id, 'Downloading video info')['gfyItem']
|
||||||
video_title = json['title']
|
|
||||||
else:
|
|
||||||
video_title = json['gfyName']
|
|
||||||
|
|
||||||
# Formats
|
title = gfy.get('title') or gfy['gfyName']
|
||||||
# Pref: mp4, webm, gif
|
description = gfy.get('description')
|
||||||
formats = [{
|
timestamp = int_or_none(gfy.get('createDate'))
|
||||||
'format_id': 'mp4',
|
uploader = gfy.get('userName')
|
||||||
'ext': 'mp4',
|
view_count = int_or_none(gfy.get('views'))
|
||||||
'url': json['mp4Url'],
|
like_count = int_or_none(gfy.get('likes'))
|
||||||
'width': json['width'],
|
dislike_count = int_or_none(gfy.get('dislikes'))
|
||||||
'height': json['height'],
|
age_limit = 18 if gfy.get('nsfw') == '1' else 0
|
||||||
'fps': json['frameRate'],
|
|
||||||
'filesize': json['mp4Size'],
|
|
||||||
'preference': 2
|
|
||||||
}, {
|
|
||||||
'format_id': 'webm',
|
|
||||||
'ext': 'webm',
|
|
||||||
'url': json['webmUrl'],
|
|
||||||
'width': json['width'],
|
|
||||||
'height': json['height'],
|
|
||||||
'fps': json['frameRate'],
|
|
||||||
'filesize': json['webmSize'],
|
|
||||||
'preference': 1
|
|
||||||
}, {
|
|
||||||
'format_id': 'gif',
|
|
||||||
'ext': 'gif',
|
|
||||||
'url': json['gifUrl'],
|
|
||||||
'width': json['width'],
|
|
||||||
'height': json['height'],
|
|
||||||
'fps': json['frameRate'],
|
|
||||||
'filesize': json['gifSize'],
|
|
||||||
'preference': 0
|
|
||||||
}]
|
|
||||||
|
|
||||||
self._sort_formats(formats)
|
width = int_or_none(gfy.get('width'))
|
||||||
|
height = int_or_none(gfy.get('height'))
|
||||||
|
fps = int_or_none(gfy.get('frameRate'))
|
||||||
|
num_frames = int_or_none(gfy.get('numFrames'))
|
||||||
|
|
||||||
|
duration = float_or_none(num_frames, fps) if num_frames and fps else None
|
||||||
|
|
||||||
# Date
|
categories = gfy.get('tags') or gfy.get('extraLemmas') or []
|
||||||
date = datetime.datetime.fromtimestamp(
|
|
||||||
int(json['createDate'])
|
|
||||||
).strftime('%Y%m%d')
|
|
||||||
|
|
||||||
# Length
|
FORMATS = ('gif', 'webm', 'mp4')
|
||||||
duration = json['numFrames'] / json['frameRate']
|
quality = qualities(FORMATS)
|
||||||
|
|
||||||
# Age limit
|
formats = []
|
||||||
# 1 = nsfw / 0 = sfw
|
for format_id in FORMATS:
|
||||||
if json['nsfw'] == 1:
|
video_url = gfy.get('%sUrl' % format_id)
|
||||||
age_limit = 18
|
if not video_url:
|
||||||
else:
|
continue
|
||||||
age_limit = 0
|
filesize = gfy.get('%sSize' % format_id)
|
||||||
|
formats.append({
|
||||||
|
'url': video_url,
|
||||||
|
'format_id': format_id,
|
||||||
|
'width': width,
|
||||||
|
'height': height,
|
||||||
|
'fps': fps,
|
||||||
|
'filesize': filesize,
|
||||||
|
'quality': quality(format_id),
|
||||||
|
})
|
||||||
|
self._sort_formats(formats)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': video_title,
|
'title': title,
|
||||||
'formats': formats,
|
'description': description,
|
||||||
'creator': json['userName'],
|
'timestamp': timestamp,
|
||||||
'description': json['description'],
|
'uploader': uploader,
|
||||||
'upload_date': date,
|
'duration': duration,
|
||||||
'categories': json['tags'],
|
'view_count': view_count,
|
||||||
'age_limit': age_limit,
|
'like_count': like_count,
|
||||||
'duration': duration,
|
'dislike_count': dislike_count,
|
||||||
'view_count': json['views']
|
'categories': categories,
|
||||||
|
'age_limit': age_limit,
|
||||||
|
'formats': formats,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue