logo

youtube-dl

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

hrfernsehen.py (3877B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. import re
  5. from ..utils import (
  6. int_or_none,
  7. unified_timestamp,
  8. unescapeHTML
  9. )
  10. from .common import InfoExtractor
  11. class HRFernsehenIE(InfoExtractor):
  12. IE_NAME = 'hrfernsehen'
  13. _VALID_URL = r'^https?://www\.(?:hr-fernsehen|hessenschau)\.de/.*,video-(?P<id>[0-9]{6})\.html'
  14. _TESTS = [{
  15. 'url': 'https://www.hessenschau.de/tv-sendung/hessenschau-vom-26082020,video-130546.html',
  16. 'md5': '5c4e0ba94677c516a2f65a84110fc536',
  17. 'info_dict': {
  18. 'id': '130546',
  19. 'ext': 'mp4',
  20. 'description': 'Sturmtief Kirsten fegt über Hessen / Die Corona-Pandemie – eine Chronologie / '
  21. 'Sterbehilfe: Die Lage in Hessen / Miss Hessen leitet zwei eigene Unternehmen / '
  22. 'Pop-Up Museum zeigt Schwarze Unterhaltung und Black Music',
  23. 'subtitles': {'de': [{
  24. 'url': 'https://hr-a.akamaihd.net/video/as/hessenschau/2020_08/hrLogo_200826200407_L385592_512x288-25p-500kbit.vtt'
  25. }]},
  26. 'timestamp': 1598470200,
  27. 'upload_date': '20200826',
  28. 'thumbnail': 'https://www.hessenschau.de/tv-sendung/hs_ganz-1554~_t-1598465545029_v-16to9__medium.jpg',
  29. 'title': 'hessenschau vom 26.08.2020'
  30. }
  31. }, {
  32. 'url': 'https://www.hr-fernsehen.de/sendungen-a-z/mex/sendungen/fair-und-gut---was-hinter-aldis-eigenem-guetesiegel-steckt,video-130544.html',
  33. 'only_matching': True
  34. }]
  35. _GEO_COUNTRIES = ['DE']
  36. def extract_airdate(self, loader_data):
  37. airdate_str = loader_data.get('mediaMetadata', {}).get('agf', {}).get('airdate')
  38. if airdate_str is None:
  39. return None
  40. return unified_timestamp(airdate_str)
  41. def extract_formats(self, loader_data):
  42. stream_formats = []
  43. for stream_obj in loader_data["videoResolutionLevels"]:
  44. stream_format = {
  45. 'format_id': str(stream_obj['verticalResolution']) + "p",
  46. 'height': stream_obj['verticalResolution'],
  47. 'url': stream_obj['url'],
  48. }
  49. quality_information = re.search(r'([0-9]{3,4})x([0-9]{3,4})-([0-9]{2})p-([0-9]{3,4})kbit',
  50. stream_obj['url'])
  51. if quality_information:
  52. stream_format['width'] = int_or_none(quality_information.group(1))
  53. stream_format['height'] = int_or_none(quality_information.group(2))
  54. stream_format['fps'] = int_or_none(quality_information.group(3))
  55. stream_format['tbr'] = int_or_none(quality_information.group(4))
  56. stream_formats.append(stream_format)
  57. self._sort_formats(stream_formats)
  58. return stream_formats
  59. def _real_extract(self, url):
  60. video_id = self._match_id(url)
  61. webpage = self._download_webpage(url, video_id)
  62. title = self._html_search_meta(
  63. ['og:title', 'twitter:title', 'name'], webpage)
  64. description = self._html_search_meta(
  65. ['description'], webpage)
  66. loader_str = unescapeHTML(self._search_regex(r"data-new-hr-mediaplayer-loader='([^']*)'", webpage, "ardloader"))
  67. loader_data = json.loads(loader_str)
  68. info = {
  69. 'id': video_id,
  70. 'title': title,
  71. 'description': description,
  72. 'formats': self.extract_formats(loader_data),
  73. 'timestamp': self.extract_airdate(loader_data)
  74. }
  75. if "subtitle" in loader_data:
  76. info["subtitles"] = {"de": [{"url": loader_data["subtitle"]}]}
  77. thumbnails = list(set([t for t in loader_data.get("previewImageUrl", {}).values()]))
  78. if len(thumbnails) > 0:
  79. info["thumbnails"] = [{"url": t} for t in thumbnails]
  80. return info