abcotvs.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_iso8601,
  8. )
  9. class ABCOTVSIE(InfoExtractor):
  10. IE_NAME = 'abcotvs'
  11. _VALID_URL = r'https?://(?:abc(?:7(?:news|ny|chicago)?|11|13|30)|6abc)\.com(?:/[^/]+/(?P<display_id>[^/]+))?/(?P<id>\d+)'
  12. _TESTS = [
  13. {
  14. 'url': 'http://abc7news.com/entertainment/east-bay-museum-celebrates-vintage-synthesizers/472581/',
  15. 'info_dict': {
  16. 'id': '472581',
  17. 'display_id': 'east-bay-museum-celebrates-vintage-synthesizers',
  18. 'ext': 'mp4',
  19. 'title': 'East Bay museum celebrates vintage synthesizers',
  20. 'description': 'md5:a4f10fb2f2a02565c1749d4adbab4b10',
  21. 'thumbnail': 're:^https?://.*\.jpg$',
  22. 'timestamp': 1421123075,
  23. 'upload_date': '20150113',
  24. 'uploader': 'Jonathan Bloom',
  25. },
  26. 'params': {
  27. # m3u8 download
  28. 'skip_download': True,
  29. },
  30. },
  31. {
  32. 'url': 'http://abc7news.com/472581',
  33. 'only_matching': True,
  34. },
  35. ]
  36. def _real_extract(self, url):
  37. mobj = re.match(self._VALID_URL, url)
  38. video_id = mobj.group('id')
  39. display_id = mobj.group('display_id') or video_id
  40. webpage = self._download_webpage(url, display_id)
  41. m3u8 = self._html_search_meta(
  42. 'contentURL', webpage, 'm3u8 url', fatal=True).split('?')[0]
  43. formats = self._extract_m3u8_formats(m3u8, display_id, 'mp4')
  44. self._sort_formats(formats)
  45. title = self._og_search_title(webpage).strip()
  46. description = self._og_search_description(webpage).strip()
  47. thumbnail = self._og_search_thumbnail(webpage)
  48. timestamp = parse_iso8601(self._search_regex(
  49. r'<div class="meta">\s*<time class="timeago" datetime="([^"]+)">',
  50. webpage, 'upload date', fatal=False))
  51. uploader = self._search_regex(
  52. r'rel="author">([^<]+)</a>',
  53. webpage, 'uploader', default=None)
  54. return {
  55. 'id': video_id,
  56. 'display_id': display_id,
  57. 'title': title,
  58. 'description': description,
  59. 'thumbnail': thumbnail,
  60. 'timestamp': timestamp,
  61. 'uploader': uploader,
  62. 'formats': formats,
  63. }
  64. class ABCOTVSClipsIE(InfoExtractor):
  65. IE_NAME = 'abcotvs:clips'
  66. _VALID_URL = r'https?://clips\.abcotvs\.com/(?:[^/]+/)*video/(?P<id>\d+)'
  67. _TEST = {
  68. 'url': 'https://clips.abcotvs.com/kabc/video/214814',
  69. 'info_dict': {
  70. 'id': '214814',
  71. 'ext': 'mp4',
  72. 'title': 'SpaceX launch pad explosion destroys rocket, satellite',
  73. 'description': 'md5:9f186e5ad8f490f65409965ee9c7be1b',
  74. 'upload_date': '20160901',
  75. 'timestamp': 1472756695,
  76. },
  77. 'params': {
  78. # m3u8 download
  79. 'skip_download': True,
  80. },
  81. }
  82. def _real_extract(self, url):
  83. video_id = self._match_id(url)
  84. video_data = self._download_json('https://clips.abcotvs.com/vogo/video/getByIds?ids=' + video_id, video_id)['results'][0]
  85. title = video_data['title']
  86. formats = self._extract_m3u8_formats(
  87. video_data['videoURL'].split('?')[0], video_id, 'mp4')
  88. self._sort_formats(formats)
  89. return {
  90. 'id': video_id,
  91. 'title': title,
  92. 'description': video_data.get('description'),
  93. 'thumbnail': video_data.get('thumbnailURL'),
  94. 'duration': int_or_none(video_data.get('duration')),
  95. 'timestamp': int_or_none(video_data.get('pubDate')),
  96. 'formats': formats,
  97. }