]>
Commit | Line | Data |
---|---|---|
8bcd4048 | 1 | from .common import InfoExtractor |
2 | ||
3 | from ..utils import ( | |
4 | ExtractorError, | |
5 | parse_resolution, | |
6 | traverse_obj, | |
7 | try_get, | |
8 | urlencode_postdata, | |
9 | ) | |
10 | ||
11 | ||
12 | class DigitalConcertHallIE(InfoExtractor): | |
13 | IE_DESC = 'DigitalConcertHall extractor' | |
55ed4ff7 | 14 | _VALID_URL = r'https?://(?:www\.)?digitalconcerthall\.com/(?P<language>[a-z]+)/(?P<type>film|concert)/(?P<id>[0-9]+)' |
8bcd4048 | 15 | _OAUTH_URL = 'https://api.digitalconcerthall.com/v2/oauth2/token' |
16 | _ACCESS_TOKEN = None | |
17 | _NETRC_MACHINE = 'digitalconcerthall' | |
18 | _TESTS = [{ | |
19 | 'note': 'Playlist with only one video', | |
20 | 'url': 'https://www.digitalconcerthall.com/en/concert/53201', | |
21 | 'info_dict': { | |
22 | 'id': '53201-1', | |
23 | 'ext': 'mp4', | |
24 | 'composer': 'Kurt Weill', | |
25 | 'title': '[Magic Night]', | |
26 | 'thumbnail': r're:^https?://images.digitalconcerthall.com/cms/thumbnails.*\.jpg$', | |
27 | 'upload_date': '20210624', | |
28 | 'timestamp': 1624548600, | |
29 | 'duration': 2798, | |
30 | 'album_artist': 'Members of the Berliner Philharmoniker / Simon Rössler', | |
31 | }, | |
32 | 'params': {'skip_download': 'm3u8'}, | |
33 | }, { | |
34 | 'note': 'Concert with several works and an interview', | |
35 | 'url': 'https://www.digitalconcerthall.com/en/concert/53785', | |
36 | 'info_dict': { | |
37 | 'id': '53785', | |
38 | 'album_artist': 'Berliner Philharmoniker / Kirill Petrenko', | |
39 | 'title': 'Kirill Petrenko conducts Mendelssohn and Shostakovich', | |
40 | }, | |
41 | 'params': {'skip_download': 'm3u8'}, | |
42 | 'playlist_count': 3, | |
55ed4ff7 MAM |
43 | }, { |
44 | 'url': 'https://www.digitalconcerthall.com/en/film/388', | |
45 | 'info_dict': { | |
46 | 'id': '388', | |
47 | 'ext': 'mp4', | |
48 | 'title': 'The Berliner Philharmoniker and Frank Peter Zimmermann', | |
49 | 'description': 'md5:cfe25a7044fa4be13743e5089b5b5eb2', | |
50 | 'thumbnail': r're:^https?://images.digitalconcerthall.com/cms/thumbnails.*\.jpg$', | |
51 | 'upload_date': '20220714', | |
52 | 'timestamp': 1657785600, | |
53 | 'album_artist': 'Frank Peter Zimmermann / Benedikt von Bernstorff / Jakob von Bernstorff', | |
54 | }, | |
55 | 'params': {'skip_download': 'm3u8'}, | |
8bcd4048 | 56 | }] |
57 | ||
52efa4b3 | 58 | def _perform_login(self, username, password): |
8bcd4048 | 59 | token_response = self._download_json( |
60 | self._OAUTH_URL, | |
61 | None, 'Obtaining token', errnote='Unable to obtain token', data=urlencode_postdata({ | |
62 | 'affiliate': 'none', | |
63 | 'grant_type': 'device', | |
64 | 'device_vendor': 'unknown', | |
65 | 'app_id': 'dch.webapp', | |
66 | 'app_version': '1.0.0', | |
67 | 'client_secret': '2ySLN+2Fwb', | |
68 | }), headers={ | |
69 | 'Content-Type': 'application/x-www-form-urlencoded', | |
70 | }) | |
71 | self._ACCESS_TOKEN = token_response['access_token'] | |
72 | try: | |
73 | self._download_json( | |
74 | self._OAUTH_URL, | |
75 | None, note='Logging in', errnote='Unable to login', data=urlencode_postdata({ | |
76 | 'grant_type': 'password', | |
77 | 'username': username, | |
78 | 'password': password, | |
79 | }), headers={ | |
80 | 'Content-Type': 'application/x-www-form-urlencoded', | |
81 | 'Referer': 'https://www.digitalconcerthall.com', | |
82 | 'Authorization': f'Bearer {self._ACCESS_TOKEN}' | |
83 | }) | |
84 | except ExtractorError: | |
85 | self.raise_login_required(msg='Login info incorrect') | |
86 | ||
87 | def _real_initialize(self): | |
52efa4b3 | 88 | if not self._ACCESS_TOKEN: |
89 | self.raise_login_required(method='password') | |
8bcd4048 | 90 | |
55ed4ff7 | 91 | def _entries(self, items, language, type_, **kwargs): |
8bcd4048 | 92 | for item in items: |
93 | video_id = item['id'] | |
94 | stream_info = self._download_json( | |
95 | self._proto_relative_url(item['_links']['streams']['href']), video_id, headers={ | |
96 | 'Accept': 'application/json', | |
97 | 'Authorization': f'Bearer {self._ACCESS_TOKEN}', | |
98 | 'Accept-Language': language | |
99 | }) | |
100 | ||
101 | m3u8_url = traverse_obj( | |
a79cba0c | 102 | stream_info, ('channel', lambda k, _: k.startswith('vod_mixed'), 'stream', 0, 'url'), get_all=False) |
8bcd4048 | 103 | formats = self._extract_m3u8_formats(m3u8_url, video_id, 'mp4', 'm3u8_native', fatal=False) |
8bcd4048 | 104 | |
105 | yield { | |
106 | 'id': video_id, | |
107 | 'title': item.get('title'), | |
108 | 'composer': item.get('name_composer'), | |
109 | 'url': m3u8_url, | |
110 | 'formats': formats, | |
111 | 'duration': item.get('duration_total'), | |
112 | 'timestamp': traverse_obj(item, ('date', 'published')), | |
113 | 'description': item.get('short_description') or stream_info.get('short_description'), | |
114 | **kwargs, | |
115 | 'chapters': [{ | |
116 | 'start_time': chapter.get('time'), | |
117 | 'end_time': try_get(chapter, lambda x: x['time'] + x['duration']), | |
118 | 'title': chapter.get('text'), | |
55ed4ff7 | 119 | } for chapter in item['cuepoints']] if item.get('cuepoints') and type_ == 'concert' else None, |
8bcd4048 | 120 | } |
121 | ||
122 | def _real_extract(self, url): | |
55ed4ff7 | 123 | language, type_, video_id = self._match_valid_url(url).group('language', 'type', 'id') |
8bcd4048 | 124 | if not language: |
125 | language = 'en' | |
126 | ||
127 | thumbnail_url = self._html_search_regex( | |
128 | r'(https?://images\.digitalconcerthall\.com/cms/thumbnails/.*\.jpg)', | |
129 | self._download_webpage(url, video_id), 'thumbnail') | |
130 | thumbnails = [{ | |
131 | 'url': thumbnail_url, | |
132 | **parse_resolution(thumbnail_url) | |
133 | }] | |
134 | ||
135 | vid_info = self._download_json( | |
55ed4ff7 | 136 | f'https://api.digitalconcerthall.com/v2/{type_}/{video_id}', video_id, headers={ |
8bcd4048 | 137 | 'Accept': 'application/json', |
138 | 'Accept-Language': language | |
139 | }) | |
140 | album_artist = ' / '.join(traverse_obj(vid_info, ('_links', 'artist', ..., 'name')) or '') | |
55ed4ff7 | 141 | videos = [vid_info] if type_ == 'film' else traverse_obj(vid_info, ('_embedded', ..., ...)) |
8bcd4048 | 142 | |
143 | return { | |
144 | '_type': 'playlist', | |
145 | 'id': video_id, | |
146 | 'title': vid_info.get('title'), | |
55ed4ff7 | 147 | 'entries': self._entries(videos, language, thumbnails=thumbnails, album_artist=album_artist, type_=type_), |
8bcd4048 | 148 | 'thumbnails': thumbnails, |
149 | 'album_artist': album_artist, | |
150 | } |