]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/collegehumor.py
   1 from __future__ 
import unicode_literals
 
   6 from .common 
import InfoExtractor
 
   7 from ..utils 
import int_or_none
 
  10 class CollegeHumorIE(InfoExtractor
): 
  11     _VALID_URL 
= r
'^(?:https?://)?(?:www\.)?collegehumor\.com/(video|embed|e)/(?P<videoid>[0-9]+)/?(?P<shorttitle>.*)$' 
  14         'url': 'http://www.collegehumor.com/video/6902724/comic-con-cosplay-catastrophe', 
  15         'md5': 'dcc0f5c1c8be98dc33889a191f4c26bd', 
  19             'title': 'Comic-Con Cosplay Catastrophe', 
  20             'description': 'Fans get creative this year', 
  25         'url': 'http://www.collegehumor.com/video/3505939/font-conference', 
  26         'md5': '72fa701d8ef38664a4dbb9e2ab721816', 
  30             'title': 'Font Conference', 
  31             'description': 'This video wasn\'t long enough,', 
  36     # embedded youtube video 
  38         'url': 'http://www.collegehumor.com/embed/6950457', 
  42             'title': 'Funny Dogs Protecting Babies Compilation 2014 [NEW HD]', 
  43             'uploader': 'Funnyplox TV', 
  44             'uploader_id': 'funnyploxtv', 
  45             'description': 'md5:7ded37421526d54afdf005e25bc2b7a3', 
  46             'upload_date': '20140128', 
  49             'skip_download': True, 
  51         'add_ie': ['Youtube'], 
  55     def _real_extract(self
, url
): 
  56         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  57         video_id 
= mobj
.group('videoid') 
  59         jsonUrl 
= 'http://www.collegehumor.com/moogaloop/video/' + video_id 
+ '.json' 
  60         data 
= json
.loads(self
._download
_webpage
( 
  61             jsonUrl
, video_id
, 'Downloading info JSON')) 
  63         if vdata
.get('youtubeId') is not None: 
  66                 'url': vdata
['youtubeId'], 
  70         AGE_LIMITS 
= {'nc17': 18, 'r': 18, 'pg13': 13, 'pg': 10, 'g': 0} 
  71         rating 
= vdata
.get('rating') 
  73             age_limit 
= AGE_LIMITS
.get(rating
.lower()) 
  75             age_limit 
= None  # None = No idea 
  77         PREFS 
= {'high_quality': 2, 'low_quality': 0} 
  79         for format_key 
in ('mp4', 'webm'): 
  80             for qname
, qurl 
in vdata
.get(format_key
, {}).items(): 
  82                     'format_id': format_key 
+ '_' + qname
, 
  85                     'preference': PREFS
.get(qname
), 
  87         self
._sort
_formats
(formats
) 
  89         duration 
= int_or_none(vdata
.get('duration'), 1000) 
  93             'title': vdata
['title'], 
  94             'description': vdata
.get('description'), 
  95             'thumbnail': vdata
.get('thumbnail'), 
  97             'age_limit': age_limit
,