2 from __future__ import unicode_literals
4 from .common import InfoExtractor
12 class GfycatIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?gfycat\.com/(?:ifr/)?(?P<id>[^/?#]+)'
15 'url': 'http://gfycat.com/DeadlyDecisiveGermanpinscher',
17 'id': 'DeadlyDecisiveGermanpinscher',
19 'title': 'Ghost in the Shell',
20 'timestamp': 1410656006,
21 'upload_date': '20140914',
22 'uploader': 'anonymous',
31 'url': 'http://gfycat.com/ifr/JauntyTimelyAmazontreeboa',
33 'id': 'JauntyTimelyAmazontreeboa',
35 'title': 'JauntyTimelyAmazontreeboa',
36 'timestamp': 1411720126,
37 'upload_date': '20140926',
38 'uploader': 'anonymous',
48 def _real_extract(self, url):
49 video_id = self._match_id(url)
51 gfy = self._download_json(
52 'http://gfycat.com/cajax/get/%s' % video_id,
53 video_id, 'Downloading video info')['gfyItem']
55 title = gfy.get('title') or gfy['gfyName']
56 description = gfy.get('description')
57 timestamp = int_or_none(gfy.get('createDate'))
58 uploader = gfy.get('userName')
59 view_count = int_or_none(gfy.get('views'))
60 like_count = int_or_none(gfy.get('likes'))
61 dislike_count = int_or_none(gfy.get('dislikes'))
62 age_limit = 18 if gfy.get('nsfw') == '1' else 0
64 width = int_or_none(gfy.get('width'))
65 height = int_or_none(gfy.get('height'))
66 fps = int_or_none(gfy.get('frameRate'))
67 num_frames = int_or_none(gfy.get('numFrames'))
69 duration = float_or_none(num_frames, fps) if num_frames and fps else None
71 categories = gfy.get('tags') or gfy.get('extraLemmas') or []
73 FORMATS = ('gif', 'webm', 'mp4')
74 quality = qualities(FORMATS)
77 for format_id in FORMATS:
78 video_url = gfy.get('%sUrl' % format_id)
81 filesize = gfy.get('%sSize' % format_id)
84 'format_id': format_id,
89 'quality': quality(format_id),
91 self._sort_formats(formats)
96 'description': description,
97 'timestamp': timestamp,
100 'view_count': view_count,
101 'like_count': like_count,
102 'dislike_count': dislike_count,
103 'categories': categories,
104 'age_limit': age_limit,