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.

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