3 from __future__ import unicode_literals
7 from .common import InfoExtractor
9 class GfycatIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?gfycat\.com/(?P<id>[^/?#]+)'
13 'url': 'http://gfycat.com/DeadlyDecisiveGermanpinscher',
15 'id': 'DeadlyDecisiveGermanpinscher',
16 'title': 'Ghost in the Shell',
18 'upload_date': '20140913'
21 'url': 'http://gfycat.com/pleasinghilariouskusimanse',
23 'id': 'pleasinghilariouskusimanse',
24 'title': 'PleasingHilariousKusimanse',
26 'upload_date': '20150412'
32 'url': 'http://gfycat.com/requiredunkemptbuzzard',
34 'id': 'requiredunkemptbuzzard',
37 'upload_date': '20150129'
45 def _real_extract(self, url):
46 video_id = self._match_id(url)
47 json = self._download_json("http://gfycat.com/cajax/get/" + video_id, video_id, 'Downloading video info')['gfyItem']
50 # Use user title first, else fallback to url formated name
52 video_title = json['title']
54 video_title = json['gfyName']
57 # Pref: mp4, webm, gif
61 'url': json['mp4Url'],
62 'width': json['width'],
63 'height': json['height'],
64 'fps': json['frameRate'],
65 'filesize': json['mp4Size'],
70 'url': json['webmUrl'],
71 'width': json['width'],
72 'height': json['height'],
73 'fps': json['frameRate'],
74 'filesize': json['webmSize'],
79 'url': json['gifUrl'],
80 'width': json['width'],
81 'height': json['height'],
82 'fps': json['frameRate'],
83 'filesize': json['gifSize'],
87 self._sort_formats(formats)
90 date = datetime.datetime.fromtimestamp(
91 int(json['createDate'])
95 duration = json['numFrames'] / json['frameRate']
106 'title': video_title,
108 'creator': json['userName'],
109 'description': json['description'],
111 'categories': json['tags'],
112 'age_limit': age_limit,
113 'duration': duration,
114 'view_count': json['views']