]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/gfycat.py
a0670b6456adf7e092dadbfc14d193f920aa0262
   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', 
  52     def _real_extract(self
, url
): 
  53         video_id 
= self
._match
_id
(url
) 
  55         gfy 
= self
._download
_json
( 
  56             'http://gfycat.com/cajax/get/%s' % video_id
, 
  57             video_id
, 'Downloading video info') 
  59             raise ExtractorError('Gfycat said: ' + gfy
['error'], expected
=True) 
  62         title 
= gfy
.get('title') or gfy
['gfyName'] 
  63         description 
= gfy
.get('description') 
  64         timestamp 
= int_or_none(gfy
.get('createDate')) 
  65         uploader 
= gfy
.get('userName') 
  66         view_count 
= int_or_none(gfy
.get('views')) 
  67         like_count 
= int_or_none(gfy
.get('likes')) 
  68         dislike_count 
= int_or_none(gfy
.get('dislikes')) 
  69         age_limit 
= 18 if gfy
.get('nsfw') == '1' else 0 
  71         width 
= int_or_none(gfy
.get('width')) 
  72         height 
= int_or_none(gfy
.get('height')) 
  73         fps 
= int_or_none(gfy
.get('frameRate')) 
  74         num_frames 
= int_or_none(gfy
.get('numFrames')) 
  76         duration 
= float_or_none(num_frames
, fps
) if num_frames 
and fps 
else None 
  78         categories 
= gfy
.get('tags') or gfy
.get('extraLemmas') or [] 
  80         FORMATS 
= ('gif', 'webm', 'mp4') 
  81         quality 
= qualities(FORMATS
) 
  84         for format_id 
in FORMATS
: 
  85             video_url 
= gfy
.get('%sUrl' % format_id
) 
  88             filesize 
= int_or_none(gfy
.get('%sSize' % format_id
)) 
  91                 'format_id': format_id
, 
  96                 'quality': quality(format_id
), 
  98         self
._sort
_formats
(formats
) 
 103             'description': description
, 
 104             'timestamp': timestamp
, 
 105             'uploader': uploader
, 
 106             'duration': duration
, 
 107             'view_count': view_count
, 
 108             'like_count': like_count
, 
 109             'dislike_count': dislike_count
, 
 110             'categories': categories
, 
 111             'age_limit': age_limit
,