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.

130 lines
5.3 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. compat_urllib_parse_urlparse,
  10. compat_urllib_parse,
  11. )
  12. class ARDIE(InfoExtractor):
  13. _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
  14. _TESTS = [{
  15. 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
  16. 'file': '22429276.mp4',
  17. 'md5': '469751912f1de0816a9fc9df8336476c',
  18. 'info_dict': {
  19. 'title': 'Vertrauen ist gut, Spionieren ist besser - Geht so deutsch-amerikanische Freundschaft?',
  20. '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',
  21. },
  22. 'skip': 'Blocked outside of Germany',
  23. }, {
  24. 'url': 'http://www.ardmediathek.de/tv/Tatort/Das-Wunder-von-Wolbeck-Video-tgl-ab-20/Das-Erste/Video?documentId=22490580&bcastId=602916',
  25. 'info_dict': {
  26. 'id': '22490580',
  27. 'ext': 'mp4',
  28. 'title': 'Das Wunder von Wolbeck (Video tgl. ab 20 Uhr)',
  29. '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.',
  30. },
  31. 'skip': 'Blocked outside of Germany',
  32. }]
  33. def _real_extract(self, url):
  34. # determine video id from url
  35. m = re.match(self._VALID_URL, url)
  36. numid = re.search(r'documentId=([0-9]+)', url)
  37. if numid:
  38. video_id = numid.group(1)
  39. else:
  40. video_id = m.group('video_id')
  41. urlp = compat_urllib_parse_urlparse(url)
  42. url = urlp._replace(path=compat_urllib_parse.quote(urlp.path.encode('utf-8'))).geturl()
  43. webpage = self._download_webpage(url, video_id)
  44. if '>Der gewünschte Beitrag ist nicht mehr verfügbar.<' in webpage:
  45. raise ExtractorError('Video %s is no longer available' % video_id, expected=True)
  46. title = self._html_search_regex(
  47. [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
  48. r'<meta name="dcterms.title" content="(.*?)"/>',
  49. r'<h4 class="headline">(.*?)</h4>'],
  50. webpage, 'title')
  51. description = self._html_search_meta(
  52. 'dcterms.abstract', webpage, 'description', default=None)
  53. if description is None:
  54. description = self._html_search_meta(
  55. 'description', webpage, 'meta description')
  56. # Thumbnail is sometimes not present.
  57. # It is in the mobile version, but that seems to use a different URL
  58. # structure altogether.
  59. thumbnail = self._og_search_thumbnail(webpage, default=None)
  60. media_streams = re.findall(r'''(?x)
  61. mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
  62. "([^"]+)"''', webpage)
  63. if media_streams:
  64. QUALITIES = qualities(['lo', 'hi', 'hq'])
  65. formats = []
  66. for furl in set(media_streams):
  67. if furl.endswith('.f4m'):
  68. fid = 'f4m'
  69. else:
  70. fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
  71. fid = fid_m.group(1) if fid_m else None
  72. formats.append({
  73. 'quality': QUALITIES(fid),
  74. 'format_id': fid,
  75. 'url': furl,
  76. })
  77. else: # request JSON file
  78. media_info = self._download_json(
  79. 'http://www.ardmediathek.de/play/media/%s' % video_id, video_id)
  80. # The second element of the _mediaArray contains the standard http urls
  81. streams = media_info['_mediaArray'][1]['_mediaStreamArray']
  82. if not streams:
  83. if '"fsk"' in webpage:
  84. raise ExtractorError('This video is only available after 20:00')
  85. formats = []
  86. for s in streams:
  87. if type(s['_stream']) == list:
  88. for index, url in enumerate(s['_stream'][::-1]):
  89. quality = s['_quality'] + index
  90. formats.append({
  91. 'quality': quality,
  92. 'url': url,
  93. 'format_id': '%s-%s' % (determine_ext(url), quality)
  94. })
  95. continue
  96. format = {
  97. 'quality': s['_quality'],
  98. 'url': s['_stream'],
  99. }
  100. format['format_id'] = '%s-%s' % (
  101. determine_ext(format['url']), format['quality'])
  102. formats.append(format)
  103. self._sort_formats(formats)
  104. return {
  105. 'id': video_id,
  106. 'title': title,
  107. 'description': description,
  108. 'formats': formats,
  109. 'thumbnail': thumbnail,
  110. }