bleacherreport.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. from .amp import AMPIE
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. ExtractorError,
  5. int_or_none,
  6. parse_iso8601,
  7. str_or_none,
  8. )
  9. class BleacherReportIE(InfoExtractor):
  10. _WORKING = False
  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. 'skip': 'Video removed',
  26. }, {
  27. 'url': 'http://bleacherreport.com/articles/2586817-aussie-golfers-get-fright-of-their-lives-after-being-chased-by-angry-kangaroo',
  28. 'md5': '6a5cd403418c7b01719248ca97fb0692',
  29. 'info_dict': {
  30. 'id': '2586817',
  31. 'ext': 'webm',
  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:b1601e2314c4d8eec23b6eafe086a757',
  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(f'http://api.bleacherreport.com/api/v1/articles/{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': str_or_none(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 in ('cms.bleacherreport.com', 'vid.bleacherreport.com'):
  67. info['url'] = 'http://bleacherreport.com/video_embed?id={}'.format(video['id'])
  68. elif video_type == 'youtube.com':
  69. info['url'] = video['id']
  70. elif video_type == 'vine.co':
  71. info['url'] = 'https://vine.co/v/{}'.format(video['id'])
  72. else:
  73. info['url'] = video_type + video['id']
  74. return info
  75. else:
  76. raise ExtractorError('no video in the article', expected=True)
  77. class BleacherReportCMSIE(AMPIE):
  78. _WORKING = False
  79. _VALID_URL = r'https?://(?:www\.)?bleacherreport\.com/video_embed\?id=(?P<id>[0-9a-f-]{36}|\d{5})'
  80. _TESTS = [{
  81. 'url': 'http://bleacherreport.com/video_embed?id=8fd44c2f-3dc5-4821-9118-2c825a98c0e1&library=video-cms',
  82. 'md5': '670b2d73f48549da032861130488c681',
  83. 'info_dict': {
  84. 'id': '8fd44c2f-3dc5-4821-9118-2c825a98c0e1',
  85. 'ext': 'mp4',
  86. 'title': 'Cena vs. Rollins Would Expose the Heavyweight Division',
  87. 'description': 'md5:984afb4ade2f9c0db35f3267ed88b36e',
  88. 'upload_date': '20150723',
  89. 'timestamp': 1437679032,
  90. },
  91. 'expected_warnings': [
  92. 'Unable to download f4m manifest',
  93. ],
  94. }]
  95. def _real_extract(self, url):
  96. video_id = self._match_id(url)
  97. info = self._extract_feed_info(f'http://vid.bleacherreport.com/videos/{video_id}.akamai')
  98. info['id'] = video_id
  99. return info