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.

106 lines
4.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .amp import AMPIE
  5. from ..utils import (
  6. ExtractorError,
  7. int_or_none,
  8. parse_iso8601,
  9. )
  10. class BleacherReportIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?bleacherreport\.com/articles/(?P<id>\d+)'
  12. _TESTS = [{
  13. 'url': 'http://bleacherreport.com/articles/2496438-fsu-stat-projections-is-jalen-ramsey-best-defensive-player-in-college-football',
  14. 'md5': 'a3ffc3dc73afdbc2010f02d98f990f20',
  15. 'info_dict': {
  16. 'id': '2496438',
  17. 'ext': 'mp4',
  18. 'title': 'FSU Stat Projections: Is Jalen Ramsey Best Defensive Player in College Football?',
  19. 'uploader_id': 3992341,
  20. 'description': 'CFB, ACC, Florida State',
  21. 'timestamp': 1434380212,
  22. 'upload_date': '20150615',
  23. 'uploader': 'Team Stream Now ',
  24. },
  25. 'add_ie': ['Ooyala'],
  26. }, {
  27. 'url': 'http://bleacherreport.com/articles/2586817-aussie-golfers-get-fright-of-their-lives-after-being-chased-by-angry-kangaroo',
  28. 'md5': 'af5f90dc9c7ba1c19d0a3eac806bbf50',
  29. 'info_dict': {
  30. 'id': '2586817',
  31. 'ext': 'mp4',
  32. 'title': 'Aussie Golfers Get Fright of Their Lives After Being Chased by Angry Kangaroo',
  33. 'timestamp': 1446839961,
  34. 'uploader': 'Sean Fay',
  35. 'description': 'md5:825e94e0f3521df52fa83b2ed198fa20',
  36. 'uploader_id': 6466954,
  37. 'upload_date': '20151011',
  38. },
  39. 'add_ie': ['Youtube'],
  40. }]
  41. def _real_extract(self, url):
  42. article_id = self._match_id(url)
  43. article_data = self._download_json('http://api.bleacherreport.com/api/v1/articles/%s' % article_id, article_id)['article']
  44. thumbnails = []
  45. primary_photo = article_data.get('primaryPhoto')
  46. if primary_photo:
  47. thumbnails = [{
  48. 'url': primary_photo['url'],
  49. 'width': primary_photo.get('width'),
  50. 'height': primary_photo.get('height'),
  51. }]
  52. info = {
  53. '_type': 'url_transparent',
  54. 'id': article_id,
  55. 'title': article_data['title'],
  56. 'uploader': article_data.get('author', {}).get('name'),
  57. 'uploader_id': article_data.get('authorId'),
  58. 'timestamp': parse_iso8601(article_data.get('createdAt')),
  59. 'thumbnails': thumbnails,
  60. 'comment_count': int_or_none(article_data.get('commentsCount')),
  61. 'view_count': int_or_none(article_data.get('hitCount')),
  62. }
  63. video = article_data.get('video')
  64. if video:
  65. video_type = video['type']
  66. if video_type == 'cms.bleacherreport.com':
  67. info['url'] = 'http://bleacherreport.com/video_embed?id=%s' % video['id']
  68. elif video_type == 'ooyala.com':
  69. info['url'] = 'ooyala:%s' % video['id']
  70. elif video_type == 'youtube.com':
  71. info['url'] = video['id']
  72. elif video_type == 'vine.co':
  73. info['url'] = 'https://vine.co/v/%s' % video['id']
  74. else:
  75. info['url'] = video_type + video['id']
  76. return info
  77. else:
  78. raise ExtractorError('no video in the article', expected=True)
  79. class BleacherReportCMSIE(AMPIE):
  80. _VALID_URL = r'https?://(?:www\.)?bleacherreport\.com/video_embed\?id=(?P<id>[0-9a-f-]{36})'
  81. _TESTS = [{
  82. 'url': 'http://bleacherreport.com/video_embed?id=8fd44c2f-3dc5-4821-9118-2c825a98c0e1',
  83. 'md5': '8c2c12e3af7805152675446c905d159b',
  84. 'info_dict': {
  85. 'id': '8fd44c2f-3dc5-4821-9118-2c825a98c0e1',
  86. 'ext': 'flv',
  87. 'title': 'Cena vs. Rollins Would Expose the Heavyweight Division',
  88. 'description': 'md5:984afb4ade2f9c0db35f3267ed88b36e',
  89. },
  90. }]
  91. def _real_extract(self, url):
  92. video_id = self._match_id(url)
  93. info = self._extract_feed_info('http://cms.bleacherreport.com/media/items/%s/akamai.json' % video_id)
  94. info['id'] = video_id
  95. return info