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.

155 lines
6.4 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import parse_filesize
  6. class TagesschauIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?tagesschau\.de/multimedia/(?:[^/]+/)*?[^/#?]+?(?P<id>-?[0-9]+)(?:~_[^/#?]+?)?\.html'
  8. _TESTS = [{
  9. 'url': 'http://www.tagesschau.de/multimedia/video/video-102143.html',
  10. 'md5': '917a228bc7df7850783bc47979673a09',
  11. 'info_dict': {
  12. 'id': '102143',
  13. 'ext': 'mp4',
  14. 'title': 'Regierungsumbildung in Athen: Neue Minister in Griechenland vereidigt',
  15. 'description': 'md5:171feccd9d9b3dd54d05d501568f6359',
  16. 'thumbnail': 're:^https?:.*\.jpg$',
  17. },
  18. }, {
  19. 'url': 'http://www.tagesschau.de/multimedia/sendung/ts-5727.html',
  20. 'md5': '3c54c1f6243d279b706bde660ceec633',
  21. 'info_dict': {
  22. 'id': '5727',
  23. 'ext': 'mp4',
  24. 'description': 'md5:695c01bfd98b7e313c501386327aea59',
  25. 'title': 'Sendung: tagesschau \t04.12.2014 20:00 Uhr',
  26. 'thumbnail': 're:^https?:.*\.jpg$',
  27. },
  28. }, {
  29. 'url': 'http://www.tagesschau.de/multimedia/politikimradio/audio-18407.html',
  30. 'md5': 'aef45de271c4bf0a5db834aa40bf774c',
  31. 'info_dict': {
  32. 'id': '18407',
  33. 'ext': 'mp3',
  34. 'title': 'Flüchtlingsdebatte: Hitzig, aber wenig hilfreich',
  35. 'description': 'Flüchtlingsdebatte: Hitzig, aber wenig hilfreich',
  36. 'thumbnail': 're:^https?:.*\.jpg$',
  37. },
  38. }, {
  39. 'url': 'http://www.tagesschau.de/multimedia/sendung/tsg-3771.html',
  40. 'only_matching': True,
  41. }, {
  42. 'url': 'http://www.tagesschau.de/multimedia/sendung/tt-3827.html',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'http://www.tagesschau.de/multimedia/sendung/nm-3475.html',
  46. 'only_matching': True,
  47. }, {
  48. 'url': 'http://www.tagesschau.de/multimedia/sendung/weltspiegel-3167.html',
  49. 'only_matching': True,
  50. }, {
  51. 'url': 'http://www.tagesschau.de/multimedia/tsvorzwanzig-959.html',
  52. 'only_matching': True,
  53. }, {
  54. 'url': 'http://www.tagesschau.de/multimedia/sendung/bab/bab-3299~_bab-sendung-209.html',
  55. 'only_matching': True,
  56. }, {
  57. 'url': 'http://www.tagesschau.de/multimedia/video/video-102303~_bab-sendung-211.html',
  58. 'only_matching': True,
  59. }]
  60. _FORMATS = {
  61. 's': {'width': 256, 'height': 144, 'quality': 1},
  62. 'm': {'width': 512, 'height': 288, 'quality': 2},
  63. 'l': {'width': 960, 'height': 544, 'quality': 3},
  64. }
  65. def _real_extract(self, url):
  66. video_id = self._match_id(url)
  67. display_id = video_id.lstrip('-')
  68. webpage = self._download_webpage(url, display_id)
  69. player_url = self._html_search_meta(
  70. 'twitter:player', webpage, 'player URL', default=None)
  71. if player_url:
  72. playerpage = self._download_webpage(
  73. player_url, display_id, 'Downloading player page')
  74. formats = []
  75. for media in re.finditer(
  76. r'''(?x)
  77. (?P<q_url>["\'])(?P<url>http://media.+?)(?P=q_url)
  78. ,\s*type:(?P<q_type>["\'])(?P<type>video|audio)/(?P<ext>.+?)(?P=q_type)
  79. (?:,\s*quality:(?P<q_quality>["\'])(?P<quality>.+?)(?P=q_quality))?
  80. ''', playerpage):
  81. url = media.group('url')
  82. type_ = media.group('type')
  83. ext = media.group('ext')
  84. res = media.group('quality')
  85. f = {
  86. 'format_id': '%s_%s' % (res, ext) if res else ext,
  87. 'url': url,
  88. 'ext': ext,
  89. 'vcodec': 'none' if type_ == 'audio' else None,
  90. }
  91. f.update(self._FORMATS.get(res, {}))
  92. formats.append(f)
  93. thumbnail = self._og_search_thumbnail(playerpage)
  94. title = self._og_search_title(webpage).strip()
  95. description = self._og_search_description(webpage).strip()
  96. else:
  97. download_text = self._search_regex(
  98. r'(?s)<p>Wir bieten dieses Video in folgenden Formaten zum Download an:</p>\s*<div class="controls">(.*?)</div>\s*<p>',
  99. webpage, 'download links')
  100. links = re.finditer(
  101. r'<div class="button" title="(?P<title>[^"]*)"><a href="(?P<url>[^"]+)">(?P<name>.+?)</a></div>',
  102. download_text)
  103. formats = []
  104. for l in links:
  105. format_id = self._search_regex(
  106. r'.*/[^/.]+\.([^/]+)\.[^/.]+', l.group('url'), 'format ID')
  107. format = {
  108. 'format_id': format_id,
  109. 'url': l.group('url'),
  110. 'format_name': l.group('name'),
  111. }
  112. m = re.match(
  113. r'''(?x)
  114. Video:\s*(?P<vcodec>[a-zA-Z0-9/._-]+)\s*&\#10;
  115. (?P<width>[0-9]+)x(?P<height>[0-9]+)px&\#10;
  116. (?P<vbr>[0-9]+)kbps&\#10;
  117. Audio:\s*(?P<abr>[0-9]+)kbps,\s*(?P<audio_desc>[A-Za-z\.0-9]+)&\#10;
  118. Gr&ouml;&szlig;e:\s*(?P<filesize_approx>[0-9.,]+\s+[a-zA-Z]*B)''',
  119. l.group('title'))
  120. if m:
  121. format.update({
  122. 'format_note': m.group('audio_desc'),
  123. 'vcodec': m.group('vcodec'),
  124. 'width': int(m.group('width')),
  125. 'height': int(m.group('height')),
  126. 'abr': int(m.group('abr')),
  127. 'vbr': int(m.group('vbr')),
  128. 'filesize_approx': parse_filesize(m.group('filesize_approx')),
  129. })
  130. formats.append(format)
  131. thumbnail = self._og_search_thumbnail(webpage)
  132. description = self._html_search_regex(
  133. r'(?s)<p class="teasertext">(.*?)</p>',
  134. webpage, 'description', default=None)
  135. title = self._html_search_regex(
  136. r'<span class="headline".*?>(.*?)</span>', webpage, 'title')
  137. self._sort_formats(formats)
  138. return {
  139. 'id': display_id,
  140. 'title': title,
  141. 'thumbnail': thumbnail,
  142. 'formats': formats,
  143. 'description': description,
  144. }