]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/gfycat.py
   2 from __future__ 
import unicode_literals
 
   4 from .common 
import InfoExtractor
 
  12 class GfycatIE(InfoExtractor
): 
  13     _VALID_URL 
= r
'https?://(?:www\.)?gfycat\.com/(?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', 
  32     def _real_extract(self
, url
): 
  33         video_id 
= self
._match
_id
(url
) 
  35         gfy 
= self
._download
_json
( 
  36             'http://gfycat.com/cajax/get/%s' % video_id
, 
  37             video_id
, 'Downloading video info')['gfyItem'] 
  39         title 
= gfy
.get('title') or gfy
['gfyName'] 
  40         description 
= gfy
.get('description') 
  41         timestamp 
= int_or_none(gfy
.get('createDate')) 
  42         uploader 
= gfy
.get('userName') 
  43         view_count 
= int_or_none(gfy
.get('views')) 
  44         like_count 
= int_or_none(gfy
.get('likes')) 
  45         dislike_count 
= int_or_none(gfy
.get('dislikes')) 
  46         age_limit 
= 18 if gfy
.get('nsfw') == '1' else 0 
  48         width 
= int_or_none(gfy
.get('width')) 
  49         height 
= int_or_none(gfy
.get('height')) 
  50         fps 
= int_or_none(gfy
.get('frameRate')) 
  51         num_frames 
= int_or_none(gfy
.get('numFrames')) 
  53         duration 
= float_or_none(num_frames
, fps
) if num_frames 
and fps 
else None 
  55         categories 
= gfy
.get('tags') or gfy
.get('extraLemmas') or [] 
  57         FORMATS 
= ('gif', 'webm', 'mp4') 
  58         quality 
= qualities(FORMATS
) 
  61         for format_id 
in FORMATS
: 
  62             video_url 
= gfy
.get('%sUrl' % format_id
) 
  65             filesize 
= gfy
.get('%sSize' % format_id
) 
  68                 'format_id': format_id
, 
  73                 'quality': quality(format_id
), 
  75         self
._sort
_formats
(formats
) 
  80             'description': description
, 
  81             'timestamp': timestamp
, 
  84             'view_count': view_count
, 
  85             'like_count': like_count
, 
  86             'dislike_count': dislike_count
, 
  87             'categories': categories
, 
  88             'age_limit': age_limit
,