Skip to content

Commit

Permalink
Update bgplay.js
Browse files Browse the repository at this point in the history
  • Loading branch information
prateek-chaubey authored Feb 4, 2025
1 parent 113c0c1 commit d013a06
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions scripts/bgplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,73 +26,69 @@ document.body.appendChild(a);
}


/*The main BG Play fun*/
async function ytproAudPlayer(id){



/*The main BG Play fun*/
async function ytproAudPlayer(id){



if (!queue.includes(id)) {
queue.push(id);
}




if(document.getElementById("ytproAudDiv") == null ){
createAudElements();
}

var ytproURL="";


if(id != new URLSearchParams(window.location.search).get("v")){
createGTVideo();
}else{
if (document.querySelector("#GTVideo") != null) document.querySelector("#GTVideo").remove();
}

Android.fetchYouTubeData(id,true);

}



var g=`https://m.youtube.com/watch?v=${id}`;
var f=await fetch(g).then(r => r.text())


async function backToBgplay(info){

var ytproURL="";

try{
var sD=JSON.parse("{"+(f.substr(f.indexOf("streamingData")-1,((f.indexOf("playbackTracking")-1)-f.indexOf("streamingData"))))+"}");
var vD=JSON.parse("{"+f.substr(f.indexOf("\"videoDetails"),((f.indexOf("\"trackingParams")-1)-f.indexOf("\"videoDetails")))+"}");
}catch(e){
if(Object.keys(info).length === 0){
history.back();
return Android.showToast("Playback Error , Please open and issue on Github if the error persists.\n\n"+e);
return Android.showToast("Playback Error , Please open and issue on Github if the error persists.\n\n");
}


var af=sD?.streamingData?.adaptiveFormats;
var af=info?.streamingData?.adaptiveFormats;

var author=vD?.videoDetails?.author;
var thumb =[...vD?.videoDetails?.thumbnail?.thumbnails].pop().url;
var title=vD?.videoDetails?.title;
var author=info?.videoDetails?.author;
var thumb =[...info?.videoDetails?.thumbnail?.thumbnails].pop().url;
var title=info?.videoDetails?.title;



for(var x in af){

if(af[x]?.itag == "140"){
if("signatureCipher" in af[x]){
ytproURL=ytproGetURL(af[x].signatureCipher,"sig");
}else{
ytproURL=ytproGetURL(af[x].url,"n");
}

ytproURL=af[x].url;


break;

}
}

//console.log(ytproURL)


/*UI is important as well*/
Expand Down Expand Up @@ -179,10 +175,10 @@ setTimeout(()=>{Android.bgStart(iconBase64.replace("data:image/png;base64,", "")
ytproAud.play();



/*
if(songIndex >= (queue.length - 1)){
getQueue(id);
}
}*/



Expand Down Expand Up @@ -584,4 +580,3 @@ queue=[];
}



0 comments on commit d013a06

Please sign in to comment.