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.

114 lines
4.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. parse_iso8601,
  7. )
  8. class CWTVIE(InfoExtractor):
  9. _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})'
  10. _TESTS = [{
  11. 'url': 'http://cwtv.com/shows/arrow/legends-of-yesterday/?play=6b15e985-9345-4f60-baf8-56e96be57c63',
  12. 'info_dict': {
  13. 'id': '6b15e985-9345-4f60-baf8-56e96be57c63',
  14. 'ext': 'mp4',
  15. 'title': 'Legends of Yesterday',
  16. '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.',
  17. 'duration': 2665,
  18. 'series': 'Arrow',
  19. 'season_number': 4,
  20. 'season': '4',
  21. 'episode_number': 8,
  22. 'upload_date': '20151203',
  23. 'timestamp': 1449122100,
  24. },
  25. 'params': {
  26. # m3u8 download
  27. 'skip_download': True,
  28. },
  29. 'skip': 'redirect to http://cwtv.com/shows/arrow/',
  30. }, {
  31. 'url': 'http://www.cwseed.com/shows/whose-line-is-it-anyway/jeff-davis-4/?play=24282b12-ead2-42f2-95ad-26770c2c6088',
  32. 'info_dict': {
  33. 'id': '24282b12-ead2-42f2-95ad-26770c2c6088',
  34. 'ext': 'mp4',
  35. 'title': 'Jeff Davis 4',
  36. 'description': 'Jeff Davis is back to make you laugh.',
  37. 'duration': 1263,
  38. 'series': 'Whose Line Is It Anyway?',
  39. 'season_number': 11,
  40. 'season': '11',
  41. 'episode_number': 20,
  42. 'upload_date': '20151006',
  43. 'timestamp': 1444107300,
  44. },
  45. }, {
  46. 'url': 'http://cwtv.com/thecw/chroniclesofcisco/?play=8adebe35-f447-465f-ab52-e863506ff6d6',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'http://cwtvpr.com/the-cw/video?watch=9eee3f60-ef4e-440b-b3b2-49428ac9c54e',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'http://cwtv.com/shows/arrow/legends-of-yesterday/?watch=6b15e985-9345-4f60-baf8-56e96be57c63',
  53. 'only_matching': True,
  54. }]
  55. def _real_extract(self, url):
  56. video_id = self._match_id(url)
  57. video_data = None
  58. formats = []
  59. for partner in (154, 213):
  60. vdata = self._download_json(
  61. 'http://metaframe.digitalsmiths.tv/v2/CWtv/assets/%s/partner/%d?format=json' % (video_id, partner), video_id, fatal=False)
  62. if not vdata:
  63. continue
  64. video_data = vdata
  65. for quality, quality_data in vdata.get('videos', {}).items():
  66. quality_url = quality_data.get('uri')
  67. if not quality_url:
  68. continue
  69. if quality == 'variantplaylist':
  70. formats.extend(self._extract_m3u8_formats(
  71. quality_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
  72. else:
  73. tbr = int_or_none(quality_data.get('bitrate'))
  74. format_id = 'http' + ('-%d' % tbr if tbr else '')
  75. if self._is_valid_url(quality_url, video_id, format_id):
  76. formats.append({
  77. 'format_id': format_id,
  78. 'url': quality_url,
  79. 'tbr': tbr,
  80. })
  81. self._sort_formats(formats)
  82. thumbnails = [{
  83. 'url': image['uri'],
  84. 'width': image.get('width'),
  85. 'height': image.get('height'),
  86. } for image_id, image in video_data['images'].items() if image.get('uri')] if video_data.get('images') else None
  87. video_metadata = video_data['assetFields']
  88. subtitles = {
  89. 'en': [{
  90. 'url': video_metadata['UnicornCcUrl'],
  91. }],
  92. } if video_metadata.get('UnicornCcUrl') else None
  93. return {
  94. 'id': video_id,
  95. 'title': video_metadata['title'],
  96. 'description': video_metadata.get('description'),
  97. 'duration': int_or_none(video_metadata.get('duration')),
  98. 'series': video_metadata.get('seriesName'),
  99. 'season_number': int_or_none(video_metadata.get('seasonNumber')),
  100. 'season': video_metadata.get('seasonName'),
  101. 'episode_number': int_or_none(video_metadata.get('episodeNumber')),
  102. 'timestamp': parse_iso8601(video_data.get('startTime')),
  103. 'thumbnails': thumbnails,
  104. 'formats': formats,
  105. 'subtitles': subtitles,
  106. }