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.

89 lines
3.2 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'<meta name="dcterms.title" content="(.*?)"/>',
  34. r'<h4 class="headline">(.*?)</h4>'],
  35. webpage, 'title')
  36. description = self._html_search_meta(
  37. 'dcterms.abstract', webpage, 'description')
  38. thumbnail = self._og_search_thumbnail(webpage)
  39. media_info = self._download_json(
  40. 'http://www.ardmediathek.de/play/media/%s' % video_id, video_id)
  41. # The second element of the _mediaArray contains the standard http urls
  42. streams = media_info['_mediaArray'][1]['_mediaStreamArray']
  43. if not streams:
  44. if '"fsk"' in webpage:
  45. raise ExtractorError('This video is only available after 20:00')
  46. formats = []
  47. for s in streams:
  48. if type(s['_stream']) == list:
  49. for index, url in enumerate(s['_stream'][::-1]):
  50. quality = s['_quality'] + index
  51. formats.append({
  52. 'quality': quality,
  53. 'url': url,
  54. 'format_id': '%s-%s' % (determine_ext(url), quality)
  55. })
  56. continue
  57. format = {
  58. 'quality': s['_quality'],
  59. 'url': s['_stream'],
  60. }
  61. format['format_id'] = '%s-%s' % (
  62. determine_ext(format['url']), format['quality'])
  63. formats.append(format)
  64. self._sort_formats(formats)
  65. return {
  66. 'id': video_id,
  67. 'title': title,
  68. 'description': description,
  69. 'formats': formats,
  70. 'thumbnail': thumbnail,
  71. }