sendtonews.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. determine_protocol,
  5. float_or_none,
  6. int_or_none,
  7. parse_iso8601,
  8. unescapeHTML,
  9. update_url_query,
  10. )
  11. class SendtoNewsIE(InfoExtractor):
  12. _WORKING = False
  13. _VALID_URL = r'https?://embed\.sendtonews\.com/player2/embedplayer\.php\?.*\bSC=(?P<id>[0-9A-Za-z-]+)'
  14. _TEST = {
  15. # From http://cleveland.cbslocal.com/2016/05/16/indians-score-season-high-15-runs-in-blowout-win-over-reds-rapid-reaction/
  16. 'url': 'http://embed.sendtonews.com/player2/embedplayer.php?SC=GxfCe0Zo7D-175909-5588&type=single&autoplay=on&sound=YES',
  17. 'info_dict': {
  18. 'id': 'GxfCe0Zo7D-175909-5588',
  19. },
  20. 'playlist_count': 8,
  21. # test the first video only to prevent lengthy tests
  22. 'playlist': [{
  23. 'info_dict': {
  24. 'id': '240385',
  25. 'ext': 'mp4',
  26. 'title': 'Indians introduce Encarnacion',
  27. 'description': 'Indians president of baseball operations Chris Antonetti and Edwin Encarnacion discuss the slugger\'s three-year contract with Cleveland',
  28. 'duration': 137.898,
  29. 'thumbnail': r're:https?://.*\.jpg$',
  30. 'upload_date': '20170105',
  31. 'timestamp': 1483649762,
  32. },
  33. }],
  34. 'params': {
  35. # m3u8 download
  36. 'skip_download': True,
  37. },
  38. }
  39. _URL_TEMPLATE = '//embed.sendtonews.com/player2/embedplayer.php?SC=%s'
  40. @classmethod
  41. def _extract_embed_urls(cls, url, webpage):
  42. mobj = re.search(r'''(?x)<script[^>]+src=([\'"])
  43. (?:https?:)?//embed\.sendtonews\.com/player/responsiveembed\.php\?
  44. .*\bSC=(?P<SC>[0-9a-zA-Z-]+).*
  45. \1>''', webpage)
  46. if mobj:
  47. sc = mobj.group('SC')
  48. yield cls._URL_TEMPLATE % sc
  49. def _real_extract(self, url):
  50. playlist_id = self._match_id(url)
  51. data_url = update_url_query(
  52. url.replace('embedplayer.php', 'data_read.php'),
  53. {'cmd': 'loadInitial'})
  54. playlist_data = self._download_json(data_url, playlist_id)
  55. entries = []
  56. for video in playlist_data['playlistData'][0]:
  57. info_dict = self._parse_jwplayer_data(
  58. video['jwconfiguration'],
  59. require_title=False, m3u8_id='hls', rtmp_params={'no_resume': True})
  60. for f in info_dict['formats']:
  61. if f.get('tbr'):
  62. continue
  63. tbr = int_or_none(self._search_regex(
  64. r'/(\d+)k/', f['url'], 'bitrate', default=None))
  65. if not tbr:
  66. continue
  67. f.update({
  68. 'format_id': f'{determine_protocol(f)}-{tbr}',
  69. 'tbr': tbr,
  70. })
  71. thumbnails = []
  72. if video.get('thumbnailUrl'):
  73. thumbnails.append({
  74. 'id': 'normal',
  75. 'url': video['thumbnailUrl'],
  76. })
  77. if video.get('smThumbnailUrl'):
  78. thumbnails.append({
  79. 'id': 'small',
  80. 'url': video['smThumbnailUrl'],
  81. })
  82. info_dict.update({
  83. 'title': video['S_headLine'].strip(),
  84. 'description': unescapeHTML(video.get('S_fullStory')),
  85. 'thumbnails': thumbnails,
  86. 'duration': float_or_none(video.get('SM_length')),
  87. 'timestamp': parse_iso8601(video.get('S_sysDate'), delimiter=' '),
  88. # 'tbr' was explicitly set to be preferred over 'height' originally,
  89. # So this is being kept unless someone can confirm this is unnecessary
  90. '_format_sort_fields': ('tbr', 'res'),
  91. })
  92. entries.append(info_dict)
  93. return self.playlist_result(entries, playlist_id)