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.

86 lines
3.0 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .jwplatform import JWPlatformBaseIE
  5. from ..compat import compat_parse_qs
  6. from ..utils import (
  7. ExtractorError,
  8. parse_duration,
  9. )
  10. class SendtoNewsIE(JWPlatformBaseIE):
  11. _VALID_URL = r'https?://embed\.sendtonews\.com/player/embed\.php\?(?P<query>[^#]+)'
  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/player/embed.php?SK=GxfCe0Zo7D&MK=175909&PK=5588&autoplay=on&sound=yes',
  15. 'info_dict': {
  16. 'id': 'GxfCe0Zo7D-175909-5588',
  17. 'ext': 'mp4',
  18. 'title': 'Recap: CLE 15, CIN 6',
  19. 'description': '5/16/16: Indians\' bats explode for 15 runs in a win',
  20. 'duration': 49,
  21. },
  22. 'params': {
  23. # m3u8 download
  24. 'skip_download': True,
  25. },
  26. }
  27. _URL_TEMPLATE = '//embed.sendtonews.com/player/embed.php?SK=%s&MK=%s&PK=%s'
  28. @classmethod
  29. def _extract_url(cls, webpage):
  30. mobj = re.search(r'''(?x)<script[^>]+src=([\'"])
  31. (?:https?:)?//embed\.sendtonews\.com/player/responsiveembed\.php\?
  32. .*\bSC=(?P<SC>[0-9a-zA-Z-]+).*
  33. \1>''', webpage)
  34. if mobj:
  35. sk, mk, pk = mobj.group('SC').split('-')
  36. return cls._URL_TEMPLATE % (sk, mk, pk)
  37. def _real_extract(self, url):
  38. mobj = re.match(self._VALID_URL, url)
  39. params = compat_parse_qs(mobj.group('query'))
  40. if 'SK' not in params or 'MK' not in params or 'PK' not in params:
  41. raise ExtractorError('Invalid URL', expected=True)
  42. video_id = '-'.join([params['SK'][0], params['MK'][0], params['PK'][0]])
  43. webpage = self._download_webpage(url, video_id)
  44. jwplayer_data_str = self._search_regex(
  45. r'jwplayer\("[^"]+"\)\.setup\((.+?)\);', webpage, 'JWPlayer data')
  46. js_vars = {
  47. 'w': 1024,
  48. 'h': 768,
  49. 'modeVar': 'html5',
  50. }
  51. for name, val in js_vars.items():
  52. js_val = '%d' % val if isinstance(val, int) else '"%s"' % val
  53. jwplayer_data_str = jwplayer_data_str.replace(':%s,' % name, ':%s,' % js_val)
  54. info_dict = self._parse_jwplayer_data(
  55. self._parse_json(jwplayer_data_str, video_id),
  56. video_id, require_title=False, rtmp_params={'no_resume': True})
  57. title = self._html_search_regex(
  58. r'<div[^>]+class="embedTitle">([^<]+)</div>', webpage, 'title')
  59. description = self._html_search_regex(
  60. r'<div[^>]+class="embedSubTitle">([^<]+)</div>', webpage,
  61. 'description', fatal=False)
  62. duration = parse_duration(self._html_search_regex(
  63. r'<div[^>]+class="embedDetails">([0-9:]+)', webpage,
  64. 'duration', fatal=False))
  65. info_dict.update({
  66. 'title': title,
  67. 'description': description,
  68. 'duration': duration,
  69. })
  70. return info_dict