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.

89 lines
3.0 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. )
  10. class SendtoNewsIE(JWPlatformBaseIE):
  11. _VALID_URL = r'https?://embed\.sendtonews\.com/player2/embedplayer\.php\?.*\bSC=(?P<id>[0-9A-Za-z-]+)'
  12. _TEST = {
  13. # From http://cleveland.cbslocal.com/2016/05/16/indians-score-season-high-15-runs-in-blowout-win-over-reds-rapid-reaction/
  14. 'url': 'http://embed.sendtonews.com/player2/embedplayer.php?SC=GxfCe0Zo7D-175909-5588&type=single&autoplay=on&sound=YES',
  15. 'info_dict': {
  16. 'id': 'GxfCe0Zo7D-175909-5588'
  17. },
  18. 'playlist_count': 9,
  19. # test the first video only to prevent lengthy tests
  20. 'playlist': [{
  21. 'info_dict': {
  22. 'id': '198180',
  23. 'ext': 'mp4',
  24. 'title': 'Recap: CLE 5, LAA 4',
  25. 'description': '8/14/16: Naquin, Almonte lead Indians in 5-4 win',
  26. 'duration': 57.343,
  27. 'thumbnail': 're:https?://.*\.jpg$',
  28. 'upload_date': '20160815',
  29. 'timestamp': 1471221961,
  30. },
  31. }],
  32. 'params': {
  33. # m3u8 download
  34. 'skip_download': True,
  35. },
  36. }
  37. _URL_TEMPLATE = '//embed.sendtonews.com/player2/embedplayer.php?SC=%s'
  38. @classmethod
  39. def _extract_url(cls, webpage):
  40. mobj = re.search(r'''(?x)<script[^>]+src=([\'"])
  41. (?:https?:)?//embed\.sendtonews\.com/player/responsiveembed\.php\?
  42. .*\bSC=(?P<SC>[0-9a-zA-Z-]+).*
  43. \1>''', webpage)
  44. if mobj:
  45. sc = mobj.group('SC')
  46. return cls._URL_TEMPLATE % sc
  47. def _real_extract(self, url):
  48. playlist_id = self._match_id(url)
  49. data_url = update_url_query(
  50. url.replace('embedplayer.php', 'data_read.php'),
  51. {'cmd': 'loadInitial'})
  52. playlist_data = self._download_json(data_url, playlist_id)
  53. entries = []
  54. for video in playlist_data['playlistData'][0]:
  55. info_dict = self._parse_jwplayer_data(
  56. video['jwconfiguration'],
  57. require_title=False, rtmp_params={'no_resume': True})
  58. thumbnails = []
  59. if video.get('thumbnailUrl'):
  60. thumbnails.append({
  61. 'id': 'normal',
  62. 'url': video['thumbnailUrl'],
  63. })
  64. if video.get('smThumbnailUrl'):
  65. thumbnails.append({
  66. 'id': 'small',
  67. 'url': video['smThumbnailUrl'],
  68. })
  69. info_dict.update({
  70. 'title': video['S_headLine'],
  71. 'description': video.get('S_fullStory'),
  72. 'thumbnails': thumbnails,
  73. 'duration': float_or_none(video.get('SM_length')),
  74. 'timestamp': parse_iso8601(video.get('S_sysDate'), delimiter=' '),
  75. })
  76. entries.append(info_dict)
  77. return self.playlist_result(entries, playlist_id)