logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

ntvde.py (3195B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urlparse
  6. from ..utils import (
  7. int_or_none,
  8. js_to_json,
  9. parse_duration,
  10. )
  11. class NTVDeIE(InfoExtractor):
  12. IE_NAME = 'n-tv.de'
  13. _VALID_URL = r'https?://(?:www\.)?n-tv\.de/mediathek/videos/[^/?#]+/[^/?#]+-article(?P<id>.+)\.html'
  14. _TESTS = [{
  15. 'url': 'http://www.n-tv.de/mediathek/videos/panorama/Schnee-und-Glaette-fuehren-zu-zahlreichen-Unfaellen-und-Staus-article14438086.html',
  16. 'md5': '6ef2514d4b1e8e03ca24b49e2f167153',
  17. 'info_dict': {
  18. 'id': '14438086',
  19. 'ext': 'mp4',
  20. 'thumbnail': r're:^https?://.*\.jpg$',
  21. 'title': 'Schnee und Glätte führen zu zahlreichen Unfällen und Staus',
  22. 'alt_title': 'Winterchaos auf deutschen Straßen',
  23. 'description': 'Schnee und Glätte sorgen deutschlandweit für einen chaotischen Start in die Woche: Auf den Straßen kommt es zu kilometerlangen Staus und Dutzenden Glätteunfällen. In Düsseldorf und München wirbelt der Schnee zudem den Flugplan durcheinander. Dutzende Flüge landen zu spät, einige fallen ganz aus.',
  24. 'duration': 4020,
  25. 'timestamp': 1422892797,
  26. 'upload_date': '20150202',
  27. },
  28. }]
  29. def _real_extract(self, url):
  30. video_id = self._match_id(url)
  31. webpage = self._download_webpage(url, video_id)
  32. info = self._parse_json(self._search_regex(
  33. r'(?s)ntv\.pageInfo\.article\s*=\s*(\{.*?\});', webpage, 'info'),
  34. video_id, transform_source=js_to_json)
  35. timestamp = int_or_none(info.get('publishedDateAsUnixTimeStamp'))
  36. vdata = self._parse_json(self._search_regex(
  37. r'(?s)\$\(\s*"\#player"\s*\)\s*\.data\(\s*"player",\s*(\{.*?\})\);',
  38. webpage, 'player data'), video_id,
  39. transform_source=lambda s: js_to_json(re.sub(r'advertising:\s*{[^}]+},', '', s)))
  40. duration = parse_duration(vdata.get('duration'))
  41. formats = []
  42. if vdata.get('video'):
  43. formats.append({
  44. 'format_id': 'flash',
  45. 'url': 'rtmp://fms.n-tv.de/%s' % vdata['video'],
  46. })
  47. if vdata.get('videoMp4'):
  48. formats.append({
  49. 'format_id': 'mobile',
  50. 'url': compat_urlparse.urljoin('http://video.n-tv.de', vdata['videoMp4']),
  51. 'tbr': 400, # estimation
  52. })
  53. if vdata.get('videoM3u8'):
  54. m3u8_url = compat_urlparse.urljoin('http://video.n-tv.de', vdata['videoM3u8'])
  55. formats.extend(self._extract_m3u8_formats(
  56. m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native',
  57. preference=0, m3u8_id='hls', fatal=False))
  58. self._sort_formats(formats)
  59. return {
  60. 'id': video_id,
  61. 'title': info['headline'],
  62. 'description': info.get('intro'),
  63. 'alt_title': info.get('kicker'),
  64. 'timestamp': timestamp,
  65. 'thumbnail': vdata.get('html5VideoPoster'),
  66. 'duration': duration,
  67. 'formats': formats,
  68. }