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.

148 lines
5.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import calendar
  4. import re
  5. import time
  6. from .amp import AMPIE
  7. from .common import InfoExtractor
  8. from .youtube import YoutubeIE
  9. from ..compat import compat_urlparse
  10. class AbcNewsVideoIE(AMPIE):
  11. IE_NAME = 'abcnews:video'
  12. _VALID_URL = r'''(?x)
  13. https?://
  14. (?:
  15. abcnews\.go\.com/
  16. (?:
  17. [^/]+/video/(?P<display_id>[0-9a-z-]+)-|
  18. video/embed\?.*?\bid=
  19. )|
  20. fivethirtyeight\.abcnews\.go\.com/video/embed/\d+/
  21. )
  22. (?P<id>\d+)
  23. '''
  24. _TESTS = [{
  25. 'url': 'http://abcnews.go.com/ThisWeek/video/week-exclusive-irans-foreign-minister-zarif-20411932',
  26. 'info_dict': {
  27. 'id': '20411932',
  28. 'ext': 'mp4',
  29. 'display_id': 'week-exclusive-irans-foreign-minister-zarif',
  30. 'title': '\'This Week\' Exclusive: Iran\'s Foreign Minister Zarif',
  31. 'description': 'George Stephanopoulos goes one-on-one with Iranian Foreign Minister Dr. Javad Zarif.',
  32. 'duration': 180,
  33. 'thumbnail': r're:^https?://.*\.jpg$',
  34. },
  35. 'params': {
  36. # m3u8 download
  37. 'skip_download': True,
  38. },
  39. }, {
  40. 'url': 'http://abcnews.go.com/video/embed?id=46979033',
  41. 'only_matching': True,
  42. }, {
  43. 'url': 'http://abcnews.go.com/2020/video/2020-husband-stands-teacher-jail-student-affairs-26119478',
  44. 'only_matching': True,
  45. }]
  46. def _real_extract(self, url):
  47. mobj = re.match(self._VALID_URL, url)
  48. display_id = mobj.group('display_id')
  49. video_id = mobj.group('id')
  50. info_dict = self._extract_feed_info(
  51. 'http://abcnews.go.com/video/itemfeed?id=%s' % video_id)
  52. info_dict.update({
  53. 'id': video_id,
  54. 'display_id': display_id,
  55. })
  56. return info_dict
  57. class AbcNewsIE(InfoExtractor):
  58. IE_NAME = 'abcnews'
  59. _VALID_URL = r'https?://abcnews\.go\.com/(?:[^/]+/)+(?P<display_id>[0-9a-z-]+)/story\?id=(?P<id>\d+)'
  60. _TESTS = [{
  61. 'url': 'http://abcnews.go.com/Blotter/News/dramatic-video-rare-death-job-america/story?id=10498713#.UIhwosWHLjY',
  62. 'info_dict': {
  63. 'id': '10505354',
  64. 'ext': 'flv',
  65. 'display_id': 'dramatic-video-rare-death-job-america',
  66. 'title': 'Occupational Hazards',
  67. 'description': 'Nightline investigates the dangers that lurk at various jobs.',
  68. 'thumbnail': r're:^https?://.*\.jpg$',
  69. 'upload_date': '20100428',
  70. 'timestamp': 1272412800,
  71. },
  72. 'add_ie': ['AbcNewsVideo'],
  73. }, {
  74. 'url': 'http://abcnews.go.com/Entertainment/justin-timberlake-performs-stop-feeling-eurovision-2016/story?id=39125818',
  75. 'info_dict': {
  76. 'id': '38897857',
  77. 'ext': 'mp4',
  78. 'display_id': 'justin-timberlake-performs-stop-feeling-eurovision-2016',
  79. 'title': 'Justin Timberlake Drops Hints For Secret Single',
  80. 'description': 'Lara Spencer reports the buzziest stories of the day in "GMA" Pop News.',
  81. 'upload_date': '20160515',
  82. 'timestamp': 1463329500,
  83. },
  84. 'params': {
  85. # m3u8 download
  86. 'skip_download': True,
  87. # The embedded YouTube video is blocked due to copyright issues
  88. 'playlist_items': '1',
  89. },
  90. 'add_ie': ['AbcNewsVideo'],
  91. }, {
  92. 'url': 'http://abcnews.go.com/Technology/exclusive-apple-ceo-tim-cook-iphone-cracking-software/story?id=37173343',
  93. 'only_matching': True,
  94. }]
  95. def _real_extract(self, url):
  96. mobj = re.match(self._VALID_URL, url)
  97. display_id = mobj.group('display_id')
  98. video_id = mobj.group('id')
  99. webpage = self._download_webpage(url, video_id)
  100. video_url = self._search_regex(
  101. r'window\.abcnvideo\.url\s*=\s*"([^"]+)"', webpage, 'video URL')
  102. full_video_url = compat_urlparse.urljoin(url, video_url)
  103. youtube_url = YoutubeIE._extract_url(webpage)
  104. timestamp = None
  105. date_str = self._html_search_regex(
  106. r'<span[^>]+class="timestamp">([^<]+)</span>',
  107. webpage, 'timestamp', fatal=False)
  108. if date_str:
  109. tz_offset = 0
  110. if date_str.endswith(' ET'): # Eastern Time
  111. tz_offset = -5
  112. date_str = date_str[:-3]
  113. date_formats = ['%b. %d, %Y', '%b %d, %Y, %I:%M %p']
  114. for date_format in date_formats:
  115. try:
  116. timestamp = calendar.timegm(time.strptime(date_str.strip(), date_format))
  117. except ValueError:
  118. continue
  119. if timestamp is not None:
  120. timestamp -= tz_offset * 3600
  121. entry = {
  122. '_type': 'url_transparent',
  123. 'ie_key': AbcNewsVideoIE.ie_key(),
  124. 'url': full_video_url,
  125. 'id': video_id,
  126. 'display_id': display_id,
  127. 'timestamp': timestamp,
  128. }
  129. if youtube_url:
  130. entries = [entry, self.url_result(youtube_url, ie=YoutubeIE.ie_key())]
  131. return self.playlist_result(entries)
  132. return entry