1 from __future__ import unicode_literals
6 from .common import InfoExtractor
9 class CollegeHumorIE(InfoExtractor):
10 _VALID_URL = r'^(?:https?://)?(?:www\.)?collegehumor\.com/(video|embed|e)/(?P<videoid>[0-9]+)/?(?P<shorttitle>.*)$'
13 'url': 'http://www.collegehumor.com/video/6902724/comic-con-cosplay-catastrophe',
14 'file': '6902724.mp4',
15 'md5': 'dcc0f5c1c8be98dc33889a191f4c26bd',
17 'title': 'Comic-Con Cosplay Catastrophe',
18 'description': 'Fans get creative this year at San Diego. Too',
23 'url': 'http://www.collegehumor.com/video/3505939/font-conference',
24 'file': '3505939.mp4',
25 'md5': '72fa701d8ef38664a4dbb9e2ab721816',
27 'title': 'Font Conference',
28 'description': 'This video wasn\'t long enough, so we made it double-spaced.',
32 # embedded youtube video
34 'url': 'http://www.collegehumor.com/embed/6950457',
38 'title': 'Funny Dogs Protecting Babies Compilation 2014 [NEW HD]',
39 'uploader': 'Funnyplox TV',
40 'uploader_id': 'funnyploxtv',
41 'description': 'md5:506f69f7a297ed698ced3375f2363b0e',
42 'upload_date': '20140128',
45 'skip_download': True,
47 'add_ie': ['Youtube'],
51 def _real_extract(self, url):
52 mobj = re.match(self._VALID_URL, url)
53 video_id = mobj.group('videoid')
55 jsonUrl = 'http://www.collegehumor.com/moogaloop/video/' + video_id + '.json'
56 data = json.loads(self._download_webpage(
57 jsonUrl, video_id, 'Downloading info JSON'))
59 if vdata.get('youtubeId') is not None:
62 'url': vdata['youtubeId'],
66 AGE_LIMITS = {'nc17': 18, 'r': 18, 'pg13': 13, 'pg': 10, 'g': 0}
67 rating = vdata.get('rating')
69 age_limit = AGE_LIMITS.get(rating.lower())
71 age_limit = None # None = No idea
73 PREFS = {'high_quality': 2, 'low_quality': 0}
75 for format_key in ('mp4', 'webm'):
76 for qname, qurl in vdata.get(format_key, {}).items():
78 'format_id': format_key + '_' + qname,
81 'preference': PREFS.get(qname),
83 self._sort_formats(formats)
87 'title': vdata['title'],
88 'description': vdata.get('description'),
89 'thumbnail': vdata.get('thumbnail'),
91 'age_limit': age_limit,