]>
Commit | Line | Data |
---|---|---|
7c0578dc PH |
1 | from __future__ import unicode_literals |
2 | ||
b4a9bf70 | 3 | import json |
7beb36a5 | 4 | import re |
7beb36a5 PH |
5 | |
6 | from .common import InfoExtractor | |
83cebd73 | 7 | from ..utils import int_or_none |
7beb36a5 PH |
8 | |
9 | ||
10 | class CollegeHumorIE(InfoExtractor): | |
39b782b3 | 11 | _VALID_URL = r'^(?:https?://)?(?:www\.)?collegehumor\.com/(video|embed|e)/(?P<videoid>[0-9]+)/?(?P<shorttitle>.*)$' |
7beb36a5 | 12 | |
87f78946 | 13 | _TESTS = [{ |
7c0578dc | 14 | 'url': 'http://www.collegehumor.com/video/6902724/comic-con-cosplay-catastrophe', |
7c0578dc PH |
15 | 'md5': 'dcc0f5c1c8be98dc33889a191f4c26bd', |
16 | 'info_dict': { | |
83cebd73 PH |
17 | 'id': '6902724', |
18 | 'ext': 'mp4', | |
7c0578dc | 19 | 'title': 'Comic-Con Cosplay Catastrophe', |
2a5b5023 | 20 | 'description': "Fans get creative this year at San Diego. Too creative. And yes, that's really Joss Whedon.", |
7c0578dc | 21 | 'age_limit': 13, |
2a5b5023 | 22 | 'duration': 187, |
de48adda | 23 | }, |
87f78946 PH |
24 | }, |
25 | { | |
7c0578dc | 26 | 'url': 'http://www.collegehumor.com/video/3505939/font-conference', |
7c0578dc PH |
27 | 'md5': '72fa701d8ef38664a4dbb9e2ab721816', |
28 | 'info_dict': { | |
83cebd73 PH |
29 | 'id': '3505939', |
30 | 'ext': 'mp4', | |
7c0578dc | 31 | 'title': 'Font Conference', |
83cebd73 | 32 | 'description': 'This video wasn\'t long enough,', |
7c0578dc | 33 | 'age_limit': 10, |
83cebd73 | 34 | 'duration': 179, |
87f78946 | 35 | }, |
fcdea266 JMF |
36 | }, |
37 | # embedded youtube video | |
38 | { | |
a496524d | 39 | 'url': 'http://www.collegehumor.com/embed/6950306', |
fcdea266 | 40 | 'info_dict': { |
a496524d | 41 | 'id': 'Z-bao9fg6Yc', |
fcdea266 | 42 | 'ext': 'mp4', |
a496524d S |
43 | 'title': 'Young Americans Think President John F. Kennedy Died THIS MORNING IN A CAR ACCIDENT!!!', |
44 | 'uploader': 'Mark Dice', | |
45 | 'uploader_id': 'MarkDice', | |
46 | 'description': 'md5:62c3dab9351fac7bb44b53b69511d87f', | |
47 | 'upload_date': '20140127', | |
fcdea266 JMF |
48 | }, |
49 | 'params': { | |
50 | 'skip_download': True, | |
51 | }, | |
52 | 'add_ie': ['Youtube'], | |
53 | }, | |
54 | ] | |
7beb36a5 PH |
55 | |
56 | def _real_extract(self, url): | |
57 | mobj = re.match(self._VALID_URL, url) | |
7beb36a5 PH |
58 | video_id = mobj.group('videoid') |
59 | ||
b4a9bf70 PH |
60 | jsonUrl = 'http://www.collegehumor.com/moogaloop/video/' + video_id + '.json' |
61 | data = json.loads(self._download_webpage( | |
7c0578dc | 62 | jsonUrl, video_id, 'Downloading info JSON')) |
b4a9bf70 | 63 | vdata = data['video'] |
fcdea266 JMF |
64 | if vdata.get('youtubeId') is not None: |
65 | return { | |
66 | '_type': 'url', | |
67 | 'url': vdata['youtubeId'], | |
68 | 'ie_key': 'Youtube', | |
69 | } | |
b4a9bf70 | 70 | |
55033ffb PH |
71 | AGE_LIMITS = {'nc17': 18, 'r': 18, 'pg13': 13, 'pg': 10, 'g': 0} |
72 | rating = vdata.get('rating') | |
73 | if rating: | |
74 | age_limit = AGE_LIMITS.get(rating.lower()) | |
75 | else: | |
76 | age_limit = None # None = No idea | |
77 | ||
b4a9bf70 PH |
78 | PREFS = {'high_quality': 2, 'low_quality': 0} |
79 | formats = [] | |
80 | for format_key in ('mp4', 'webm'): | |
c4db377c | 81 | for qname, qurl in vdata.get(format_key, {}).items(): |
b4a9bf70 PH |
82 | formats.append({ |
83 | 'format_id': format_key + '_' + qname, | |
84 | 'url': qurl, | |
85 | 'format': format_key, | |
86 | 'preference': PREFS.get(qname), | |
87 | }) | |
b4a9bf70 PH |
88 | self._sort_formats(formats) |
89 | ||
83cebd73 | 90 | duration = int_or_none(vdata.get('duration'), 1000) |
355271fb | 91 | like_count = int_or_none(vdata.get('likes')) |
83cebd73 | 92 | |
b4a9bf70 | 93 | return { |
7beb36a5 | 94 | 'id': video_id, |
b4a9bf70 PH |
95 | 'title': vdata['title'], |
96 | 'description': vdata.get('description'), | |
97 | 'thumbnail': vdata.get('thumbnail'), | |
98 | 'formats': formats, | |
55033ffb | 99 | 'age_limit': age_limit, |
83cebd73 | 100 | 'duration': duration, |
355271fb | 101 | 'like_count': like_count, |
7beb36a5 | 102 | } |