added direct album and playlist play

This commit is contained in:
KGT1 2020-10-05 23:22:31 +02:00
parent e97c3f6a83
commit 2964b4a7e0
3 changed files with 34 additions and 16 deletions

View File

@ -34,7 +34,7 @@ function getMaxWidthString (string) {
class InterActivePlayMessage { class InterActivePlayMessage {
// musicplayermessage // musicplayermessage
// probably should have done events instead of. // probably should have done events instead of callbacks
/** /**
* *
* @param {Object} message * @param {Object} message
@ -125,14 +125,17 @@ class InterActivePlayMessage {
} }
updateProgress (ticks) { updateProgress (ticks) {
this.musicplayermessage.embeds[0].fields[0] = { if(typeof this.musicplayermessage !== "undefined" && typeof this.musicplayermessage.embeds[0] !== "undefined" && typeof this.musicplayermessage.embeds[0].fields[0] !== "undefined"){
name: getProgressString(ticks / this.ticksLength),
value: `${secondsToHms(ticksToSeconds(ticks))} / ${secondsToHms(ticksToSeconds(this.ticksLength))}`,
inline: false
};
this.musicplayermessage.timestamp = new Date(); this.musicplayermessage.embeds[0].fields[0] = {
this.musicplayermessage.edit(this.musicplayermessage.embeds[0]); name: getProgressString(ticks / this.ticksLength),
value: `${secondsToHms(ticksToSeconds(ticks))} / ${secondsToHms(ticksToSeconds(this.ticksLength))}`,
inline: false
};
this.musicplayermessage.timestamp = new Date();
this.musicplayermessage.edit(this.musicplayermessage.embeds[0]);
}
} }
updateCurrentSongMessage (title, artist, imageURL, itemURL, ticksLength, playlistIndex, playlistLenth) { updateCurrentSongMessage (title, artist, imageURL, itemURL, ticksLength, playlistIndex, playlistLenth) {

View File

@ -38,9 +38,11 @@ function hasMessage () {
* @param {Function} callback function to retrieve current ticks * @param {Function} callback function to retrieve current ticks
*/ */
function startUpate (callback) { function startUpate (callback) {
updateInterval = setInterval(() => { if(typeof CONFIG["interactive-seek-bar-update-intervall"] === "number" && CONFIG["interactive-seek-bar-update-intervall"] > 0){
iapm.updateProgress(callback()); updateInterval = setInterval(() => {
}, CONFIG["interactive-seek-bar-update-intervall"]); iapm.updateProgress(callback());
}, CONFIG["interactive-seek-bar-update-intervall"]);
}
} }
function updateCurrentSongMessage (title, artist, imageURL, itemURL, ticksLength, playlistIndex, playlistLenth) { function updateCurrentSongMessage (title, artist, imageURL, itemURL, ticksLength, playlistIndex, playlistLenth) {

View File

@ -47,13 +47,26 @@ function getRandomDiscordColor () {
async function searchForItemID (searchString) { async function searchForItemID (searchString) {
const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({ const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({
searchTerm: searchString, searchTerm: searchString,
includeItemTypes: "Audio" includeItemTypes: "Audio,MusicAlbum,Playlist"
}); });
if (response.TotalRecordCount < 1) { if (response.TotalRecordCount < 1) {
throw Error("Found no Song"); throw Error("Found nothing");
} else { } else {
return response.SearchHints[0].ItemId; console.log(response);
switch(response.SearchHints[0].Type){
case "Audio":
return [response.SearchHints[0].ItemId];
case "Playlist":
case "MusicAlbum":
console.log("Hey its a Music Album")
let resp = await jellyfinClientManager.getJellyfinClient().getItems(jellyfinClientManager.getJellyfinClient().getCurrentUserId(),{sortBy:"SortName", sortOrder:"Ascending",parentId:response.SearchHints[0].ItemId});
let itemArray = [];
resp.Items.forEach(element => {
itemArray.push(element.Id)
});
return itemArray;
}
} }
} }
@ -88,7 +101,7 @@ async function playThis (message) {
// check if play command was used with itemID // check if play command was used with itemID
const regexresults = checkJellyfinItemIDRegex(argument); const regexresults = checkJellyfinItemIDRegex(argument);
if (regexresults) { if (regexresults) {
itemID = regexresults[0]; itemID = regexresults;
} else { } else {
try { try {
itemID = await searchForItemID(argument); itemID = await searchForItemID(argument);
@ -101,7 +114,7 @@ async function playThis (message) {
} }
discordClient.user.client.voice.connections.forEach((element) => { discordClient.user.client.voice.connections.forEach((element) => {
playbackmanager.startPlaying(element, [itemID], 0, 0, isSummendByPlay); playbackmanager.startPlaying(element, itemID, 0, 0, isSummendByPlay);
playbackmanager.spawnPlayMessage(message); playbackmanager.spawnPlayMessage(message);
}); });
} }