You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.0 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. class CollegeHumorIE(InfoExtractor):
  6. _VALID_URL = r'^(?:https?://)?(?:www\.)?collegehumor\.com/(video|embed|e)/(?P<videoid>[0-9]+)/?(?P<shorttitle>.*)$'
  7. _TESTS = [{
  8. 'url': 'http://www.collegehumor.com/video/6902724/comic-con-cosplay-catastrophe',
  9. 'file': '6902724.mp4',
  10. 'md5': 'dcc0f5c1c8be98dc33889a191f4c26bd',
  11. 'info_dict': {
  12. 'title': 'Comic-Con Cosplay Catastrophe',
  13. 'description': 'Fans get creative this year at San Diego. Too',
  14. 'age_limit': 13,
  15. },
  16. },
  17. {
  18. 'url': 'http://www.collegehumor.com/video/3505939/font-conference',
  19. 'file': '3505939.mp4',
  20. 'md5': '72fa701d8ef38664a4dbb9e2ab721816',
  21. 'info_dict': {
  22. 'title': 'Font Conference',
  23. 'description': 'This video wasn\'t long enough, so we made it double-spaced.',
  24. 'age_limit': 10,
  25. },
  26. },
  27. # embedded youtube video
  28. {
  29. 'url': 'http://www.collegehumor.com/embed/6950457',
  30. 'info_dict': {
  31. 'id': 'W5gMp3ZjYg4',
  32. 'ext': 'mp4',
  33. 'title': 'Funny Dogs Protecting Babies Compilation 2014 [NEW HD]',
  34. 'uploader': 'Funnyplox TV',
  35. 'uploader_id': 'funnyploxtv',
  36. 'description': 'md5:b20fc87608e2837596bbc8df85a3c34d',
  37. 'upload_date': '20140128',
  38. },
  39. 'params': {
  40. 'skip_download': True,
  41. },
  42. 'add_ie': ['Youtube'],
  43. },
  44. ]
  45. def _real_extract(self, url):
  46. mobj = re.match(self._VALID_URL, url)
  47. video_id = mobj.group('videoid')
  48. jsonUrl = 'http://www.collegehumor.com/moogaloop/video/' + video_id + '.json'
  49. data = json.loads(self._download_webpage(
  50. jsonUrl, video_id, 'Downloading info JSON'))
  51. vdata = data['video']
  52. if vdata.get('youtubeId') is not None:
  53. return {
  54. '_type': 'url',
  55. 'url': vdata['youtubeId'],
  56. 'ie_key': 'Youtube',
  57. }
  58. AGE_LIMITS = {'nc17': 18, 'r': 18, 'pg13': 13, 'pg': 10, 'g': 0}
  59. rating = vdata.get('rating')
  60. if rating:
  61. age_limit = AGE_LIMITS.get(rating.lower())
  62. else:
  63. age_limit = None # None = No idea
  64. PREFS = {'high_quality': 2, 'low_quality': 0}
  65. formats = []
  66. for format_key in ('mp4', 'webm'):
  67. for qname, qurl in vdata.get(format_key, {}).items():
  68. formats.append({
  69. 'format_id': format_key + '_' + qname,
  70. 'url': qurl,
  71. 'format': format_key,
  72. 'preference': PREFS.get(qname),
  73. })
  74. self._sort_formats(formats)
  75. return {
  76. 'id': video_id,
  77. 'title': vdata['title'],
  78. 'description': vdata.get('description'),
  79. 'thumbnail': vdata.get('thumbnail'),
  80. 'formats': formats,
  81. 'age_limit': age_limit,
  82. }