4 from .common import InfoExtractor
7 class CollegeHumorIE(InfoExtractor):
8 _VALID_URL = r'^(?:https?://)?(?:www\.)?collegehumor\.com/(video|embed|e)/(?P<videoid>[0-9]+)/?(?P<shorttitle>.*)$'
11 u'url': u'http://www.collegehumor.com/video/6902724/comic-con-cosplay-catastrophe',
12 u'file': u'6902724.mp4',
13 u'md5': u'dcc0f5c1c8be98dc33889a191f4c26bd',
15 u'title': u'Comic-Con Cosplay Catastrophe',
16 u'description': u'Fans get creative this year at San Diego. Too',
21 u'url': u'http://www.collegehumor.com/video/3505939/font-conference',
22 u'file': u'3505939.mp4',
23 u'md5': u'72fa701d8ef38664a4dbb9e2ab721816',
25 u'title': u'Font Conference',
26 u'description': u'This video wasn\'t long enough, so we made it double-spaced.',
31 def _real_extract(self, url):
32 mobj = re.match(self._VALID_URL, url)
33 video_id = mobj.group('videoid')
35 jsonUrl = 'http://www.collegehumor.com/moogaloop/video/' + video_id + '.json'
36 data = json.loads(self._download_webpage(
37 jsonUrl, video_id, u'Downloading info JSON'))
40 AGE_LIMITS = {'nc17': 18, 'r': 18, 'pg13': 13, 'pg': 10, 'g': 0}
41 rating = vdata.get('rating')
43 age_limit = AGE_LIMITS.get(rating.lower())
45 age_limit = None # None = No idea
47 PREFS = {'high_quality': 2, 'low_quality': 0}
49 for format_key in ('mp4', 'webm'):
50 for qname, qurl in vdata[format_key].items():
52 'format_id': format_key + '_' + qname,
55 'preference': PREFS.get(qname),
57 self._sort_formats(formats)
61 'title': vdata['title'],
62 'description': vdata.get('description'),
63 'thumbnail': vdata.get('thumbnail'),
65 'age_limit': age_limit,