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.

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