2 from __future__ import unicode_literals
4 from .common import InfoExtractor
13 class GfycatIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:(?:www|giant|thumbs)\.)?gfycat\.com/(?:ru/|ifr/|gifs/detail/)?(?P<id>[^-/?#\.]+)'
16 'url': 'http://gfycat.com/DeadlyDecisiveGermanpinscher',
18 'id': 'DeadlyDecisiveGermanpinscher',
20 'title': 'Ghost in the Shell',
21 'timestamp': 1410656006,
22 'upload_date': '20140914',
23 'uploader': 'anonymous',
32 'url': 'http://gfycat.com/ifr/JauntyTimelyAmazontreeboa',
34 'id': 'JauntyTimelyAmazontreeboa',
36 'title': 'JauntyTimelyAmazontreeboa',
37 'timestamp': 1411720126,
38 'upload_date': '20140926',
39 'uploader': 'anonymous',
48 'url': 'https://gfycat.com/ru/RemarkableDrearyAmurstarfish',
51 'url': 'https://gfycat.com/gifs/detail/UnconsciousLankyIvorygull',
54 'url': 'https://gfycat.com/acceptablehappygoluckyharborporpoise-baseball',
57 'url': 'https://thumbs.gfycat.com/acceptablehappygoluckyharborporpoise-size_restricted.gif',
60 'url': 'https://giant.gfycat.com/acceptablehappygoluckyharborporpoise.mp4',
64 def _real_extract(self, url):
65 video_id = self._match_id(url)
67 gfy = self._download_json(
68 'https://api.gfycat.com/v1/gfycats/%s' % video_id,
69 video_id, 'Downloading video info')
71 raise ExtractorError('Gfycat said: ' + gfy['error'], expected=True)
74 title = gfy.get('title') or gfy['gfyName']
75 description = gfy.get('description')
76 timestamp = int_or_none(gfy.get('createDate'))
77 uploader = gfy.get('userName')
78 view_count = int_or_none(gfy.get('views'))
79 like_count = int_or_none(gfy.get('likes'))
80 dislike_count = int_or_none(gfy.get('dislikes'))
81 age_limit = 18 if gfy.get('nsfw') == '1' else 0
83 width = int_or_none(gfy.get('width'))
84 height = int_or_none(gfy.get('height'))
85 fps = int_or_none(gfy.get('frameRate'))
86 num_frames = int_or_none(gfy.get('numFrames'))
88 duration = float_or_none(num_frames, fps) if num_frames and fps else None
90 categories = gfy.get('tags') or gfy.get('extraLemmas') or []
92 FORMATS = ('gif', 'webm', 'mp4')
93 quality = qualities(FORMATS)
96 for format_id in FORMATS:
97 video_url = gfy.get('%sUrl' % format_id)
100 filesize = int_or_none(gfy.get('%sSize' % format_id))
103 'format_id': format_id,
107 'filesize': filesize,
108 'quality': quality(format_id),
110 self._sort_formats(formats)
115 'description': description,
116 'timestamp': timestamp,
117 'uploader': uploader,
118 'duration': duration,
119 'view_count': view_count,
120 'like_count': like_count,
121 'dislike_count': dislike_count,
122 'categories': categories,
123 'age_limit': age_limit,