2 from __future__ import unicode_literals
4 from .common import InfoExtractor
13 class GfycatIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?gfycat\.com/(?: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/gifs/detail/UnconsciousLankyIvorygull',
51 'url': 'https://gfycat.com/acceptablehappygoluckyharborporpoise-baseball',
55 def _real_extract(self, url):
56 video_id = self._match_id(url)
58 gfy = self._download_json(
59 'https://api.gfycat.com/v1/gfycats/%s' % video_id,
60 video_id, 'Downloading video info')
62 raise ExtractorError('Gfycat said: ' + gfy['error'], expected=True)
65 title = gfy.get('title') or gfy['gfyName']
66 description = gfy.get('description')
67 timestamp = int_or_none(gfy.get('createDate'))
68 uploader = gfy.get('userName')
69 view_count = int_or_none(gfy.get('views'))
70 like_count = int_or_none(gfy.get('likes'))
71 dislike_count = int_or_none(gfy.get('dislikes'))
72 age_limit = 18 if gfy.get('nsfw') == '1' else 0
74 width = int_or_none(gfy.get('width'))
75 height = int_or_none(gfy.get('height'))
76 fps = int_or_none(gfy.get('frameRate'))
77 num_frames = int_or_none(gfy.get('numFrames'))
79 duration = float_or_none(num_frames, fps) if num_frames and fps else None
81 categories = gfy.get('tags') or gfy.get('extraLemmas') or []
83 FORMATS = ('gif', 'webm', 'mp4')
84 quality = qualities(FORMATS)
87 for format_id in FORMATS:
88 video_url = gfy.get('%sUrl' % format_id)
91 filesize = int_or_none(gfy.get('%sSize' % format_id))
94 'format_id': format_id,
99 'quality': quality(format_id),
101 self._sort_formats(formats)
106 'description': description,
107 'timestamp': timestamp,
108 'uploader': uploader,
109 'duration': duration,
110 'view_count': view_count,
111 'like_count': like_count,
112 'dislike_count': dislike_count,
113 'categories': categories,
114 'age_limit': age_limit,