abcnews.py 5.4 KB

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