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.

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