This commit is contained in:
KGT1 2020-09-23 17:06:20 +02:00
parent 242ae2ffff
commit 212b9f658b
6 changed files with 17 additions and 34 deletions

View File

@ -15,6 +15,7 @@
"quotes": ["error", "double"],
"indent": ["error", "tab"],
"no-unused-vars": ["error"],
"no-tabs":["error",{"allowIndentationTabs":true}]
"no-tabs":["error",{"allowIndentationTabs":true}],
"no-console":["warn",{"allow":["error"]}]
}
}

View File

@ -10,5 +10,5 @@ if (!configfile["jellyfin-password"]) { configfile["jellyfin-password"] = proces
if (!configfile["jellyfin-app-name"]) { configfile["jellyfin-app-name"] = process.env.JELLYFIN_APP_NAME; }
fs.writeFile(filename, JSON.stringify(configfile, null, 1), (err) => {
if (err) return console.log(err);
if (err) return console.error(err);
});

View File

@ -15,10 +15,6 @@ jellyfinClientManager.getJellyfinClient().authenticateUserByName(CONFIG["jellyfi
jellyfinClientManager.getJellyfinClient().setAuthenticationInfo(response.AccessToken, response.SessionInfo.UserId);
});
discordClient.on("ready", () => {
console.log("connected to Discord");
});
discordClient.on("message", message => {
handleChannelMessage(message);
});

View File

@ -25,15 +25,14 @@ function startPlaying (voiceconnection = discordclientmanager.getDiscordClient()
isPaused = false;
currentPlayingItemId = itemID;
_disconnectOnFinish = disconnectOnFinish;
_seek=seekTo*1000;
_seek = seekTo * 1000;
async function playasync () {
const url = streamURLbuilder(itemID, voiceconnection.channel.bitrate);
setAudioDispatcher(voiceconnection.play(url ,{seek: seekTo}));
console.log(seekTo, ticksToSeconds(getPostitionTicks()));
if(seekTo){
setAudioDispatcher(voiceconnection.play(url, { seek: seekTo }));
if (seekTo) {
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload());
}else{
jellyfinClientManager.getJellyfinClient().reportPlaybackStart({ userID: `${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}`, itemID: `${itemID}`, canSeek: true ,playSessionId: getPlaySessionId(), playMethod:getPlayMethod()});
} else {
jellyfinClientManager.getJellyfinClient().reportPlaybackStart({ userID: `${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}`, itemID: `${itemID}`, canSeek: true, playSessionId: getPlaySessionId(), playMethod: getPlayMethod() });
}
getAudioDispatcher().on("finish", () => {
@ -44,14 +43,14 @@ function startPlaying (voiceconnection = discordclientmanager.getDiscordClient()
}
});
}
playasync().catch((rsn) => { console.log(rsn); });
playasync().catch((rsn) => { console.error(rsn); });
}
/**
* @param {Number} toSeek - where to seek in ticks
*/
function seek(toSeek = 0){
if(getAudioDispatcher()){
startPlaying(undefined,undefined,ticksToSeconds(toSeek),_disconnectOnFinish);
function seek (toSeek = 0) {
if (getAudioDispatcher()) {
startPlaying(undefined, undefined, ticksToSeconds(toSeek), _disconnectOnFinish);
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload());
}
}
@ -64,14 +63,13 @@ function stop (disconnectVoiceConnection) {
if (disconnectVoiceConnection) {
disconnectVoiceConnection.disconnect();
}
jellyfinClientManager.getJellyfinClient().reportPlaybackStopped({ userId: jellyfinClientManager.getJellyfinClient().getCurrentUserId(), itemId: currentPlayingItemId ,playSessionId: getPlaySessionId()});
jellyfinClientManager.getJellyfinClient().reportPlaybackStopped({ userId: jellyfinClientManager.getJellyfinClient().getCurrentUserId(), itemId: currentPlayingItemId, playSessionId: getPlaySessionId() });
if (getAudioDispatcher()) { getAudioDispatcher().destroy(); }
setAudioDispatcher(undefined);
clearInterval(progressInterval);
}
function pause () {
isPaused = true;
console.log("here paused is changed", isPaused);
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload());
getAudioDispatcher().pause(true);
}
@ -86,7 +84,7 @@ function playPause () {
function getPostitionTicks () {
// this is very sketchy but i dont know how else to do it
return (_seek+getAudioDispatcher().streamTime - getAudioDispatcher().pausedTime) * 10000;
return (_seek + getAudioDispatcher().streamTime - getAudioDispatcher().pausedTime) * 10000;
}
function getPlayMethod () {

View File

@ -3,8 +3,8 @@ function checkJellyfinItemIDRegex (strgintomatch) {
return regexresult;
}
function ticksToSeconds (ticks){
return ticks/10000000;
function ticksToSeconds (ticks) {
return ticks / 10000000;
}
module.exports = {

View File

@ -1,5 +1,4 @@
const jellyfinClientManager = require("./jellyfinclientmanager");
const discordclientmanager = require("./discordclientmanager");
const playbackmanager = require("./playbackmanager");
function openSocket () {
@ -11,21 +10,10 @@ function openSocket () {
SupportedCommands: "Play,Playstate"
}
);
jellyfinClientManager.getJellyfinClient().ajax({
type: 'POST',
url: jellyfinClientManager.getJellyfinClient().getUrl('system/info/public'),
data: JSON.stringify({}),
contentType: 'application/json'
}).then((resp)=>{console.log(resp)})
jellyfinClientManager.getJellyfinEvents().on(jellyfinClientManager.getJellyfinClient(), "message", (type, data) => {
if (data.MessageType === "Play") {
if (data.Data.PlayCommand === "PlayNow") {
playbackmanager.startPlaying(undefined, data.Data.ItemIds[data.Data.StartIndex || 0],0, false);
playbackmanager.startPlaying(undefined, data.Data.ItemIds[data.Data.StartIndex || 0], 0, false);
}
} else if (data.MessageType === "Playstate") {
if (data.Data.Command === "PlayPause") {