logo

youtube-dl

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

heise.py (6543B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .kaltura import KalturaIE
  5. from .youtube import YoutubeIE
  6. from ..utils import (
  7. determine_ext,
  8. int_or_none,
  9. NO_DEFAULT,
  10. parse_iso8601,
  11. smuggle_url,
  12. xpath_text,
  13. )
  14. class HeiseIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:www\.)?heise\.de/(?:[^/]+/)+[^/]+-(?P<id>[0-9]+)\.html'
  16. _TESTS = [{
  17. # kaltura embed
  18. 'url': 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html',
  19. 'info_dict': {
  20. 'id': '1_kkrq94sm',
  21. 'ext': 'mp4',
  22. 'title': "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone",
  23. 'timestamp': 1512734959,
  24. 'upload_date': '20171208',
  25. 'description': 'md5:c934cbfb326c669c2bcabcbe3d3fcd20',
  26. },
  27. 'params': {
  28. 'skip_download': True,
  29. },
  30. }, {
  31. # YouTube embed
  32. 'url': 'http://www.heise.de/newsticker/meldung/Netflix-In-20-Jahren-vom-Videoverleih-zum-TV-Revolutionaer-3814130.html',
  33. 'md5': 'e403d2b43fea8e405e88e3f8623909f1',
  34. 'info_dict': {
  35. 'id': '6kmWbXleKW4',
  36. 'ext': 'mp4',
  37. 'title': 'NEU IM SEPTEMBER | Netflix',
  38. 'description': 'md5:2131f3c7525e540d5fd841de938bd452',
  39. 'upload_date': '20170830',
  40. 'uploader': 'Netflix Deutschland, Österreich und Schweiz',
  41. 'uploader_id': 'netflixdach',
  42. },
  43. 'params': {
  44. 'skip_download': True,
  45. },
  46. }, {
  47. 'url': 'https://www.heise.de/video/artikel/nachgehakt-Wie-sichert-das-c-t-Tool-Restric-tor-Windows-10-ab-3700244.html',
  48. 'info_dict': {
  49. 'id': '1_ntrmio2s',
  50. 'ext': 'mp4',
  51. 'title': "nachgehakt: Wie sichert das c't-Tool Restric'tor Windows 10 ab?",
  52. 'description': 'md5:47e8ffb6c46d85c92c310a512d6db271',
  53. 'timestamp': 1512470717,
  54. 'upload_date': '20171205',
  55. },
  56. 'params': {
  57. 'skip_download': True,
  58. },
  59. }, {
  60. 'url': 'https://www.heise.de/ct/artikel/c-t-uplink-20-8-Staubsaugerroboter-Xiaomi-Vacuum-2-AR-Brille-Meta-2-und-Android-rooten-3959893.html',
  61. 'info_dict': {
  62. 'id': '1_59mk80sf',
  63. 'ext': 'mp4',
  64. 'title': "c't uplink 20.8: Staubsaugerroboter Xiaomi Vacuum 2, AR-Brille Meta 2 und Android rooten",
  65. 'description': 'md5:f50fe044d3371ec73a8f79fcebd74afc',
  66. 'timestamp': 1517567237,
  67. 'upload_date': '20180202',
  68. },
  69. 'params': {
  70. 'skip_download': True,
  71. },
  72. }, {
  73. 'url': 'http://www.heise.de/ct/artikel/c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2403911.html',
  74. 'only_matching': True,
  75. }, {
  76. 'url': 'http://www.heise.de/newsticker/meldung/c-t-uplink-Owncloud-Tastaturen-Peilsender-Smartphone-2404251.html?wt_mc=rss.ho.beitrag.atom',
  77. 'only_matching': True,
  78. }, {
  79. 'url': 'http://www.heise.de/ct/ausgabe/2016-12-Spiele-3214137.html',
  80. 'only_matching': True,
  81. }]
  82. def _real_extract(self, url):
  83. video_id = self._match_id(url)
  84. webpage = self._download_webpage(url, video_id)
  85. def extract_title(default=NO_DEFAULT):
  86. title = self._html_search_meta(
  87. ('fulltitle', 'title'), webpage, default=None)
  88. if not title or title == "c't":
  89. title = self._search_regex(
  90. r'<div[^>]+class="videoplayerjw"[^>]+data-title="([^"]+)"',
  91. webpage, 'title', default=None)
  92. if not title:
  93. title = self._html_search_regex(
  94. r'<h1[^>]+\bclass=["\']article_page_title[^>]+>(.+?)<',
  95. webpage, 'title', default=default)
  96. return title
  97. title = extract_title(default=None)
  98. description = self._og_search_description(
  99. webpage, default=None) or self._html_search_meta(
  100. 'description', webpage)
  101. def _make_kaltura_result(kaltura_url):
  102. return {
  103. '_type': 'url_transparent',
  104. 'url': smuggle_url(kaltura_url, {'source_url': url}),
  105. 'ie_key': KalturaIE.ie_key(),
  106. 'title': title,
  107. 'description': description,
  108. }
  109. kaltura_url = KalturaIE._extract_url(webpage)
  110. if kaltura_url:
  111. return _make_kaltura_result(kaltura_url)
  112. kaltura_id = self._search_regex(
  113. r'entry-id=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'kaltura id',
  114. default=None, group='id')
  115. if kaltura_id:
  116. return _make_kaltura_result('kaltura:2238431:%s' % kaltura_id)
  117. yt_urls = YoutubeIE._extract_urls(webpage)
  118. if yt_urls:
  119. return self.playlist_from_matches(
  120. yt_urls, video_id, title, ie=YoutubeIE.ie_key())
  121. title = extract_title()
  122. container_id = self._search_regex(
  123. r'<div class="videoplayerjw"[^>]+data-container="([0-9]+)"',
  124. webpage, 'container ID')
  125. sequenz_id = self._search_regex(
  126. r'<div class="videoplayerjw"[^>]+data-sequenz="([0-9]+)"',
  127. webpage, 'sequenz ID')
  128. doc = self._download_xml(
  129. 'http://www.heise.de/videout/feed', video_id, query={
  130. 'container': container_id,
  131. 'sequenz': sequenz_id,
  132. })
  133. formats = []
  134. for source_node in doc.findall('.//{http://rss.jwpcdn.com/}source'):
  135. label = source_node.attrib['label']
  136. height = int_or_none(self._search_regex(
  137. r'^(.*?_)?([0-9]+)p$', label, 'height', default=None))
  138. video_url = source_node.attrib['file']
  139. ext = determine_ext(video_url, '')
  140. formats.append({
  141. 'url': video_url,
  142. 'format_note': label,
  143. 'format_id': '%s_%s' % (ext, label),
  144. 'height': height,
  145. })
  146. self._sort_formats(formats)
  147. return {
  148. 'id': video_id,
  149. 'title': title,
  150. 'description': description,
  151. 'thumbnail': (xpath_text(doc, './/{http://rss.jwpcdn.com/}image')
  152. or self._og_search_thumbnail(webpage)),
  153. 'timestamp': parse_iso8601(
  154. self._html_search_meta('date', webpage)),
  155. 'formats': formats,
  156. }