logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

abcnews.py (6400B)


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