logo

youtube-dl

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

abcotvs.py (4740B)


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