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.

99 lines
3.2 KiB

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