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.

122 lines
4.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. ExtractorError,
  8. qualities,
  9. )
  10. class ARDIE(InfoExtractor):
  11. _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
  12. _TESTS = [{
  13. 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
  14. 'file': '22429276.mp4',
  15. 'md5': '469751912f1de0816a9fc9df8336476c',
  16. 'info_dict': {
  17. 'title': 'Vertrauen ist gut, Spionieren ist besser - Geht so deutsch-amerikanische Freundschaft?',
  18. 'description': 'Das Erste Mediathek [ARD]: Vertrauen ist gut, Spionieren ist besser - Geht so deutsch-amerikanische Freundschaft?, Anne Will, Über die Spionage-Affäre diskutieren Clemens Binninger, Katrin Göring-Eckardt, Georg Mascolo, Andrew B. Denison und Constanze Kurz.. Das Video zur Sendung Anne Will am Mittwoch, 16.07.2014',
  19. },
  20. 'skip': 'Blocked outside of Germany',
  21. }, {
  22. 'url': 'http://www.ardmediathek.de/tv/Tatort/Das-Wunder-von-Wolbeck-Video-tgl-ab-20/Das-Erste/Video?documentId=22490580&bcastId=602916',
  23. 'info_dict': {
  24. 'id': '22490580',
  25. 'ext': 'mp4',
  26. 'title': 'Das Wunder von Wolbeck (Video tgl. ab 20 Uhr)',
  27. 'description': 'Auf einem restaurierten Hof bei Wolbeck wird der Heilpraktiker Raffael Lembeck eines morgens von seiner Frau Stella tot aufgefunden. Das Opfer war offensichtlich in seiner Praxis zu Fall gekommen und ist dann verblutet, erklärt Prof. Boerne am Tatort.',
  28. },
  29. 'skip': 'Blocked outside of Germany',
  30. }]
  31. def _real_extract(self, url):
  32. # determine video id from url
  33. m = re.match(self._VALID_URL, url)
  34. numid = re.search(r'documentId=([0-9]+)', url)
  35. if numid:
  36. video_id = numid.group(1)
  37. else:
  38. video_id = m.group('video_id')
  39. webpage = self._download_webpage(url, video_id)
  40. title = self._html_search_regex(
  41. [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
  42. r'<meta name="dcterms.title" content="(.*?)"/>',
  43. r'<h4 class="headline">(.*?)</h4>'],
  44. webpage, 'title')
  45. description = self._html_search_meta(
  46. 'dcterms.abstract', webpage, 'description', default=None)
  47. if description is None:
  48. description = self._html_search_meta(
  49. 'description', webpage, 'meta description')
  50. # Thumbnail is sometimes not present.
  51. # It is in the mobile version, but that seems to use a different URL
  52. # structure altogether.
  53. thumbnail = self._og_search_thumbnail(webpage, default=None)
  54. media_streams = re.findall(r'''(?x)
  55. mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
  56. "([^"]+)"''', webpage)
  57. if media_streams:
  58. QUALITIES = qualities(['lo', 'hi', 'hq'])
  59. formats = []
  60. for furl in set(media_streams):
  61. if furl.endswith('.f4m'):
  62. fid = 'f4m'
  63. else:
  64. fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
  65. fid = fid_m.group(1) if fid_m else None
  66. formats.append({
  67. 'quality': QUALITIES(fid),
  68. 'format_id': fid,
  69. 'url': furl,
  70. })
  71. else: # request JSON file
  72. media_info = self._download_json(
  73. 'http://www.ardmediathek.de/play/media/%s' % video_id, video_id)
  74. # The second element of the _mediaArray contains the standard http urls
  75. streams = media_info['_mediaArray'][1]['_mediaStreamArray']
  76. if not streams:
  77. if '"fsk"' in webpage:
  78. raise ExtractorError('This video is only available after 20:00')
  79. formats = []
  80. for s in streams:
  81. if type(s['_stream']) == list:
  82. for index, url in enumerate(s['_stream'][::-1]):
  83. quality = s['_quality'] + index
  84. formats.append({
  85. 'quality': quality,
  86. 'url': url,
  87. 'format_id': '%s-%s' % (determine_ext(url), quality)
  88. })
  89. continue
  90. format = {
  91. 'quality': s['_quality'],
  92. 'url': s['_stream'],
  93. }
  94. format['format_id'] = '%s-%s' % (
  95. determine_ext(format['url']), format['quality'])
  96. formats.append(format)
  97. self._sort_formats(formats)
  98. return {
  99. 'id': video_id,
  100. 'title': title,
  101. 'description': description,
  102. 'formats': formats,
  103. 'thumbnail': thumbnail,
  104. }