abcotvs.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. dict_get,
  4. int_or_none,
  5. try_get,
  6. )
  7. class ABCOTVSIE(InfoExtractor):
  8. IE_NAME = 'abcotvs'
  9. IE_DESC = 'ABC Owned Television Stations'
  10. _VALID_URL = r'https?://(?P<site>abc(?:7(?:news|ny|chicago)?|11|13|30)|6abc)\.com(?:(?:/[^/]+)*/(?P<display_id>[^/]+))?/(?P<id>\d+)'
  11. _TESTS = [
  12. {
  13. 'url': 'http://abc7news.com/entertainment/east-bay-museum-celebrates-vintage-synthesizers/472581/',
  14. 'info_dict': {
  15. 'id': '472548',
  16. 'display_id': 'east-bay-museum-celebrates-vintage-synthesizers',
  17. 'ext': 'mp4',
  18. 'title': 'East Bay museum celebrates synthesized music',
  19. 'description': 'md5:24ed2bd527096ec2a5c67b9d5a9005f3',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'timestamp': 1421118520,
  22. 'upload_date': '20150113',
  23. },
  24. 'params': {
  25. # m3u8 download
  26. 'skip_download': True,
  27. },
  28. },
  29. {
  30. 'url': 'http://abc7news.com/472581',
  31. 'only_matching': True,
  32. },
  33. {
  34. 'url': 'https://6abc.com/man-75-killed-after-being-struck-by-vehicle-in-chester/5725182/',
  35. 'only_matching': True,
  36. },
  37. ]
  38. _SITE_MAP = {
  39. '6abc': 'wpvi',
  40. 'abc11': 'wtvd',
  41. 'abc13': 'ktrk',
  42. 'abc30': 'kfsn',
  43. 'abc7': 'kabc',
  44. 'abc7chicago': 'wls',
  45. 'abc7news': 'kgo',
  46. 'abc7ny': 'wabc',
  47. }
  48. def _real_extract(self, url):
  49. site, display_id, video_id = self._match_valid_url(url).groups()
  50. display_id = display_id or video_id
  51. station = self._SITE_MAP[site]
  52. data = self._download_json(
  53. 'https://api.abcotvs.com/v2/content', display_id, query={
  54. 'id': video_id,
  55. 'key': f'otv.web.{station}.story',
  56. 'station': station,
  57. })['data']
  58. video = try_get(data, lambda x: x['featuredMedia']['video'], dict) or data
  59. video_id = str(dict_get(video, ('id', 'publishedKey'), video_id))
  60. title = video.get('title') or video['linkText']
  61. formats = []
  62. m3u8_url = video.get('m3u8')
  63. if m3u8_url:
  64. formats = self._extract_m3u8_formats(
  65. video['m3u8'].split('?')[0], display_id, 'mp4', m3u8_id='hls', fatal=False)
  66. mp4_url = video.get('mp4')
  67. if mp4_url:
  68. formats.append({
  69. 'abr': 128,
  70. 'format_id': 'https',
  71. 'height': 360,
  72. 'url': mp4_url,
  73. 'width': 640,
  74. })
  75. image = video.get('image') or {}
  76. return {
  77. 'id': video_id,
  78. 'display_id': display_id,
  79. 'title': title,
  80. 'description': dict_get(video, ('description', 'caption'), try_get(video, lambda x: x['meta']['description'])),
  81. 'thumbnail': dict_get(image, ('source', 'dynamicSource')),
  82. 'timestamp': int_or_none(video.get('date')),
  83. 'duration': int_or_none(video.get('length')),
  84. 'formats': formats,
  85. }
  86. class ABCOTVSClipsIE(InfoExtractor):
  87. IE_NAME = 'abcotvs:clips'
  88. _VALID_URL = r'https?://clips\.abcotvs\.com/(?:[^/]+/)*video/(?P<id>\d+)'
  89. _TEST = {
  90. 'url': 'https://clips.abcotvs.com/kabc/video/214814',
  91. 'info_dict': {
  92. 'id': '214814',
  93. 'ext': 'mp4',
  94. 'title': 'SpaceX launch pad explosion destroys rocket, satellite',
  95. 'description': 'md5:9f186e5ad8f490f65409965ee9c7be1b',
  96. 'upload_date': '20160901',
  97. 'timestamp': 1472756695,
  98. },
  99. 'params': {
  100. # m3u8 download
  101. 'skip_download': True,
  102. },
  103. }
  104. def _real_extract(self, url):
  105. video_id = self._match_id(url)
  106. video_data = self._download_json('https://clips.abcotvs.com/vogo/video/getByIds?ids=' + video_id, video_id)['results'][0]
  107. title = video_data['title']
  108. formats = self._extract_m3u8_formats(
  109. video_data['videoURL'].split('?')[0], video_id, 'mp4')
  110. return {
  111. 'id': video_id,
  112. 'title': title,
  113. 'description': video_data.get('description'),
  114. 'thumbnail': video_data.get('thumbnailURL'),
  115. 'duration': int_or_none(video_data.get('duration')),
  116. 'timestamp': int_or_none(video_data.get('pubDate')),
  117. 'formats': formats,
  118. }