]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/gfycat.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
13 class GfycatIE(InfoExtractor
):
14 _VALID_URL
= r
'https?://(?:www\.)?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',
58 def _real_extract(self
, url
):
59 video_id
= self
._match
_id
(url
)
61 gfy
= self
._download
_json
(
62 'https://api.gfycat.com/v1/gfycats/%s' % video_id
,
63 video_id
, 'Downloading video info')
65 raise ExtractorError('Gfycat said: ' + gfy
['error'], expected
=True)
68 title
= gfy
.get('title') or gfy
['gfyName']
69 description
= gfy
.get('description')
70 timestamp
= int_or_none(gfy
.get('createDate'))
71 uploader
= gfy
.get('userName')
72 view_count
= int_or_none(gfy
.get('views'))
73 like_count
= int_or_none(gfy
.get('likes'))
74 dislike_count
= int_or_none(gfy
.get('dislikes'))
75 age_limit
= 18 if gfy
.get('nsfw') == '1' else 0
77 width
= int_or_none(gfy
.get('width'))
78 height
= int_or_none(gfy
.get('height'))
79 fps
= int_or_none(gfy
.get('frameRate'))
80 num_frames
= int_or_none(gfy
.get('numFrames'))
82 duration
= float_or_none(num_frames
, fps
) if num_frames
and fps
else None
84 categories
= gfy
.get('tags') or gfy
.get('extraLemmas') or []
86 FORMATS
= ('gif', 'webm', 'mp4')
87 quality
= qualities(FORMATS
)
90 for format_id
in FORMATS
:
91 video_url
= gfy
.get('%sUrl' % format_id
)
94 filesize
= int_or_none(gfy
.get('%sSize' % format_id
))
97 'format_id': format_id
,
101 'filesize': filesize
,
102 'quality': quality(format_id
),
104 self
._sort
_formats
(formats
)
109 'description': description
,
110 'timestamp': timestamp
,
111 'uploader': uploader
,
112 'duration': duration
,
113 'view_count': view_count
,
114 'like_count': like_count
,
115 'dislike_count': dislike_count
,
116 'categories': categories
,
117 'age_limit': age_limit
,