mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-11-04 08:35:12 +00:00 
			
		
		
		
	@@ -1,14 +1,19 @@
 | 
				
			|||||||
import json
 | 
					import json
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from ..utils import int_or_none, unified_timestamp, unescapeHTML
 | 
					from ..utils import (
 | 
				
			||||||
 | 
					    int_or_none,
 | 
				
			||||||
 | 
					    traverse_obj,
 | 
				
			||||||
 | 
					    try_call,
 | 
				
			||||||
 | 
					    unescapeHTML,
 | 
				
			||||||
 | 
					    unified_timestamp,
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
from .common import InfoExtractor
 | 
					from .common import InfoExtractor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class HRFernsehenIE(InfoExtractor):
 | 
					class HRFernsehenIE(InfoExtractor):
 | 
				
			||||||
    IE_NAME = 'hrfernsehen'
 | 
					    IE_NAME = 'hrfernsehen'
 | 
				
			||||||
    _VALID_URL = r'^https?://www\.(?:hr-fernsehen|hessenschau)\.de/.*,video-(?P<id>[0-9]{6})\.html'
 | 
					    _VALID_URL = r'^https?://www\.(?:hr-fernsehen|hessenschau)\.de/.*,video-(?P<id>[0-9]{6})\.html'
 | 
				
			||||||
 | 
					 | 
				
			||||||
    _TESTS = [{
 | 
					    _TESTS = [{
 | 
				
			||||||
        'url': 'https://www.hessenschau.de/tv-sendung/hessenschau-vom-26082020,video-130546.html',
 | 
					        'url': 'https://www.hessenschau.de/tv-sendung/hessenschau-vom-26082020,video-130546.html',
 | 
				
			||||||
        'md5': '5c4e0ba94677c516a2f65a84110fc536',
 | 
					        'md5': '5c4e0ba94677c516a2f65a84110fc536',
 | 
				
			||||||
@@ -21,10 +26,11 @@ class HRFernsehenIE(InfoExtractor):
 | 
				
			|||||||
            'subtitles': {'de': [{
 | 
					            'subtitles': {'de': [{
 | 
				
			||||||
                'url': 'https://hr-a.akamaihd.net/video/as/hessenschau/2020_08/hrLogo_200826200407_L385592_512x288-25p-500kbit.vtt'
 | 
					                'url': 'https://hr-a.akamaihd.net/video/as/hessenschau/2020_08/hrLogo_200826200407_L385592_512x288-25p-500kbit.vtt'
 | 
				
			||||||
            }]},
 | 
					            }]},
 | 
				
			||||||
            'timestamp': 1598470200,
 | 
					            'timestamp': 1598400000,
 | 
				
			||||||
            'upload_date': '20200826',
 | 
					            'upload_date': '20200826',
 | 
				
			||||||
            'thumbnail': 'https://www.hessenschau.de/tv-sendung/hs_ganz-1554~_t-1598465545029_v-16to9__medium.jpg',
 | 
					            'thumbnail': 'https://www.hessenschau.de/tv-sendung/hs_ganz-1554~_t-1598465545029_v-16to9.jpg',
 | 
				
			||||||
            'title': 'hessenschau vom 26.08.2020'
 | 
					            'title': 'hessenschau vom 26.08.2020',
 | 
				
			||||||
 | 
					            'duration': 1654
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }, {
 | 
					    }, {
 | 
				
			||||||
        'url': 'https://www.hr-fernsehen.de/sendungen-a-z/mex/sendungen/fair-und-gut---was-hinter-aldis-eigenem-guetesiegel-steckt,video-130544.html',
 | 
					        'url': 'https://www.hr-fernsehen.de/sendungen-a-z/mex/sendungen/fair-und-gut---was-hinter-aldis-eigenem-guetesiegel-steckt,video-130544.html',
 | 
				
			||||||
@@ -33,25 +39,18 @@ class HRFernsehenIE(InfoExtractor):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    _GEO_COUNTRIES = ['DE']
 | 
					    _GEO_COUNTRIES = ['DE']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def extract_airdate(self, loader_data):
 | 
					 | 
				
			||||||
        airdate_str = loader_data.get('mediaMetadata', {}).get('agf', {}).get('airdate')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        if airdate_str is None:
 | 
					 | 
				
			||||||
            return None
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return unified_timestamp(airdate_str)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    def extract_formats(self, loader_data):
 | 
					    def extract_formats(self, loader_data):
 | 
				
			||||||
        stream_formats = []
 | 
					        stream_formats = []
 | 
				
			||||||
        for stream_obj in loader_data["videoResolutionLevels"]:
 | 
					        data = loader_data['mediaCollection']['streams'][0]['media']
 | 
				
			||||||
 | 
					        for inner in data[1:]:
 | 
				
			||||||
            stream_format = {
 | 
					            stream_format = {
 | 
				
			||||||
                'format_id': str(stream_obj['verticalResolution']) + "p",
 | 
					                'format_id': try_call(lambda: f'{inner["maxHResolutionPx"]}p'),
 | 
				
			||||||
                'height': stream_obj['verticalResolution'],
 | 
					                'height': inner.get('maxHResolutionPx'),
 | 
				
			||||||
                'url': stream_obj['url'],
 | 
					                'url': inner['url'],
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            quality_information = re.search(r'([0-9]{3,4})x([0-9]{3,4})-([0-9]{2})p-([0-9]{3,4})kbit',
 | 
					            quality_information = re.search(r'([0-9]{3,4})x([0-9]{3,4})-([0-9]{2})p-([0-9]{3,4})kbit',
 | 
				
			||||||
                                            stream_obj['url'])
 | 
					                                            inner['url'])
 | 
				
			||||||
            if quality_information:
 | 
					            if quality_information:
 | 
				
			||||||
                stream_format['width'] = int_or_none(quality_information.group(1))
 | 
					                stream_format['width'] = int_or_none(quality_information.group(1))
 | 
				
			||||||
                stream_format['height'] = int_or_none(quality_information.group(2))
 | 
					                stream_format['height'] = int_or_none(quality_information.group(2))
 | 
				
			||||||
@@ -72,22 +71,22 @@ class HRFernsehenIE(InfoExtractor):
 | 
				
			|||||||
        description = self._html_search_meta(
 | 
					        description = self._html_search_meta(
 | 
				
			||||||
            ['description'], webpage)
 | 
					            ['description'], webpage)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        loader_str = unescapeHTML(self._search_regex(r"data-new-hr-mediaplayer-loader='([^']*)'", webpage, "ardloader"))
 | 
					        loader_str = unescapeHTML(self._search_regex(r"data-(?:new-)?hr-mediaplayer-loader='([^']*)'", webpage, 'ardloader'))
 | 
				
			||||||
        loader_data = json.loads(loader_str)
 | 
					        loader_data = json.loads(loader_str)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        subtitle = traverse_obj(loader_data, ('mediaCollection', 'subTitles', 0, 'sources', 0, 'url'))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        info = {
 | 
					        info = {
 | 
				
			||||||
            'id': video_id,
 | 
					            'id': video_id,
 | 
				
			||||||
            'title': title,
 | 
					            'title': title,
 | 
				
			||||||
            'description': description,
 | 
					            'description': description,
 | 
				
			||||||
            'formats': self.extract_formats(loader_data),
 | 
					            'formats': self.extract_formats(loader_data),
 | 
				
			||||||
            'timestamp': self.extract_airdate(loader_data)
 | 
					            'subtitles': {'de': [{'url': subtitle}]},
 | 
				
			||||||
 | 
					            'timestamp': unified_timestamp(self._search_regex(
 | 
				
			||||||
 | 
					                r'<time\sdatetime="(\d{4}\W\d{1,2}\W\d{1,2})', webpage, 'datetime', fatal=False)),
 | 
				
			||||||
 | 
					            'duration': int_or_none(traverse_obj(
 | 
				
			||||||
 | 
					                loader_data, ('playerConfig', 'pluginData', 'trackingAti@all', 'richMedia', 'duration'))),
 | 
				
			||||||
 | 
					            'thumbnail': self._search_regex(r'thumbnailUrl\W*([^"]+)', webpage, 'thumbnail', default=None),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if "subtitle" in loader_data:
 | 
					 | 
				
			||||||
            info["subtitles"] = {"de": [{"url": loader_data["subtitle"]}]}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        thumbnails = list(set([t for t in loader_data.get("previewImageUrl", {}).values()]))
 | 
					 | 
				
			||||||
        if len(thumbnails) > 0:
 | 
					 | 
				
			||||||
            info["thumbnails"] = [{"url": t} for t in thumbnails]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return info
 | 
					        return info
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user