Completed buildPlayer method for youtubeEmbedHandler

This commit is contained in:
rainbow napkin 2025-05-08 08:22:42 -04:00
parent 1344756449
commit 1b0caa5e02
6 changed files with 43 additions and 19 deletions

View file

@ -33,7 +33,7 @@ module.exports.yankMedia = async function(url, title){
return await iaUtil.fetchMetadata(pullType.id, title); return await iaUtil.fetchMetadata(pullType.id, title);
case "yt": case "yt":
//return mediao object list from the YT-DLP module's youtube function //return mediao object list from the YT-DLP module's youtube function
return await ytdlpUtil.fetchYoutubeVideoMetadata(pullType.id, title); return await ytdlpUtil.fetchYoutubeMetadata(pullType.id, title);
case "dm": case "dm":
//return mediao object list from the YT-DLP module's dailymotion function //return mediao object list from the YT-DLP module's dailymotion function
return await ytdlpUtil.fetchDailymotionMetadata(pullType.id, title); return await ytdlpUtil.fetchDailymotionMetadata(pullType.id, title);
@ -58,7 +58,7 @@ module.exports.refreshRawLink = async function(mediaObj){
} }
//Re-fetch media metadata //Re-fetch media metadata
metadata = await ytdlpUtil.fetchYoutubeVideoMetadata(mediaObj.id); metadata = await ytdlpUtil.fetchYoutubeMetadata(mediaObj.id);
//Refresh media rawlink from metadata //Refresh media rawlink from metadata
mediaObj.rawLink = metadata[0].rawLink; mediaObj.rawLink = metadata[0].rawLink;

View file

@ -29,7 +29,7 @@ const media = require('../../app/channel/media/media.js');
const regexUtils = require('../regexUtils.js'); const regexUtils = require('../regexUtils.js');
const loggerUtils = require('../loggerUtils.js') const loggerUtils = require('../loggerUtils.js')
module.exports.fetchYoutubMetadata = async function(id, title){ module.exports.fetchYoutubeMetadata = async function(id, title){
try{ try{
//Try to pull media from youtube id //Try to pull media from youtube id
const media = await fetchMetadata(`https://youtu.be/${id}`, title, 'yt'); const media = await fetchMetadata(`https://youtu.be/${id}`, title, 'yt');

View file

@ -63,6 +63,11 @@ div#media-panel-div{
font-size: 1.2em; font-size: 1.2em;
} }
#youtube-embed-player{
width: 100%;
height: 100%;
}
div#chat-panel-div{ div#chat-panel-div{
position: relative; position: relative;
display: flex; display: flex;

View file

@ -163,7 +163,7 @@ class channel{
} }
//Youtube iframe-embed API load handler //Youtube iframe-embed API load handler
function onYoutubeIframeAPIReady(){ function onYouTubeIframeAPIReady(){
//Set embed api to true //Set embed api to true
client.ytEmbedAPILoaded = true; client.ytEmbedAPILoaded = true;
@ -171,7 +171,7 @@ function onYoutubeIframeAPIReady(){
const nowPlaying = client.player.mediaHandler.nowPlaying; const nowPlaying = client.player.mediaHandler.nowPlaying;
//If we're playing a youtube video and the official embeds are enabled //If we're playing a youtube video and the official embeds are enabled
if(nowPlaying.type == 'yt' && localStorage.get('ytPlayerType') == "embed"){ if(nowPlaying.type == 'yt' && localStorage.getItem('ytPlayerType') == "embed"){
//Restart the video now that the embed api has loaded //Restart the video now that the embed api has loaded
client.player.start({media: nowPlaying}); client.player.start({media: nowPlaying});
} }

View file

@ -312,23 +312,39 @@ class youtubeEmbedHandler extends mediaHandler{
} }
buildPlayer(){ buildPlayer(){
//If the embed API has loaded //If the embed API hasn't loaded
if(this.client.ytEmbedAPILoaded){ if(!this.client.ytEmbedAPILoaded){
//Create a new youtube player using the official YT iframe-embed api //Complain and stop
this.video = new YT.Player('video', { return console.warn("youtubeEmbedHandler.buildPlayer() Called before YT Iframe API Loaded, waiting on refresh to rebuild...");
//Inject video id
videoID: media.id,
//Set up event listeners (NGL kinda nice of google to do it this way...)
events: {
'onReady': this.embedPlayer.bind(this)
}
});
} }
//Clear out the player title so that youtube's baked in title can do it's thing.
//This will be replaced once we complete the full player control and remove the defualt youtube UI
this.player.title.textContent = "";
//Create temp div for yt api to replace
const tempDiv = document.createElement('div');
//Name the div
tempDiv.id = "youtube-embed-player"
//Append it to the video container
this.player.videoContainer.appendChild(tempDiv);
//Create a new youtube player using the official YT iframe-embed api
this.video = new YT.Player('youtube-embed-player', {
//Inject video id
videoId: this.nowPlaying.id,
//Set up event listeners (NGL kinda nice of google to do it this way...)
events: {
'onReady': this.initializePlayer.bind(this)
}
});
//Call derived function //Call derived function
super.buildPlayer(); super.buildPlayer();
} }
embedPlayer(){ initializePlayer(){
//Kick the video off
this.video.playVideo();
} }
} }

View file

@ -87,8 +87,11 @@ class player{
this.mediaHandler = new nullHandler(client, this); this.mediaHandler = new nullHandler(client, this);
//Otherwise //Otherwise
}else{ }else{
//If we have a raw-file compatible source //If we have a youtube video and the official embedded iframe player is selected
if(data.media.type == 'ia' || data.media.type == 'raw' || data.media.type == 'yt' || data.media.type == 'dm'){ if(data.media.type == 'yt' && localStorage.getItem("ytPlayerType") == 'embed'){
this.mediaHandler = new youtubeEmbedHandler(this.client, this, data.media);
//Otherwise, if we have a raw-file compatible source
}else if(data.media.type == 'ia' || data.media.type == 'raw' || data.media.type == 'yt' || data.media.type == 'dm'){
//Create a new raw file handler for it //Create a new raw file handler for it
this.mediaHandler = new rawFileHandler(client, this, data.media); this.mediaHandler = new rawFileHandler(client, this, data.media);
//Sync to time stamp //Sync to time stamp