bleacherreport.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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:e95afafa43619816552723878b3b0a84',
  36. 'uploader_id': 6466954,
  37. 'upload_date': '20151011',
  38. },
  39. 'add_ie': ['Youtube'],
  40. },{
  41. 'url': 'http://bleacherreport.com/articles/2496438-fsu-stat-projections-is-jalen-ramsey-best-defensive-player-in-college-football',
  42. 'md5': 'a3ffc3dc73afdbc2010f02d98f990f20',
  43. 'info_dict': {
  44. 'id': '2496438',
  45. 'ext': 'mp4',
  46. 'title': 'FSU Stat Projections: Is Jalen Ramsey Best Defensive Player in College Football?',
  47. 'upload_date': '20150615',
  48. 'uploader': 'Team Stream Now ',
  49. 'timestamp': 1434380212,
  50. 'description': 'CFB, ACC, Florida State',
  51. 'uploader_id': 3992341,
  52. },
  53. 'add_ie': ['Vine'],
  54. }]
  55. def _real_extract(self, url):
  56. article_id = self._match_id(url)
  57. article_data = self._download_json('http://api.bleacherreport.com/api/v1/articles/%s' % article_id, article_id)['article']
  58. thumbnails = []
  59. primary_photo = article_data.get('primaryPhoto')
  60. if primary_photo:
  61. thumbnails = [{
  62. 'url': primary_photo['url'],
  63. 'width': primary_photo.get('width'),
  64. 'height': primary_photo.get('height'),
  65. }]
  66. info = {
  67. '_type': 'url_transparent',
  68. 'id': article_id,
  69. 'title': article_data['title'],
  70. 'uploader': article_data.get('author', {}).get('name'),
  71. 'uploader_id': article_data.get('authorId'),
  72. 'timestamp': parse_iso8601(article_data.get('createdAt')),
  73. 'thumbnails': thumbnails,
  74. 'comment_count': int_or_none(article_data.get('commentsCount')),
  75. 'view_count': int_or_none(article_data.get('hitCount')),
  76. }
  77. video = article_data.get('video')
  78. if video:
  79. video_type = video['type']
  80. if video_type == 'cms.bleacherreport.com':
  81. info['url'] = 'http://bleacherreport.com/video_embed?id=%s' % video['id']
  82. elif video_type == 'ooyala.com':
  83. info['url'] = 'ooyala:%s' % video['id']
  84. elif video_type == 'youtube.com':
  85. info['url'] = video['id']
  86. elif video_type == 'vine.co':
  87. info['url'] = 'https://vine.co/v/%s' % video['id']
  88. else:
  89. info['url'] = video_type + video['id']
  90. return info
  91. else:
  92. raise ExtractorError('no video in the article', expected=True)
  93. class BleacherReportCMSIE(AMPIE):
  94. _VALID_URL = r'https?://(?:www\.)?bleacherreport\.com/video_embed\?id=(?P<id>[0-9a-f-]{36})'
  95. _TESTS = [{
  96. 'url': 'http://bleacherreport.com/video_embed?id=8fd44c2f-3dc5-4821-9118-2c825a98c0e1',
  97. 'md5': 'f0ca220af012d4df857b54f792c586bb',
  98. 'info_dict': {
  99. 'id': '8fd44c2f-3dc5-4821-9118-2c825a98c0e1',
  100. 'ext': 'flv',
  101. 'title': 'Cena vs. Rollins Would Expose the Heavyweight Division',
  102. 'description': 'md5:984afb4ade2f9c0db35f3267ed88b36e',
  103. },
  104. }]
  105. def _real_extract(self, url):
  106. video_id = self._match_id(url)
  107. info = self._extract_feed_info('http://cms.bleacherreport.com/media/items/%s/akamai.json' % video_id)
  108. info['id'] = video_id
  109. return info