@@ -3,7 +3,7 @@ import {MessageTypes} from '../../enums/MessageTypes.mjs';
33import { PlayerModes } from '../../enums/PlayerModes.mjs' ;
44import { SabrStreamingAdapter , SabrUmpProcessor } from '../../modules/googlevideo.mjs' ;
55import { Localize } from '../../modules/Localize.mjs' ;
6- import { ClientType , Innertube , UniversalCache } from '../../modules/yt.mjs' ;
6+ import { ClientType , Innertube , UniversalCache , Constants } from '../../modules/yt.mjs' ;
77import { IndexedDBManager } from '../../network/IndexedDBManager.mjs' ;
88import { SubtitleTrack } from '../../SubtitleTrack.mjs' ;
99import { AlertPolyfill } from '../../utils/AlertPolyfill.mjs' ;
@@ -103,6 +103,10 @@ export default class YTPlayer extends DashPlayer {
103103 serverAbrStreamingUrl,
104104 videoPlaybackUstreamerConfig,
105105 sabrFormats,
106+ clientInfo : {
107+ clientName : parseInt ( Constants . CLIENT_NAME_IDS [ this . ytclient . session . context . client . clientName ] ) ,
108+ clientVersion : this . ytclient . session . context . client . clientVersion ,
109+ } ,
106110 } ) ;
107111 adapter . setStreamingURL ( serverAbrStreamingUrl ) ;
108112 adapter . setServerAbrFormats ( sabrFormats ) ;
@@ -115,10 +119,47 @@ export default class YTPlayer extends DashPlayer {
115119 console . warn ( 'Sabr Snackbar Message:' , message ) ;
116120 } ) ;
117121
118- adapter . onReloadPlayerResponse ( ( response ) => {
119- console . warn ( 'Sabr Reload Player Response:' , response ) ;
122+ adapter . onReloadPlayerResponse ( async ( reloadPlaybackContext ) => {
123+ const newInfo = await this . ytclient . getInfo ( identifier , {
124+ client : this . defaultClient ,
125+ po_token : this . ytclient . session . content_token ,
126+ } , reloadPlaybackContext ) ;
127+ this . videoInfo = newInfo ;
128+
129+ const serverAbrStreamingUrl = await this . ytclient . session . player ?. decipher ( this . videoInfo . streaming_data ?. server_abr_streaming_url ) ;
130+ const videoPlaybackUstreamerConfig = this . videoInfo . player_config ?. media_common_config . media_ustreamer_request_config ?. video_playback_ustreamer_config ;
131+ const sabrFormats = this . videoInfo . streaming_data ?. adaptive_formats . map ( buildSabrFormat ) || [ ] ;
132+ this . newSabrFormats = sabrFormats ;
133+ if ( ! serverAbrStreamingUrl || ! videoPlaybackUstreamerConfig ) {
134+ console . error ( 'Failed to reload player, missing serverAbrStreamingUrl or videoPlaybackUstreamerConfig' ) ;
135+ return ;
136+ }
137+ adapter . setStreamingURL ( serverAbrStreamingUrl ) ;
138+ adapter . setUstreamerConfig ( videoPlaybackUstreamerConfig ) ;
139+ // adapter.setServerAbrFormats(sabrFormats);
140+ // console.warn('Sabr Reload Player:', reloadPlaybackContext);
141+
142+ // const manifest = await this.videoInfo.toDash({
143+ // manifest_options: {
144+ // is_sabr: true,
145+ // },
146+ // });
147+ // const blob = new Blob([manifest], {
148+ // type: 'application/dash+xml',
149+ // });
150+ // const uri = URL.createObjectURL(blob);
151+ // this.source = new VideoSource(uri, source.headers, PlayerModes.ACCELERATED_DASH);
152+ // this.source.identifier = 'yt-' + identifier;
153+ // this.source.headers['origin'] = 'https://www.youtube.com';
154+ // this.source.headers['referer'] = 'https://www.youtube.com/';
155+ // try {
156+ // this.dash.attachSource(this.source.url);
157+ // } catch (e) {
158+ // console.error('Failed to attach source', e);
159+ // }
120160 } ) ;
121161
162+
122163 adapter . attach ( ) ;
123164
124165 this . sabrAdapter = adapter ;
@@ -527,7 +568,7 @@ export default class YTPlayer extends DashPlayer {
527568 getActiveTrackFormats ( activeFormat , sabrFormats ) {
528569 const videoFormat = sabrFormats . find ( ( format ) => format . itag === parseInt ( this . currentLevel ) && format . mimeType . startsWith ( 'video/' ) ) ;
529570
530- const audioParts = this . currentAudioLevel . split ( '-' ) ;
571+ const audioParts = ( this . currentAudioLevel || '' ) . split ( '-' ) ;
531572 const itag = parseInt ( audioParts [ 0 ] ) ;
532573 let audioTrackId ;
533574 let isDrc = false ;
@@ -631,6 +672,10 @@ export default class YTPlayer extends DashPlayer {
631672 const result = await processor . processChunk ( new Uint8Array ( responseObject . data ) ) ;
632673 // console.log(result);
633674
675+ if ( requestMetadata . error ) {
676+ console . warn ( 'Request metadata has error' , requestMetadata . error ) ;
677+ }
678+
634679 if ( ! result ) {
635680 console . warn ( '(r) No result from SABR UMP processor for' , entry , requestMetadata ) ;
636681 responseObject . data = null ;
@@ -671,6 +716,10 @@ export default class YTPlayer extends DashPlayer {
671716 const result = await processor . processChunk ( new Uint8Array ( response . data ) ) ;
672717 // console.log(result);
673718
719+ if ( requestMetadata . error ) {
720+ console . warn ( 'Request metadata has error' , requestMetadata . error ) ;
721+ }
722+
674723 const responseObject = {
675724 ...response ,
676725 makeRequest : ( url , headers ) => {
@@ -774,7 +823,7 @@ async function getPoTokens(session, videoId) {
774823 const sessionCache = poTokenCache . sessionCache ;
775824
776825 let sessionToken = null ;
777- if ( sessionCache . token && sessionCache . visitorData === visitorData && sessionCache . expires > now ) {
826+ if ( sessionCache . token && sessionCache . visitorData === visitorData && sessionCache . expires > now ) {
778827 // session cache is valid, return it
779828 sessionToken = sessionCache . token ;
780829 }
0 commit comments