2 from __future__ import unicode_literals
4 from .common import InfoExtractor
13 class GfycatIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?gfycat\.com/(?:ifr/)?(?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',
49 def _real_extract(self, url):
50 video_id = self._match_id(url)
52 gfy = self._download_json(
53 'http://gfycat.com/cajax/get/%s' % video_id,
54 video_id, 'Downloading video info')
56 raise ExtractorError('Gfycat said: ' + gfy['error'], expected=True)
59 title = gfy.get('title') or gfy['gfyName']
60 description = gfy.get('description')
61 timestamp = int_or_none(gfy.get('createDate'))
62 uploader = gfy.get('userName')
63 view_count = int_or_none(gfy.get('views'))
64 like_count = int_or_none(gfy.get('likes'))
65 dislike_count = int_or_none(gfy.get('dislikes'))
66 age_limit = 18 if gfy.get('nsfw') == '1' else 0
68 width = int_or_none(gfy.get('width'))
69 height = int_or_none(gfy.get('height'))
70 fps = int_or_none(gfy.get('frameRate'))
71 num_frames = int_or_none(gfy.get('numFrames'))
73 duration = float_or_none(num_frames, fps) if num_frames and fps else None
75 categories = gfy.get('tags') or gfy.get('extraLemmas') or []
77 FORMATS = ('gif', 'webm', 'mp4')
78 quality = qualities(FORMATS)
81 for format_id in FORMATS:
82 video_url = gfy.get('%sUrl' % format_id)
85 filesize = gfy.get('%sSize' % format_id)
88 'format_id': format_id,
93 'quality': quality(format_id),
95 self._sort_formats(formats)
100 'description': description,
101 'timestamp': timestamp,
102 'uploader': uploader,
103 'duration': duration,
104 'view_count': view_count,
105 'like_count': like_count,
106 'dislike_count': dislike_count,
107 'categories': categories,
108 'age_limit': age_limit,