1
0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-12-23 00:16:48 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Bart Broere
e50adf24c9
Merge 6de650f51f into c5098961b0 2024-09-21 22:14:55 +02:00

View File

@ -5,7 +5,7 @@ import json
import re
from .common import InfoExtractor
from ..utils import ExtractorError, int_or_none, join_nonempty, merge_dicts, traverse_obj, url_or_none, T
from ..utils import ExtractorError, join_nonempty, traverse_obj
class NPOIE(InfoExtractor):
@ -17,23 +17,23 @@ class NPOIE(InfoExtractor):
'url': 'https://npo.nl/start/serie/zembla/seizoen-2015/wie-is-de-mol-2/',
'md5': 'f9ce9c43cc8bc3b8138df1562b99c379',
'info_dict': {
'title': 'Wie is de mol? (2)',
'thumbnail': 'https://assets-start.npo.nl/resources/2023/07/01/e723c3cf-3e42-418a-9ba5-f6dbb64b516a.jpg',
'description': 'Wie is de mol? (2)',
'duration': 2439,
'ext': 'm4v',
'id': 'wie-is-de-mol-2',
'description': 'wie-is-de-mol-2',
'ext': 'mp4',
'thumbnail': 'https://assets-start.npo.nl/resources/2023/07/01/e723c3cf-3e42-418a-9ba5-f6dbb64b516a.jpg',
'title': 'Wie is de mol? (2)'
}
}, {
'url': 'https://npo.nl/start/serie/vpro-tegenlicht/seizoen-11/zwart-geld-de-toekomst-komt-uit-afrika',
'md5': 'c84d054219c4888ed53b4ee3d01b2d93',
'info_dict': {
'title': 'Zwart geld: de toekomst komt uit Afrika',
'thumbnail': 'https://assets-start.npo.nl/resources/2023/06/30/d9879593-1944-4249-990c-1561dac14d8e.jpg',
'duration': 3000,
'id': 'zwart-geld-de-toekomst-komt-uit-afrika',
'description': 'zwart-geld-de-toekomst-komt-uit-afrika',
'title': 'Zwart geld: de toekomst komt uit Afrika',
'ext': 'mp4',
'description': 'Zwart geld: de toekomst komt uit Afrika',
'thumbnail': 'https://assets-start.npo.nl/resources/2023/06/30/d9879593-1944-4249-990c-1561dac14d8e.jpg',
'duration': 3000
},
}]
@ -50,22 +50,30 @@ class NPOIE(InfoExtractor):
program_metadata = self._download_json('https://npo.nl/start/api/domain/program-detail',
slug, query={'slug': slug})
product_id = traverse_obj(program_metadata, 'productId')
product_id = program_metadata.get('productId')
images = program_metadata.get('images')
thumbnail = None
for image in images:
thumbnail = image.get('url')
break
title = program_metadata.get('title')
descriptions = program_metadata.get('description', {})
description = descriptions.get('long') or descriptions.get('short') or descriptions.get('brief')
duration = program_metadata.get('durationInSeconds')
if not product_id:
raise ExtractorError('No productId found for slug: %s' % (slug,))
raise ExtractorError('No productId found for slug: %s' % slug)
formats = self._extract_formats_by_product_id(product_id, slug, url)
self._sort_formats(formats)
return merge_dicts(traverse_obj(program_metadata, {
'title': 'title',
'description': (('description', ('long', 'short', 'brief')), 'title'),
'thumbnail': ('images', Ellipsis, 'url', T(url_or_none)),
'duration': ('durationInSeconds', T(int_or_none)),
}, get_all=False), {
return {
'id': slug,
'formats': formats,
'title': slug,
'description': slug,
})
'title': title or slug,
'description': description or title or slug,
'thumbnail': thumbnail,
'duration': duration,
}
def _extract_formats_by_product_id(self, product_id, slug, url=None):
token = self._get_token(product_id)
@ -110,70 +118,6 @@ class BNNVaraIE(NPOIE):
def _real_extract(self, url):
url = url.rstrip('/')
video_id = url.split('/')[-1]
graphql_query = """query getMedia($id: ID!, $mediaUrl: String, $hasAdConsent: Boolean!, $atInternetId: Int) {
player(
id: $id
mediaUrl: $mediaUrl
hasAdConsent: $hasAdConsent
atInternetId: $atInternetId
) {
... on PlayerSucces {
brand {
name
slug
broadcastsEnabled
__typename
}
title
programTitle
pomsProductId
broadcasters {
name
__typename
}
duration
classifications {
title
imageUrl
type
__typename
}
image {
title
url
__typename
}
cta {
title
url
__typename
}
genres {
name
__typename
}
subtitles {
url
language
__typename
}
sources {
name
url
ratio
__typename
}
type
token
__typename
}
... on PlayerError {
error
__typename
}
__typename
}
}"""
media = self._download_json('https://api.bnnvara.nl/bff/graphql',
video_id,
@ -185,15 +129,14 @@ class BNNVaraIE(NPOIE):
'hasAdConsent': False,
'atInternetId': 70
},
'query': graphql_query
'query': 'query getMedia($id: ID!, $mediaUrl: String, $hasAdConsent: Boolean!, $atInternetId: Int) {\n player(\n id: $id\n mediaUrl: $mediaUrl\n hasAdConsent: $hasAdConsent\n atInternetId: $atInternetId\n ) {\n ... on PlayerSucces {\n brand {\n name\n slug\n broadcastsEnabled\n __typename\n }\n title\n programTitle\n pomsProductId\n broadcasters {\n name\n __typename\n }\n duration\n classifications {\n title\n imageUrl\n type\n __typename\n }\n image {\n title\n url\n __typename\n }\n cta {\n title\n url\n __typename\n }\n genres {\n name\n __typename\n }\n subtitles {\n url\n language\n __typename\n }\n sources {\n name\n url\n ratio\n __typename\n }\n type\n token\n __typename\n }\n ... on PlayerError {\n error\n __typename\n }\n __typename\n }\n}'
}).encode('utf8'),
headers={
'Content-Type': 'application/json',
})
product_id = media.get('data', {}).get('player', {}).get('pomsProductId')
product_id = traverse_obj(media, ('data', 'player', 'pomsProductId'))
formats = self._extract_formats_by_product_id(product_id, video_id) if product_id else []
self._sort_formats(formats)
formats = self._extract_formats_by_product_id(product_id, video_id)
return {
'id': product_id,
@ -211,9 +154,7 @@ class ONIE(NPOIE):
'url': 'https://ongehoordnederland.tv/2024/03/01/korte-clips/heeft-preppen-zin-betwijfel-dat-je-daar-echt-iets-aan-zult-hebben-bij-oorlog-lydia-daniel/',
'md5': 'a85ebd50fa86fe5cbce654655f7dbb12',
'info_dict': {
'id': 'heeft-preppen-zin-betwijfel-dat-je-daar-echt-iets-aan-zult-hebben-bij-oorlog-lydia-daniel',
'title': 'heeft-preppen-zin-betwijfel-dat-je-daar-echt-iets-aan-zult-hebben-bij-oorlog-lydia-daniel',
'ext': 'mp4',
}
}]
@ -225,7 +166,9 @@ class ONIE(NPOIE):
for result in results:
formats.extend(self._extract_formats_by_product_id(result, video_id))
self._sort_formats(formats)
if not formats:
raise ExtractorError('Could not find a POMS product id in the provided URL, '
'perhaps because all stream URLs are DRM protected.')
return {
'id': video_id,
@ -245,7 +188,6 @@ class ZAPPIE(NPOIE):
'info_dict': {
'id': 'POMS_AT_811523',
'title': 'POMS_AT_811523',
'ext': 'mp4',
},
}]
@ -271,23 +213,21 @@ class SchoolTVIE(NPOIE):
'md5': 'e9ef151c4886994e2bea23593348cb14',
'info_dict': {
'id': 'zapp-music-challenge-2015-zapp-music-challenge-2015',
'title': 'Zapp Music Challenge 2015-Alain Clark & Yaell',
'description': "Een nummer schrijven met de super bekende soulzanger en producer Alain Clark? Dat is de uitdaging voor de dertienjarige Yaell uit Delft. En als het dan echt goed is, mag hij het ook nog eens live gaan spelen op de speelplaats bij Giel Beelen! Muziek is heel erg belangrijk in het leven van Yaell. 'Als er geen muziek zou zijn, dan zou ik heel veel niet kunnen.' Hij is dan ook altijd aan het schrijven, vaak over zijn eigen leven. Maar soms is het best lastig om die teksten te verzinnen. Vindt hij de inspiratie om een hit te maken met Alain?",
'ext': 'mp4',
'title': 'Zapp Music Challenge 2015 - Alain Clark & Yaell',
'description': "Een nummer schrijven met de super bekende soulzanger en producer Alain Clark? Dat is de uitdaging voor de dertienjarige Yaell uit Delft. En als het dan echt goed is, mag hij het ook nog eens live gaan spelen op de speelplaats bij Giel Beelen! Muziek is heel erg belangrijk in het leven van Yaell. 'Als er geen muziek zou zijn, dan zou ik heel veel niet kunnen.' Hij is dan ook altijd aan het schrijven, vaak over zijn eigen leven. Maar soms is het best lastig om die teksten te verzinnen. Vindt hij de inspiratie om een hit te maken met Alain?"
},
}]
def _real_extract(self, url):
video_id = url.rstrip('/').split('/')[-1]
build_id = self._search_nextjs_data(
self._download_webpage(url, video_id),
video_id,
)['buildId']
# TODO Find out how we could obtain this automatically
# Otherwise this extractor might break each time SchoolTV deploys a new release
build_id = 'b7eHUzAVO7wHXCopYxQhV'
metadata_url = 'https://schooltv.nl/_next/data/' \
+ build_id \
+ '/video-item/' \
+ '/item/' \
+ video_id + '.json'
metadata = self._download_json(metadata_url,
@ -295,7 +235,9 @@ class SchoolTVIE(NPOIE):
formats = self._extract_formats_by_product_id(metadata.get('poms_mid'), video_id)
self._sort_formats(formats)
if not formats:
raise ExtractorError('Could not find a POMS product id in the provided URL, '
'perhaps because all stream URLs are DRM protected.')
return {
'id': video_id,
@ -316,7 +258,9 @@ class NTRSubsiteIE(NPOIE):
formats.extend(self._extract_formats_by_product_id(result, video_id))
break
self._sort_formats(formats)
if not formats:
raise ExtractorError('Could not find a POMS product id in the provided URL, '
'perhaps because all stream URLs are DRM protected.')
return {
'id': video_id,
@ -335,7 +279,6 @@ class HetKlokhuisIE(NTRSubsiteIE):
'info_dict': {
'id': 'aliens',
'title': 'aliens',
'ext': 'mp4',
},
}]
@ -350,7 +293,7 @@ class VPROIE(NPOIE):
'info_dict': {
'id': 'offline-als-luxe.html',
'title': 'offline-als-luxe.html',
'ext': 'mp4',
'ext': 'm4v',
},
}]
@ -361,9 +304,11 @@ class VPROIE(NPOIE):
formats = []
for result in results:
formats.extend(self._extract_formats_by_product_id(result, video_id))
break
break # TODO find a better solution, VPRO pages can have multiple videos embedded
self._sort_formats(formats)
if not formats:
raise ExtractorError('Could not find a POMS product id in the provided URL, '
'perhaps because all stream URLs are DRM protected.')
return {
'id': video_id,
@ -382,6 +327,5 @@ class AndereTijdenIE(NTRSubsiteIE):
'info_dict': {
'id': 'Duitse-soldaten-over-de-Slag-bij-Arnhem',
'title': 'Duitse-soldaten-over-de-Slag-bij-Arnhem',
'ext': 'mp4',
},
}]