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.

98 lines
3.8 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. }, {
  30. 'url': 'http://www.cwseed.com/shows/whose-line-is-it-anyway/jeff-davis-4/?play=24282b12-ead2-42f2-95ad-26770c2c6088',
  31. 'info_dict': {
  32. 'id': '24282b12-ead2-42f2-95ad-26770c2c6088',
  33. 'ext': 'mp4',
  34. 'title': 'Jeff Davis 4',
  35. 'description': 'Jeff Davis is back to make you laugh.',
  36. 'duration': 1263,
  37. 'series': 'Whose Line Is It Anyway?',
  38. 'season_number': 11,
  39. 'season': '11',
  40. 'episode_number': 20,
  41. 'upload_date': '20151006',
  42. 'timestamp': 1444107300,
  43. },
  44. 'params': {
  45. # m3u8 download
  46. 'skip_download': True,
  47. }
  48. }, {
  49. 'url': 'http://cwtv.com/thecw/chroniclesofcisco/?play=8adebe35-f447-465f-ab52-e863506ff6d6',
  50. 'only_matching': True,
  51. }, {
  52. 'url': 'http://cwtvpr.com/the-cw/video?watch=9eee3f60-ef4e-440b-b3b2-49428ac9c54e',
  53. 'only_matching': True,
  54. }, {
  55. 'url': 'http://cwtv.com/shows/arrow/legends-of-yesterday/?watch=6b15e985-9345-4f60-baf8-56e96be57c63',
  56. 'only_matching': True,
  57. }]
  58. def _real_extract(self, url):
  59. video_id = self._match_id(url)
  60. video_data = self._download_json(
  61. 'http://metaframe.digitalsmiths.tv/v2/CWtv/assets/%s/partner/132?format=json' % video_id, video_id)
  62. formats = self._extract_m3u8_formats(
  63. video_data['videos']['variantplaylist']['uri'], video_id, 'mp4')
  64. self._sort_formats(formats)
  65. thumbnails = [{
  66. 'url': image['uri'],
  67. 'width': image.get('width'),
  68. 'height': image.get('height'),
  69. } for image_id, image in video_data['images'].items() if image.get('uri')] if video_data.get('images') else None
  70. video_metadata = video_data['assetFields']
  71. subtitles = {
  72. 'en': [{
  73. 'url': video_metadata['UnicornCcUrl'],
  74. }],
  75. } if video_metadata.get('UnicornCcUrl') else None
  76. return {
  77. 'id': video_id,
  78. 'title': video_metadata['title'],
  79. 'description': video_metadata.get('description'),
  80. 'duration': int_or_none(video_metadata.get('duration')),
  81. 'series': video_metadata.get('seriesName'),
  82. 'season_number': int_or_none(video_metadata.get('seasonNumber')),
  83. 'season': video_metadata.get('seasonName'),
  84. 'episode_number': int_or_none(video_metadata.get('episodeNumber')),
  85. 'timestamp': parse_iso8601(video_data.get('startTime')),
  86. 'thumbnails': thumbnails,
  87. 'formats': formats,
  88. 'subtitles': subtitles,
  89. }