heise.py 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import urllib.parse
  2. from .common import InfoExtractor
  3. from .kaltura import KalturaIE
  4. from .youtube import YoutubeIE
  5. from ..utils import (
  6. NO_DEFAULT,
  7. determine_ext,
  8. int_or_none,
  9. parse_iso8601,
  10. smuggle_url,
  11. xpath_text,
  12. )
  13. class HeiseIE(InfoExtractor):
  14. _VALID_URL = r'https?://(?:www\.)?heise\.de/(?:[^/]+/)+[^/]+-(?P<id>[0-9]+)\.html'
  15. _TESTS = [{
  16. # kaltura embed
  17. 'url': 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html',
  18. 'info_dict': {
  19. 'id': '1_kkrq94sm',
  20. 'ext': 'mp4',
  21. 'title': "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone",
  22. 'timestamp': 1512734959,
  23. 'upload_date': '20171208',
  24. 'description': 'md5:c934cbfb326c669c2bcabcbe3d3fcd20',
  25. 'thumbnail': 're:^https?://.*/thumbnail/.*',
  26. 'duration': 2845,
  27. 'view_count': int,
  28. },
  29. 'params': {
  30. 'skip_download': True,
  31. },
  32. }, {
  33. # YouTube embed
  34. 'url': 'http://www.heise.de/newsticker/meldung/Netflix-In-20-Jahren-vom-Videoverleih-zum-TV-Revolutionaer-3814130.html',
  35. 'md5': 'e403d2b43fea8e405e88e3f8623909f1',
  36. 'info_dict': {
  37. 'id': '6kmWbXleKW4',
  38. 'ext': 'mp4',
  39. 'title': 'Neu im September 2017 | Netflix',
  40. 'description': 'md5:d6852d1f96bb80760608eed3b907437c',
  41. 'upload_date': '20170830',
  42. 'uploader': 'Netflix Deutschland, Österreich und Schweiz',
  43. 'uploader_id': 'netflixdach',
  44. 'categories': ['Entertainment'],
  45. 'tags': 'count:27',
  46. 'age_limit': 0,
  47. 'availability': 'public',
  48. 'comment_count': int,
  49. 'channel_id': 'UCZqgRlLcvO3Fnx_npQJygcQ',
  50. 'thumbnail': 'https://i.ytimg.com/vi_webp/6kmWbXleKW4/maxresdefault.webp',
  51. 'uploader_url': 'http://www.youtube.com/user/netflixdach',
  52. 'playable_in_embed': True,
  53. 'live_status': 'not_live',
  54. 'channel_url': 'https://www.youtube.com/channel/UCZqgRlLcvO3Fnx_npQJygcQ',
  55. 'view_count': int,
  56. 'channel': 'Netflix Deutschland, Österreich und Schweiz',
  57. 'channel_follower_count': int,
  58. 'like_count': int,
  59. 'duration': 67,
  60. },
  61. 'params': {
  62. 'skip_download': True,
  63. },
  64. }, {
  65. 'url': 'https://www.heise.de/video/artikel/nachgehakt-Wie-sichert-das-c-t-Tool-Restric-tor-Windows-10-ab-3700244.html',
  66. 'info_dict': {
  67. 'id': '1_ntrmio2s',
  68. 'ext': 'mp4',
  69. 'title': "nachgehakt: Wie sichert das c't-Tool Restric'tor Windows 10 ab?",
  70. 'description': 'md5:47e8ffb6c46d85c92c310a512d6db271',
  71. 'timestamp': 1512470717,
  72. 'upload_date': '20171205',
  73. 'duration': 786,
  74. 'view_count': int,
  75. 'thumbnail': 're:^https?://.*/thumbnail/.*',
  76. },
  77. 'params': {
  78. 'skip_download': True,
  79. },
  80. }, {
  81. # FIXME: Video m3u8 fails to download; issue with Kaltura extractor
  82. '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',
  83. 'info_dict': {
  84. 'id': '1_59mk80sf',
  85. 'ext': 'mp4',
  86. 'title': "c't uplink 20.8: Staubsaugerroboter Xiaomi Vacuum 2, AR-Brille Meta 2 und Android rooten",
  87. 'description': 'md5:f50fe044d3371ec73a8f79fcebd74afc',
  88. 'timestamp': 1517567237,
  89. 'upload_date': '20180202',
  90. },
  91. 'params': {
  92. 'skip_download': True,
  93. },
  94. }, {
  95. # videout
  96. 'url': 'https://www.heise.de/ct/artikel/c-t-uplink-3-8-Anonyme-SIM-Karten-G-Sync-Monitore-Citizenfour-2440327.html',
  97. 'info_dict': {
  98. 'id': '2440327',
  99. 'ext': 'mp4',
  100. 'title': 'c\'t uplink 3.8: Anonyme SIM-Karten, G-Sync-Monitore, Citizenfour',
  101. 'thumbnail': 'http://www.heise.de/imagine/yxM2qmol0xV3iFB7qFb70dGvXjc/gallery/',
  102. 'description': 'md5:fa164d8c8707dff124a9626d39205f5d',
  103. 'timestamp': 1414825200,
  104. 'upload_date': '20141101',
  105. },
  106. }, {
  107. 'url': 'http://www.heise.de/ct/artikel/c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2403911.html',
  108. 'only_matching': True,
  109. }, {
  110. 'url': 'http://www.heise.de/newsticker/meldung/c-t-uplink-Owncloud-Tastaturen-Peilsender-Smartphone-2404251.html?wt_mc=rss.ho.beitrag.atom',
  111. 'only_matching': True,
  112. }, {
  113. 'url': 'http://www.heise.de/ct/ausgabe/2016-12-Spiele-3214137.html',
  114. 'only_matching': True,
  115. }]
  116. def _real_extract(self, url):
  117. video_id = self._match_id(url)
  118. webpage = self._download_webpage(url, video_id)
  119. def extract_title(default=NO_DEFAULT):
  120. title = self._html_search_meta(
  121. ('fulltitle', 'title'), webpage, default=None)
  122. if not title or title == "c't":
  123. title = self._search_regex(
  124. r'<div[^>]+class="videoplayerjw"[^>]+data-title="([^"]+)"',
  125. webpage, 'title', default=None)
  126. if not title:
  127. title = self._html_search_regex(
  128. r'<h1[^>]+\bclass=["\']article_page_title[^>]+>(.+?)<',
  129. webpage, 'title', default=default)
  130. return title
  131. title = extract_title(default=None)
  132. description = self._og_search_description(
  133. webpage, default=None) or self._html_search_meta(
  134. 'description', webpage)
  135. def _make_kaltura_result(kaltura_url):
  136. return {
  137. '_type': 'url_transparent',
  138. 'url': smuggle_url(kaltura_url, {'source_url': url}),
  139. 'ie_key': KalturaIE.ie_key(),
  140. 'title': title,
  141. 'description': description,
  142. }
  143. kaltura_url = KalturaIE._extract_url(webpage)
  144. if kaltura_url:
  145. return _make_kaltura_result(kaltura_url)
  146. kaltura_id = self._search_regex(
  147. r'entry-id=(["\'])(?P<id>(?:(?!\1).)+)\1', webpage, 'kaltura id',
  148. default=None, group='id')
  149. if kaltura_id:
  150. return _make_kaltura_result(f'kaltura:2238431:{kaltura_id}')
  151. yt_urls = tuple(YoutubeIE._extract_embed_urls(url, webpage))
  152. if yt_urls:
  153. return self.playlist_from_matches(
  154. yt_urls, video_id, title, ie=YoutubeIE.ie_key())
  155. title = extract_title()
  156. api_params = urllib.parse.parse_qs(
  157. self._search_regex(r'/videout/feed\.json\?([^\']+)', webpage, 'feed params', default=None) or '')
  158. if not api_params or 'container' not in api_params or 'sequenz' not in api_params:
  159. container_id = self._search_regex(
  160. r'<div class="videoplayerjw"[^>]+data-container="([0-9]+)"',
  161. webpage, 'container ID')
  162. sequenz_id = self._search_regex(
  163. r'<div class="videoplayerjw"[^>]+data-sequenz="([0-9]+)"',
  164. webpage, 'sequenz ID')
  165. api_params = {
  166. 'container': container_id,
  167. 'sequenz': sequenz_id,
  168. }
  169. doc = self._download_xml(
  170. 'http://www.heise.de/videout/feed', video_id, query=api_params)
  171. formats = []
  172. for source_node in doc.findall('.//{http://rss.jwpcdn.com/}source'):
  173. label = source_node.attrib['label']
  174. height = int_or_none(self._search_regex(
  175. r'^(.*?_)?([0-9]+)p$', label, 'height', default=None))
  176. video_url = source_node.attrib['file']
  177. ext = determine_ext(video_url, '')
  178. formats.append({
  179. 'url': video_url,
  180. 'format_note': label,
  181. 'format_id': f'{ext}_{label}',
  182. 'height': height,
  183. })
  184. return {
  185. 'id': video_id,
  186. 'title': title,
  187. 'description': description,
  188. 'thumbnail': (xpath_text(doc, './/{http://rss.jwpcdn.com/}image')
  189. or self._og_search_thumbnail(webpage)),
  190. 'timestamp': parse_iso8601(
  191. self._html_search_meta('date', webpage)),
  192. 'formats': formats,
  193. }