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.

85 lines
3.1 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. )
  9. class ARDIE(InfoExtractor):
  10. _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[^/\?]+)(?:\?.*)?'
  11. _TEST = {
  12. 'url': 'http://www.ardmediathek.de/das-erste/guenther-jauch/edward-snowden-im-interview-held-oder-verraeter?documentId=19288786',
  13. 'file': '19288786.mp4',
  14. 'md5': '515bf47ce209fb3f5a61b7aad364634c',
  15. 'info_dict': {
  16. 'title': 'Edward Snowden im Interview - Held oder Verräter?',
  17. 'description': 'Edward Snowden hat alles aufs Spiel gesetzt, um die weltweite \xdcberwachung durch die Geheimdienste zu enttarnen. Nun stellt sich der ehemalige NSA-Mitarbeiter erstmals weltweit in einem TV-Interview den Fragen eines NDR-Journalisten. Die Sendung vom Sonntagabend.',
  18. 'thumbnail': 'http://www.ardmediathek.de/ard/servlet/contentblob/19/28/87/90/19288790/bild/2250037',
  19. },
  20. 'skip': 'Blocked outside of Germany',
  21. }
  22. def _real_extract(self, url):
  23. # determine video id from url
  24. m = re.match(self._VALID_URL, url)
  25. numid = re.search(r'documentId=([0-9]+)', url)
  26. if numid:
  27. video_id = numid.group(1)
  28. else:
  29. video_id = m.group('video_id')
  30. webpage = self._download_webpage(url, video_id)
  31. title = self._html_search_regex(
  32. [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
  33. r'<h4 class="headline">(.*?)</h4>'],
  34. webpage, 'title')
  35. description = self._html_search_meta(
  36. 'dcterms.abstract', webpage, 'description')
  37. thumbnail = self._og_search_thumbnail(webpage)
  38. streams = [
  39. mo.groupdict()
  40. for mo in re.finditer(
  41. r'mediaCollection\.addMediaStream\((?P<media_type>\d+), (?P<quality>\d+), "(?P<rtmp_url>[^"]*)", "(?P<video_url>[^"]*)", "[^"]*"\)', webpage)]
  42. if not streams:
  43. if '"fsk"' in webpage:
  44. raise ExtractorError('This video is only available after 20:00')
  45. formats = []
  46. for s in streams:
  47. format = {
  48. 'quality': int(s['quality']),
  49. }
  50. if s.get('rtmp_url'):
  51. format['protocol'] = 'rtmp'
  52. format['url'] = s['rtmp_url']
  53. format['playpath'] = s['video_url']
  54. else:
  55. format['url'] = s['video_url']
  56. quality_name = self._search_regex(
  57. r'[,.]([a-zA-Z0-9_-]+),?\.mp4', format['url'],
  58. 'quality name', default='NA')
  59. format['format_id'] = '%s-%s-%s-%s' % (
  60. determine_ext(format['url']), quality_name, s['media_type'],
  61. s['quality'])
  62. formats.append(format)
  63. self._sort_formats(formats)
  64. return {
  65. 'id': video_id,
  66. 'title': title,
  67. 'description': description,
  68. 'formats': formats,
  69. 'thumbnail': thumbnail,
  70. }