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.

83 lines
3.0 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>', webpage, 'title')
  33. description = self._html_search_meta(
  34. 'dcterms.abstract', webpage, 'description')
  35. thumbnail = self._og_search_thumbnail(webpage)
  36. streams = [
  37. mo.groupdict()
  38. for mo in re.finditer(
  39. r'mediaCollection\.addMediaStream\((?P<media_type>\d+), (?P<quality>\d+), "(?P<rtmp_url>[^"]*)", "(?P<video_url>[^"]*)", "[^"]*"\)', webpage)]
  40. if not streams:
  41. if '"fsk"' in webpage:
  42. raise ExtractorError('This video is only available after 20:00')
  43. formats = []
  44. for s in streams:
  45. format = {
  46. 'quality': int(s['quality']),
  47. }
  48. if s.get('rtmp_url'):
  49. format['protocol'] = 'rtmp'
  50. format['url'] = s['rtmp_url']
  51. format['playpath'] = s['video_url']
  52. else:
  53. format['url'] = s['video_url']
  54. quality_name = self._search_regex(
  55. r'[,.]([a-zA-Z0-9_-]+),?\.mp4', format['url'],
  56. 'quality name', default='NA')
  57. format['format_id'] = '%s-%s-%s-%s' % (
  58. determine_ext(format['url']), quality_name, s['media_type'],
  59. s['quality'])
  60. formats.append(format)
  61. self._sort_formats(formats)
  62. return {
  63. 'id': video_id,
  64. 'title': title,
  65. 'description': description,
  66. 'formats': formats,
  67. 'thumbnail': thumbnail,
  68. }