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.

105 lines
3.8 KiB

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