abcnews.py 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. from .amp import AMPIE
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. parse_duration,
  5. parse_iso8601,
  6. try_get,
  7. )
  8. class AbcNewsVideoIE(AMPIE):
  9. IE_NAME = 'abcnews:video'
  10. _VALID_URL = r'''(?x)
  11. https?://
  12. (?:
  13. abcnews\.go\.com/
  14. (?:
  15. (?:[^/]+/)*video/(?P<display_id>[0-9a-z-]+)-|
  16. video/(?:embed|itemfeed)\?.*?\bid=
  17. )|
  18. fivethirtyeight\.abcnews\.go\.com/video/embed/\d+/
  19. )
  20. (?P<id>\d+)
  21. '''
  22. _TESTS = [{
  23. 'url': 'http://abcnews.go.com/ThisWeek/video/week-exclusive-irans-foreign-minister-zarif-20411932',
  24. 'info_dict': {
  25. 'id': '20411932',
  26. 'ext': 'mp4',
  27. 'display_id': 'week-exclusive-irans-foreign-minister-zarif',
  28. 'title': '\'This Week\' Exclusive: Iran\'s Foreign Minister Zarif',
  29. 'description': 'George Stephanopoulos goes one-on-one with Iranian Foreign Minister Dr. Javad Zarif.',
  30. 'duration': 180,
  31. 'thumbnail': r're:^https?://.*\.jpg$',
  32. 'timestamp': 1380454200,
  33. 'upload_date': '20130929',
  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. 'url': 'http://abcnews.go.com/video/itemfeed?id=46979033',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'https://abcnews.go.com/GMA/News/video/history-christmas-story-67894761',
  50. 'only_matching': True,
  51. }]
  52. def _real_extract(self, url):
  53. mobj = self._match_valid_url(url)
  54. display_id = mobj.group('display_id')
  55. video_id = mobj.group('id')
  56. info_dict = self._extract_feed_info(
  57. f'http://abcnews.go.com/video/itemfeed?id={video_id}')
  58. info_dict.update({
  59. 'id': video_id,
  60. 'display_id': display_id,
  61. })
  62. return info_dict
  63. class AbcNewsIE(InfoExtractor):
  64. IE_NAME = 'abcnews'
  65. _VALID_URL = r'https?://abcnews\.go\.com/(?:[^/]+/)+(?P<display_id>[0-9a-z-]+)/story\?id=(?P<id>\d+)'
  66. _TESTS = [{
  67. # Youtube Embeds
  68. 'url': 'https://abcnews.go.com/Entertainment/peter-billingsley-child-actor-christmas-story-hollywood-power/story?id=51286501',
  69. 'info_dict': {
  70. 'id': '51286501',
  71. 'title': "Peter Billingsley: From child actor in 'A Christmas Story' to Hollywood power player",
  72. 'description': 'Billingsley went from a child actor to Hollywood power player.',
  73. },
  74. 'playlist_count': 5,
  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. 'title': 'Justin Timberlake Drops Hints For Secret Single',
  81. 'description': 'Lara Spencer reports the buzziest stories of the day in "GMA" Pop News.',
  82. 'upload_date': '20160505',
  83. 'timestamp': 1462442280,
  84. },
  85. 'params': {
  86. # m3u8 download
  87. 'skip_download': True,
  88. # The embedded YouTube video is blocked due to copyright issues
  89. 'playlist_items': '1',
  90. },
  91. 'add_ie': ['AbcNewsVideo'],
  92. }, {
  93. 'url': 'http://abcnews.go.com/Technology/exclusive-apple-ceo-tim-cook-iphone-cracking-software/story?id=37173343',
  94. 'only_matching': True,
  95. }, {
  96. # inline.type == 'video'
  97. 'url': 'http://abcnews.go.com/Technology/exclusive-apple-ceo-tim-cook-iphone-cracking-software/story?id=37173343',
  98. 'only_matching': True,
  99. }]
  100. def _real_extract(self, url):
  101. story_id = self._match_id(url)
  102. webpage = self._download_webpage(url, story_id)
  103. story = self._parse_json(self._search_regex(
  104. r"window\['__abcnews__'\]\s*=\s*({.+?});",
  105. webpage, 'data'), story_id)['page']['content']['story']['everscroll'][0]
  106. article_contents = story.get('articleContents') or {}
  107. def entries():
  108. featured_video = story.get('featuredVideo') or {}
  109. feed = try_get(featured_video, lambda x: x['video']['feed'])
  110. if feed:
  111. yield {
  112. '_type': 'url',
  113. 'id': featured_video.get('id'),
  114. 'title': featured_video.get('name'),
  115. 'url': feed,
  116. 'thumbnail': featured_video.get('images'),
  117. 'description': featured_video.get('description'),
  118. 'timestamp': parse_iso8601(featured_video.get('uploadDate')),
  119. 'duration': parse_duration(featured_video.get('duration')),
  120. 'ie_key': AbcNewsVideoIE.ie_key(),
  121. }
  122. for inline in (article_contents.get('inlines') or []):
  123. inline_type = inline.get('type')
  124. if inline_type == 'iframe':
  125. iframe_url = try_get(inline, lambda x: x['attrs']['src'])
  126. if iframe_url:
  127. yield self.url_result(iframe_url)
  128. elif inline_type == 'video':
  129. video_id = inline.get('id')
  130. if video_id:
  131. yield {
  132. '_type': 'url',
  133. 'id': video_id,
  134. 'url': 'http://abcnews.go.com/video/embed?id=' + video_id,
  135. 'thumbnail': inline.get('imgSrc') or inline.get('imgDefault'),
  136. 'description': inline.get('description'),
  137. 'duration': parse_duration(inline.get('duration')),
  138. 'ie_key': AbcNewsVideoIE.ie_key(),
  139. }
  140. return self.playlist_result(
  141. entries(), story_id, article_contents.get('headline'),
  142. article_contents.get('subHead'))