You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
4.2 KiB

7 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from .youtube import YoutubeIE
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. parse_iso8601,
  9. xpath_text,
  10. )
  11. class HeiseIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?heise\.de/(?:[^/]+/)+[^/]+-(?P<id>[0-9]+)\.html'
  13. _TESTS = [{
  14. 'url': 'http://www.heise.de/video/artikel/Podcast-c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2404147.html',
  15. 'md5': 'ffed432483e922e88545ad9f2f15d30e',
  16. 'info_dict': {
  17. 'id': '2404147',
  18. 'ext': 'mp4',
  19. 'title': "Podcast: c't uplink 3.3 – Owncloud / Tastaturen / Peilsender Smartphone",
  20. 'format_id': 'mp4_720p',
  21. 'timestamp': 1411812600,
  22. 'upload_date': '20140927',
  23. 'description': 'md5:c934cbfb326c669c2bcabcbe3d3fcd20',
  24. 'thumbnail': r're:^https?://.*/gallery/$',
  25. }
  26. }, {
  27. # YouTube embed
  28. 'url': 'http://www.heise.de/newsticker/meldung/Netflix-In-20-Jahren-vom-Videoverleih-zum-TV-Revolutionaer-3814130.html',
  29. 'md5': 'e403d2b43fea8e405e88e3f8623909f1',
  30. 'info_dict': {
  31. 'id': '6kmWbXleKW4',
  32. 'ext': 'mp4',
  33. 'title': 'NEU IM SEPTEMBER | Netflix',
  34. 'description': 'md5:2131f3c7525e540d5fd841de938bd452',
  35. 'upload_date': '20170830',
  36. 'uploader': 'Netflix Deutschland, Österreich und Schweiz',
  37. 'uploader_id': 'netflixdach',
  38. },
  39. 'params': {
  40. 'skip_download': True,
  41. },
  42. }, {
  43. 'url': 'http://www.heise.de/ct/artikel/c-t-uplink-3-3-Owncloud-Tastaturen-Peilsender-Smartphone-2403911.html',
  44. 'only_matching': True,
  45. }, {
  46. 'url': 'http://www.heise.de/newsticker/meldung/c-t-uplink-Owncloud-Tastaturen-Peilsender-Smartphone-2404251.html?wt_mc=rss.ho.beitrag.atom',
  47. 'only_matching': True,
  48. }, {
  49. 'url': 'http://www.heise.de/ct/ausgabe/2016-12-Spiele-3214137.html',
  50. 'only_matching': True,
  51. }]
  52. def _real_extract(self, url):
  53. video_id = self._match_id(url)
  54. webpage = self._download_webpage(url, video_id)
  55. title = self._html_search_meta('fulltitle', webpage, default=None)
  56. if not title or title == "c't":
  57. title = self._search_regex(
  58. r'<div[^>]+class="videoplayerjw"[^>]+data-title="([^"]+)"',
  59. webpage, 'title')
  60. yt_urls = YoutubeIE._extract_urls(webpage)
  61. if yt_urls:
  62. return self.playlist_from_matches(yt_urls, video_id, title, ie=YoutubeIE.ie_key())
  63. container_id = self._search_regex(
  64. r'<div class="videoplayerjw"[^>]+data-container="([0-9]+)"',
  65. webpage, 'container ID')
  66. sequenz_id = self._search_regex(
  67. r'<div class="videoplayerjw"[^>]+data-sequenz="([0-9]+)"',
  68. webpage, 'sequenz ID')
  69. doc = self._download_xml(
  70. 'http://www.heise.de/videout/feed', video_id, query={
  71. 'container': container_id,
  72. 'sequenz': sequenz_id,
  73. })
  74. formats = []
  75. for source_node in doc.findall('.//{http://rss.jwpcdn.com/}source'):
  76. label = source_node.attrib['label']
  77. height = int_or_none(self._search_regex(
  78. r'^(.*?_)?([0-9]+)p$', label, 'height', default=None))
  79. video_url = source_node.attrib['file']
  80. ext = determine_ext(video_url, '')
  81. formats.append({
  82. 'url': video_url,
  83. 'format_note': label,
  84. 'format_id': '%s_%s' % (ext, label),
  85. 'height': height,
  86. })
  87. self._sort_formats(formats)
  88. description = self._og_search_description(
  89. webpage, default=None) or self._html_search_meta(
  90. 'description', webpage)
  91. return {
  92. 'id': video_id,
  93. 'title': title,
  94. 'description': description,
  95. 'thumbnail': (xpath_text(doc, './/{http://rss.jwpcdn.com/}image') or
  96. self._og_search_thumbnail(webpage)),
  97. 'timestamp': parse_iso8601(
  98. self._html_search_meta('date', webpage)),
  99. 'formats': formats,
  100. }