logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

sevenplus.py (3304B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .brightcove import BrightcoveNewIE
  5. from ..compat import (
  6. compat_HTTPError,
  7. compat_str,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. try_get,
  12. update_url_query,
  13. )
  14. class SevenPlusIE(BrightcoveNewIE):
  15. IE_NAME = '7plus'
  16. _VALID_URL = r'https?://(?:www\.)?7plus\.com\.au/(?P<path>[^?]+\?.*?\bepisode-id=(?P<id>[^&#]+))'
  17. _TESTS = [{
  18. 'url': 'https://7plus.com.au/MTYS?episode-id=MTYS7-003',
  19. 'info_dict': {
  20. 'id': 'MTYS7-003',
  21. 'ext': 'mp4',
  22. 'title': 'S7 E3 - Wind Surf',
  23. 'description': 'md5:29c6a69f21accda7601278f81b46483d',
  24. 'uploader_id': '5303576322001',
  25. 'upload_date': '20171201',
  26. 'timestamp': 1512106377,
  27. 'series': 'Mighty Ships',
  28. 'season_number': 7,
  29. 'episode_number': 3,
  30. 'episode': 'Wind Surf',
  31. },
  32. 'params': {
  33. 'format': 'bestvideo',
  34. 'skip_download': True,
  35. }
  36. }, {
  37. 'url': 'https://7plus.com.au/UUUU?episode-id=AUMS43-001',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. path, episode_id = re.match(self._VALID_URL, url).groups()
  42. try:
  43. media = self._download_json(
  44. 'https://videoservice.swm.digital/playback', episode_id, query={
  45. 'appId': '7plus',
  46. 'deviceType': 'web',
  47. 'platformType': 'web',
  48. 'accountId': 5303576322001,
  49. 'referenceId': 'ref:' + episode_id,
  50. 'deliveryId': 'csai',
  51. 'videoType': 'vod',
  52. })['media']
  53. except ExtractorError as e:
  54. if isinstance(e.cause, compat_HTTPError) and e.cause.code == 403:
  55. raise ExtractorError(self._parse_json(
  56. e.cause.read().decode(), episode_id)[0]['error_code'], expected=True)
  57. raise
  58. for source in media.get('sources', {}):
  59. src = source.get('src')
  60. if not src:
  61. continue
  62. source['src'] = update_url_query(src, {'rule': ''})
  63. info = self._parse_brightcove_metadata(media, episode_id)
  64. content = self._download_json(
  65. 'https://component-cdn.swm.digital/content/' + path,
  66. episode_id, headers={
  67. 'market-id': 4,
  68. }, fatal=False) or {}
  69. for item in content.get('items', {}):
  70. if item.get('componentData', {}).get('componentType') == 'infoPanel':
  71. for src_key, dst_key in [('title', 'title'), ('shortSynopsis', 'description')]:
  72. value = item.get(src_key)
  73. if value:
  74. info[dst_key] = value
  75. info['series'] = try_get(
  76. item, lambda x: x['seriesLogo']['name'], compat_str)
  77. mobj = re.search(r'^S(\d+)\s+E(\d+)\s+-\s+(.+)$', info['title'])
  78. if mobj:
  79. info.update({
  80. 'season_number': int(mobj.group(1)),
  81. 'episode_number': int(mobj.group(2)),
  82. 'episode': mobj.group(3),
  83. })
  84. return info