2022-01-10 22:36:05 +01:00
|
|
|
from .common import InfoExtractor
|
2024-07-14 05:42:17 +02:00
|
|
|
from ..networking.exceptions import HTTPError
|
2022-01-10 22:36:05 +01:00
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
2024-07-14 05:42:17 +02:00
|
|
|
parse_codecs,
|
2022-01-10 22:36:05 +01:00
|
|
|
try_get,
|
2024-06-30 22:48:54 +02:00
|
|
|
url_or_none,
|
2022-01-10 22:36:05 +01:00
|
|
|
urlencode_postdata,
|
|
|
|
)
|
2024-06-30 22:48:54 +02:00
|
|
|
from ..utils.traversal import traverse_obj
|
2022-01-10 22:36:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
class DigitalConcertHallIE(InfoExtractor):
|
|
|
|
IE_DESC = 'DigitalConcertHall extractor'
|
2024-06-30 22:48:54 +02:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?digitalconcerthall\.com/(?P<language>[a-z]+)/(?P<type>film|concert|work)/(?P<id>[0-9]+)-?(?P<part>[0-9]+)?'
|
2022-01-10 22:36:05 +01:00
|
|
|
_OAUTH_URL = 'https://api.digitalconcerthall.com/v2/oauth2/token'
|
2024-07-14 05:42:17 +02:00
|
|
|
_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15'
|
2022-01-10 22:36:05 +01:00
|
|
|
_ACCESS_TOKEN = None
|
|
|
|
_NETRC_MACHINE = 'digitalconcerthall'
|
|
|
|
_TESTS = [{
|
|
|
|
'note': 'Playlist with only one video',
|
|
|
|
'url': 'https://www.digitalconcerthall.com/en/concert/53201',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '53201-1',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'composer': 'Kurt Weill',
|
|
|
|
'title': '[Magic Night]',
|
|
|
|
'thumbnail': r're:^https?://images.digitalconcerthall.com/cms/thumbnails.*\.jpg$',
|
|
|
|
'upload_date': '20210624',
|
|
|
|
'timestamp': 1624548600,
|
|
|
|
'duration': 2798,
|
2024-06-30 22:48:54 +02:00
|
|
|
'album_artists': ['Members of the Berliner Philharmoniker', 'Simon Rössler'],
|
|
|
|
'composers': ['Kurt Weill'],
|
2022-01-10 22:36:05 +01:00
|
|
|
},
|
|
|
|
'params': {'skip_download': 'm3u8'},
|
|
|
|
}, {
|
|
|
|
'note': 'Concert with several works and an interview',
|
|
|
|
'url': 'https://www.digitalconcerthall.com/en/concert/53785',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '53785',
|
2024-06-30 22:48:54 +02:00
|
|
|
'album_artists': ['Berliner Philharmoniker', 'Kirill Petrenko'],
|
2022-01-10 22:36:05 +01:00
|
|
|
'title': 'Kirill Petrenko conducts Mendelssohn and Shostakovich',
|
2024-06-30 22:48:54 +02:00
|
|
|
'thumbnail': r're:^https?://images.digitalconcerthall.com/cms/thumbnails.*\.jpg$',
|
2022-01-10 22:36:05 +01:00
|
|
|
},
|
|
|
|
'params': {'skip_download': 'm3u8'},
|
|
|
|
'playlist_count': 3,
|
2023-06-02 17:01:55 +02:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.digitalconcerthall.com/en/film/388',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '388',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'The Berliner Philharmoniker and Frank Peter Zimmermann',
|
|
|
|
'description': 'md5:cfe25a7044fa4be13743e5089b5b5eb2',
|
|
|
|
'thumbnail': r're:^https?://images.digitalconcerthall.com/cms/thumbnails.*\.jpg$',
|
|
|
|
'upload_date': '20220714',
|
|
|
|
'timestamp': 1657785600,
|
2024-06-30 22:48:54 +02:00
|
|
|
'album_artists': ['Frank Peter Zimmermann', 'Benedikt von Bernstorff', 'Jakob von Bernstorff'],
|
|
|
|
},
|
|
|
|
'params': {'skip_download': 'm3u8'},
|
|
|
|
}, {
|
|
|
|
'note': 'Concert with several works and an interview',
|
|
|
|
'url': 'https://www.digitalconcerthall.com/en/work/53785-1',
|
|
|
|
'info_dict': {
|
|
|
|
'id': '53785',
|
|
|
|
'album_artists': ['Berliner Philharmoniker', 'Kirill Petrenko'],
|
|
|
|
'title': 'Kirill Petrenko conducts Mendelssohn and Shostakovich',
|
|
|
|
'thumbnail': r're:^https?://images.digitalconcerthall.com/cms/thumbnails.*\.jpg$',
|
2023-06-02 17:01:55 +02:00
|
|
|
},
|
|
|
|
'params': {'skip_download': 'm3u8'},
|
2024-06-30 22:48:54 +02:00
|
|
|
'playlist_count': 1,
|
2022-01-10 22:36:05 +01:00
|
|
|
}]
|
|
|
|
|
2022-03-18 21:53:33 +01:00
|
|
|
def _perform_login(self, username, password):
|
2024-07-14 05:42:17 +02:00
|
|
|
login_token = self._download_json(
|
2022-01-10 22:36:05 +01:00
|
|
|
self._OAUTH_URL,
|
|
|
|
None, 'Obtaining token', errnote='Unable to obtain token', data=urlencode_postdata({
|
|
|
|
'affiliate': 'none',
|
|
|
|
'grant_type': 'device',
|
|
|
|
'device_vendor': 'unknown',
|
2024-07-14 05:42:17 +02:00
|
|
|
# device_model 'Safari' gets split streams of 4K/HEVC video and lossless/FLAC audio
|
|
|
|
'device_model': 'unknown' if self._configuration_arg('prefer_combined_hls') else 'Safari',
|
2022-01-10 22:36:05 +01:00
|
|
|
'app_id': 'dch.webapp',
|
2024-07-14 05:42:17 +02:00
|
|
|
'app_distributor': 'berlinphil',
|
|
|
|
'app_version': '1.84.0',
|
2022-01-10 22:36:05 +01:00
|
|
|
'client_secret': '2ySLN+2Fwb',
|
|
|
|
}), headers={
|
2024-07-14 05:42:17 +02:00
|
|
|
'Accept': 'application/json',
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
|
|
'User-Agent': self._USER_AGENT,
|
|
|
|
})['access_token']
|
2022-01-10 22:36:05 +01:00
|
|
|
try:
|
2024-07-14 05:42:17 +02:00
|
|
|
login_response = self._download_json(
|
2022-01-10 22:36:05 +01:00
|
|
|
self._OAUTH_URL,
|
|
|
|
None, note='Logging in', errnote='Unable to login', data=urlencode_postdata({
|
|
|
|
'grant_type': 'password',
|
|
|
|
'username': username,
|
|
|
|
'password': password,
|
|
|
|
}), headers={
|
2024-07-14 05:42:17 +02:00
|
|
|
'Accept': 'application/json',
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
2022-01-10 22:36:05 +01:00
|
|
|
'Referer': 'https://www.digitalconcerthall.com',
|
2024-07-14 05:42:17 +02:00
|
|
|
'Authorization': f'Bearer {login_token}',
|
|
|
|
'User-Agent': self._USER_AGENT,
|
2022-01-10 22:36:05 +01:00
|
|
|
})
|
2024-07-14 05:42:17 +02:00
|
|
|
except ExtractorError as error:
|
|
|
|
if isinstance(error.cause, HTTPError) and error.cause.status == 401:
|
|
|
|
raise ExtractorError('Invalid username or password', expected=True)
|
|
|
|
raise
|
|
|
|
self._ACCESS_TOKEN = login_response['access_token']
|
2022-01-10 22:36:05 +01:00
|
|
|
|
|
|
|
def _real_initialize(self):
|
2022-03-18 21:53:33 +01:00
|
|
|
if not self._ACCESS_TOKEN:
|
|
|
|
self.raise_login_required(method='password')
|
2022-01-10 22:36:05 +01:00
|
|
|
|
2023-06-02 17:01:55 +02:00
|
|
|
def _entries(self, items, language, type_, **kwargs):
|
2022-01-10 22:36:05 +01:00
|
|
|
for item in items:
|
|
|
|
video_id = item['id']
|
|
|
|
stream_info = self._download_json(
|
|
|
|
self._proto_relative_url(item['_links']['streams']['href']), video_id, headers={
|
|
|
|
'Accept': 'application/json',
|
|
|
|
'Authorization': f'Bearer {self._ACCESS_TOKEN}',
|
2024-06-12 01:09:58 +02:00
|
|
|
'Accept-Language': language,
|
2024-07-14 05:42:17 +02:00
|
|
|
'User-Agent': self._USER_AGENT,
|
2022-01-10 22:36:05 +01:00
|
|
|
})
|
|
|
|
|
2024-06-30 22:48:54 +02:00
|
|
|
formats = []
|
|
|
|
for m3u8_url in traverse_obj(stream_info, ('channel', ..., 'stream', ..., 'url', {url_or_none})):
|
2024-07-14 05:42:17 +02:00
|
|
|
formats.extend(self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
|
|
|
|
for fmt in formats:
|
|
|
|
if fmt.get('format_note') and fmt.get('vcodec') == 'none':
|
|
|
|
fmt.update(parse_codecs(fmt['format_note']))
|
2022-01-10 22:36:05 +01:00
|
|
|
|
|
|
|
yield {
|
|
|
|
'id': video_id,
|
|
|
|
'title': item.get('title'),
|
|
|
|
'composer': item.get('name_composer'),
|
|
|
|
'formats': formats,
|
|
|
|
'duration': item.get('duration_total'),
|
|
|
|
'timestamp': traverse_obj(item, ('date', 'published')),
|
|
|
|
'description': item.get('short_description') or stream_info.get('short_description'),
|
|
|
|
**kwargs,
|
|
|
|
'chapters': [{
|
|
|
|
'start_time': chapter.get('time'),
|
|
|
|
'end_time': try_get(chapter, lambda x: x['time'] + x['duration']),
|
|
|
|
'title': chapter.get('text'),
|
2023-06-02 17:01:55 +02:00
|
|
|
} for chapter in item['cuepoints']] if item.get('cuepoints') and type_ == 'concert' else None,
|
2022-01-10 22:36:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2024-06-30 22:48:54 +02:00
|
|
|
language, type_, video_id, part = self._match_valid_url(url).group('language', 'type', 'id', 'part')
|
2022-01-10 22:36:05 +01:00
|
|
|
if not language:
|
|
|
|
language = 'en'
|
|
|
|
|
2024-06-30 22:48:54 +02:00
|
|
|
api_type = 'concert' if type_ == 'work' else type_
|
2022-01-10 22:36:05 +01:00
|
|
|
vid_info = self._download_json(
|
2024-06-30 22:48:54 +02:00
|
|
|
f'https://api.digitalconcerthall.com/v2/{api_type}/{video_id}', video_id, headers={
|
2022-01-10 22:36:05 +01:00
|
|
|
'Accept': 'application/json',
|
2024-06-12 01:09:58 +02:00
|
|
|
'Accept-Language': language,
|
2024-07-14 05:42:17 +02:00
|
|
|
'User-Agent': self._USER_AGENT,
|
|
|
|
'Authorization': f'Bearer {self._ACCESS_TOKEN}',
|
2022-01-10 22:36:05 +01:00
|
|
|
})
|
2023-06-02 17:01:55 +02:00
|
|
|
videos = [vid_info] if type_ == 'film' else traverse_obj(vid_info, ('_embedded', ..., ...))
|
2022-01-10 22:36:05 +01:00
|
|
|
|
2024-06-30 22:48:54 +02:00
|
|
|
if type_ == 'work':
|
|
|
|
videos = [videos[int(part) - 1]]
|
|
|
|
|
2024-07-14 05:42:17 +02:00
|
|
|
album_artists = traverse_obj(vid_info, ('_links', 'artist', ..., 'name', {str}))
|
2024-06-30 22:48:54 +02:00
|
|
|
thumbnail = traverse_obj(vid_info, (
|
|
|
|
'image', ..., {self._proto_relative_url}, {url_or_none},
|
|
|
|
{lambda x: x.format(width=0, height=0)}, any)) # NB: 0x0 is the original size
|
|
|
|
|
2022-01-10 22:36:05 +01:00
|
|
|
return {
|
|
|
|
'_type': 'playlist',
|
|
|
|
'id': video_id,
|
|
|
|
'title': vid_info.get('title'),
|
2024-06-30 22:48:54 +02:00
|
|
|
'entries': self._entries(
|
|
|
|
videos, language, type_, thumbnail=thumbnail, album_artists=album_artists),
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
'album_artists': album_artists,
|
2022-01-10 22:36:05 +01:00
|
|
|
}
|