cwtv.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. ExtractorError,
  4. int_or_none,
  5. parse_age_limit,
  6. parse_iso8601,
  7. smuggle_url,
  8. str_or_none,
  9. )
  10. class CWTVIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?cw(?:tv(?:pr)?|seed)\.com/(?:shows/)?(?:[^/]+/)+[^?]*\?.*\b(?:play|watch)=(?P<id>[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12})'
  12. _TESTS = [{
  13. 'url': 'http://cwtv.com/shows/arrow/legends-of-yesterday/?play=6b15e985-9345-4f60-baf8-56e96be57c63',
  14. 'info_dict': {
  15. 'id': '6b15e985-9345-4f60-baf8-56e96be57c63',
  16. 'ext': 'mp4',
  17. 'title': 'Legends of Yesterday',
  18. 'description': 'Oliver and Barry Allen take Kendra Saunders and Carter Hall to a remote location to keep them hidden from Vandal Savage while they figure out how to defeat him.',
  19. 'duration': 2665,
  20. 'series': 'Arrow',
  21. 'season_number': 4,
  22. 'season': '4',
  23. 'episode_number': 8,
  24. 'upload_date': '20151203',
  25. 'timestamp': 1449122100,
  26. },
  27. 'params': {
  28. # m3u8 download
  29. 'skip_download': True,
  30. },
  31. 'skip': 'redirect to http://cwtv.com/shows/arrow/',
  32. }, {
  33. 'url': 'http://www.cwseed.com/shows/whose-line-is-it-anyway/jeff-davis-4/?play=24282b12-ead2-42f2-95ad-26770c2c6088',
  34. 'info_dict': {
  35. 'id': '24282b12-ead2-42f2-95ad-26770c2c6088',
  36. 'ext': 'mp4',
  37. 'title': 'Jeff Davis 4',
  38. 'description': 'Jeff Davis is back to make you laugh.',
  39. 'duration': 1263,
  40. 'series': 'Whose Line Is It Anyway?',
  41. 'season_number': 11,
  42. 'episode_number': 20,
  43. 'upload_date': '20151006',
  44. 'timestamp': 1444107300,
  45. 'age_limit': 14,
  46. 'uploader': 'CWTV',
  47. 'thumbnail': r're:^https?://.*\.jpe?g$',
  48. 'chapters': 'count:4',
  49. 'episode': 'Episode 20',
  50. 'season': 'Season 11',
  51. },
  52. 'params': {
  53. # m3u8 download
  54. 'skip_download': True,
  55. },
  56. }, {
  57. 'url': 'http://cwtv.com/thecw/chroniclesofcisco/?play=8adebe35-f447-465f-ab52-e863506ff6d6',
  58. 'only_matching': True,
  59. }, {
  60. 'url': 'http://cwtvpr.com/the-cw/video?watch=9eee3f60-ef4e-440b-b3b2-49428ac9c54e',
  61. 'only_matching': True,
  62. }, {
  63. 'url': 'http://cwtv.com/shows/arrow/legends-of-yesterday/?watch=6b15e985-9345-4f60-baf8-56e96be57c63',
  64. 'only_matching': True,
  65. }]
  66. def _real_extract(self, url):
  67. video_id = self._match_id(url)
  68. data = self._download_json(
  69. 'http://images.cwtv.com/feed/mobileapp/video-meta/apiversion_8/guid_' + video_id,
  70. video_id)
  71. if data.get('result') != 'ok':
  72. raise ExtractorError(data['msg'], expected=True)
  73. video_data = data['video']
  74. title = video_data['title']
  75. mpx_url = video_data.get('mpx_url') or f'http://link.theplatform.com/s/cwtv/media/guid/2703454149/{video_id}?formats=M3U'
  76. season = str_or_none(video_data.get('season'))
  77. episode = str_or_none(video_data.get('episode'))
  78. if episode and season:
  79. episode = episode[len(season):]
  80. return {
  81. '_type': 'url_transparent',
  82. 'id': video_id,
  83. 'title': title,
  84. 'url': smuggle_url(mpx_url, {'force_smil_url': True}),
  85. 'description': video_data.get('description_long'),
  86. 'duration': int_or_none(video_data.get('duration_secs')),
  87. 'series': video_data.get('series_name'),
  88. 'season_number': int_or_none(season),
  89. 'episode_number': int_or_none(episode),
  90. 'timestamp': parse_iso8601(video_data.get('start_time')),
  91. 'age_limit': parse_age_limit(video_data.get('rating')),
  92. 'ie_key': 'ThePlatform',
  93. 'thumbnail': video_data.get('large_thumbnail'),
  94. }