mirror of
https://github.com/informaticker/discord-jellyfin-bot.git
synced 2024-11-23 18:21:55 +01:00
fix all lint errors
This commit is contained in:
parent
31420a22cc
commit
f020613759
@ -11,5 +11,10 @@
|
|||||||
"ecmaVersion": 12
|
"ecmaVersion": 12
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
|
"semi": ["error", "always"],
|
||||||
|
"quotes": ["error", "double"],
|
||||||
|
"indent": ["error", "tab"],
|
||||||
|
"no-unused-vars": ["error"],
|
||||||
|
"no-tabs":["error",{"allowIndentationTabs":true}]
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,7 +6,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "node src/index.js",
|
"start": "node src/index.js",
|
||||||
"postinstall": "npx patch-package"
|
"postinstall": "npx patch-package",
|
||||||
|
"lint": "npx eslint src/ & npx eslint parseENV.js"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
29
parseENV.js
29
parseENV.js
@ -1,21 +1,14 @@
|
|||||||
const fs = require('fs');
|
const fs = require("fs");
|
||||||
const filename='./config.json';
|
const filename = "./config.json";
|
||||||
const configfile = require(filename);
|
const configfile = require(filename);
|
||||||
|
|
||||||
if(!configfile["discord-prefix"])
|
if (!configfile["discord-prefix"]) { configfile["discord-prefix"] = process.env.DISCORD_PREFIX; }
|
||||||
configfile["discord-prefix"]=process.env.DISCORD_PREFIX;
|
if (!configfile.token) { configfile.token = process.env.DISCORD_TOKEN; }
|
||||||
if(!configfile["token"])
|
if (!configfile["server-adress"]) { configfile["server-adress"] = process.env.JELLYFIN_SERVER_ADDRESS; }
|
||||||
configfile["token"]=process.env.DISCORD_TOKEN;
|
if (!configfile["jellyfin-username"]) { configfile["jellyfin-username"] = process.env.JELLYFIN_USERNAME; }
|
||||||
if(!configfile["server-adress"])
|
if (!configfile["jellyfin-password"]) { configfile["jellyfin-password"] = process.env.JELLYFIN_PASSWORD; }
|
||||||
configfile["server-adress"]=process.env.JELLYFIN_SERVER_ADDRESS;
|
if (!configfile["jellyfin-app-name"]) { configfile["jellyfin-app-name"] = process.env.JELLYFIN_APP_NAME; }
|
||||||
if(!configfile["jellyfin-username"])
|
|
||||||
configfile["jellyfin-username"]=process.env.JELLYFIN_USERNAME;
|
|
||||||
if(!configfile["jellyfin-password"])
|
|
||||||
configfile["jellyfin-password"]=process.env.JELLYFIN_PASSWORD;
|
|
||||||
if(!configfile["jellyfin-app-name"])
|
|
||||||
configfile["jellyfin-app-name"]=process.env.JELLYFIN_APP_NAME;
|
|
||||||
|
|
||||||
|
fs.writeFile(filename, JSON.stringify(configfile, null, 1), (err) => {
|
||||||
fs.writeFile(filename, JSON.stringify(configfile,null,1), (err) => {
|
if (err) return console.log(err);
|
||||||
if (err) return console.log(err);
|
});
|
||||||
});
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
const Discord = require('discord.js');
|
const Discord = require("discord.js");
|
||||||
|
|
||||||
var discordClient;
|
var discordClient;
|
||||||
|
|
||||||
function init(){
|
function init () {
|
||||||
discordClient= new Discord.Client();
|
discordClient = new Discord.Client();
|
||||||
}
|
}
|
||||||
function getDiscordClient(){
|
function getDiscordClient () {
|
||||||
return discordClient;
|
return discordClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getDiscordClient,
|
getDiscordClient,
|
||||||
init
|
init
|
||||||
}
|
};
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
var audioDispatcher;
|
var audioDispatcher;
|
||||||
|
|
||||||
function setAudioDispatcher(par){
|
function setAudioDispatcher (par) {
|
||||||
audioDispatcher=par;
|
audioDispatcher = par;
|
||||||
}
|
}
|
||||||
function getAudioDispatcher(){
|
function getAudioDispatcher () {
|
||||||
return audioDispatcher;
|
return audioDispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
setAudioDispatcher,
|
setAudioDispatcher,
|
||||||
getAudioDispatcher
|
getAudioDispatcher
|
||||||
}
|
};
|
||||||
|
29
src/index.js
29
src/index.js
@ -1,29 +1,26 @@
|
|||||||
|
|
||||||
|
const CONFIG = require("../config.json");
|
||||||
|
|
||||||
const CONFIG = require('../config.json');
|
const jellyfinClientManager = require("./jellyfinclientmanager");
|
||||||
|
|
||||||
const jellyfinClientManager=require('./jellyfinclientmanager');
|
const discordclientmanager = require("./discordclientmanager");
|
||||||
|
|
||||||
const discordclientmanager= require('./discordclientmanager');
|
|
||||||
discordclientmanager.init();
|
discordclientmanager.init();
|
||||||
const discordClient=discordclientmanager.getDiscordClient();
|
const discordClient = discordclientmanager.getDiscordClient();
|
||||||
|
|
||||||
const {audioDispatcher} = require('./dispachermanager');
|
const { handleChannelMessage } = require("./messagehandler");
|
||||||
const {handleChannelMessage}=require('./messagehandler');
|
|
||||||
|
|
||||||
jellyfinClientManager.init();
|
jellyfinClientManager.init();
|
||||||
//TODO Error Checking as the apiclients is inefficent
|
// TODO Error Checking as the apiclients is inefficent
|
||||||
jellyfinClientManager.getJellyfinClient().authenticateUserByName(CONFIG["jellyfin-username"],CONFIG["jellyfin-password"]).then((response)=>{
|
jellyfinClientManager.getJellyfinClient().authenticateUserByName(CONFIG["jellyfin-username"], CONFIG["jellyfin-password"]).then((response) => {
|
||||||
jellyfinClientManager.getJellyfinClient().setAuthenticationInfo(response.AccessToken, response.SessionInfo.UserId);
|
jellyfinClientManager.getJellyfinClient().setAuthenticationInfo(response.AccessToken, response.SessionInfo.UserId);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
discordClient.on("ready", () => {
|
||||||
discordClient.on('ready', () => {
|
console.log("connected to Discord");
|
||||||
console.log('connected to Discord');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
discordClient.on('message', message => {
|
discordClient.on("message", message => {
|
||||||
handleChannelMessage(message);
|
handleChannelMessage(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
discordClient.login(CONFIG.token);
|
discordClient.login(CONFIG.token);
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
|
|
||||||
const { ApiClient , Events } = require('jellyfin-apiclient');
|
const { ApiClient, Events } = require("jellyfin-apiclient");
|
||||||
const CONFIG = require('../config.json');
|
const CONFIG = require("../config.json");
|
||||||
const os = require('os');
|
const os = require("os");
|
||||||
|
|
||||||
var jellyfinClient;
|
var jellyfinClient;
|
||||||
|
|
||||||
function init(){
|
function init () {
|
||||||
jellyfinClient = new ApiClient(CONFIG["server-adress"], CONFIG["jellyfin-app-name"], "0.0.1", os.hostname(), os.hostname());
|
jellyfinClient = new ApiClient(CONFIG["server-adress"], CONFIG["jellyfin-app-name"], "0.0.1", os.hostname(), os.hostname());
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJellyfinClient(){
|
function getJellyfinClient () {
|
||||||
return jellyfinClient;
|
return jellyfinClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getJellyfinEvents(){
|
function getJellyfinEvents () {
|
||||||
return Events;
|
return Events;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getJellyfinClient,
|
getJellyfinClient,
|
||||||
getJellyfinEvents,
|
getJellyfinEvents,
|
||||||
init
|
init
|
||||||
}
|
};
|
||||||
|
@ -1,171 +1,155 @@
|
|||||||
const CONFIG = require('../config.json');
|
const CONFIG = require("../config.json");
|
||||||
const Discord = require('discord.js');
|
const Discord = require("discord.js");
|
||||||
const {
|
const {
|
||||||
checkJellyfinItemIDRegex
|
checkJellyfinItemIDRegex
|
||||||
} = require('./util');
|
} = require("./util");
|
||||||
const {
|
const {
|
||||||
getAudioDispatcher
|
getAudioDispatcher
|
||||||
} = require('./dispachermanager');
|
} = require("./dispachermanager");
|
||||||
|
|
||||||
const discordclientmanager = require('./discordclientmanager');
|
const discordclientmanager = require("./discordclientmanager");
|
||||||
const jellyfinClientManager = require('./jellyfinclientmanager');
|
const jellyfinClientManager = require("./jellyfinclientmanager");
|
||||||
const playbackmanager = require('./playbackmanager');
|
const playbackmanager = require("./playbackmanager");
|
||||||
const websocketHanler = require('./websockethandler');
|
const websocketHanler = require("./websockethandler");
|
||||||
const discordClient = discordclientmanager.getDiscordClient();
|
const discordClient = discordclientmanager.getDiscordClient();
|
||||||
|
|
||||||
|
|
||||||
var isSummendByPlay = false;
|
var isSummendByPlay = false;
|
||||||
|
|
||||||
|
// random Color of the Jellyfin Logo Gradient
|
||||||
|
function getRandomDiscordColor () {
|
||||||
|
function randomNumber (b, a) {
|
||||||
|
return Math.floor((Math.random() * Math.pow(Math.pow((b - a), 2), 1 / 2)) + (b > a ? a : b));
|
||||||
|
}
|
||||||
|
|
||||||
//random Color of the Jellyfin Logo Gradient
|
const GRANDIENT_START = "#AA5CC3";
|
||||||
function getRandomDiscordColor() {
|
const GRANDIENT_END = "#00A4DC";
|
||||||
function randomNumber(b, a) {
|
|
||||||
return Math.floor((Math.random() * Math.pow(Math.pow((b - a), 2), 1 / 2)) + (b > a ? a : b))
|
|
||||||
}
|
|
||||||
|
|
||||||
const GRANDIENT_START = '#AA5CC3';
|
let rS = GRANDIENT_START.slice(1, 3);
|
||||||
const GRANDIENT_END = '#00A4DC';
|
let gS = GRANDIENT_START.slice(3, 5);
|
||||||
|
let bS = GRANDIENT_START.slice(5, 7);
|
||||||
|
rS = parseInt(rS, 16);
|
||||||
|
gS = parseInt(gS, 16);
|
||||||
|
bS = parseInt(bS, 16);
|
||||||
|
|
||||||
let rS = GRANDIENT_START.slice(1, 3);
|
let rE = GRANDIENT_END.slice(1, 3);
|
||||||
let gS = GRANDIENT_START.slice(3, 5);
|
let gE = GRANDIENT_END.slice(3, 5);
|
||||||
let bS = GRANDIENT_START.slice(5, 7);
|
let bE = GRANDIENT_END.slice(5, 7);
|
||||||
rS = parseInt(rS, 16);
|
rE = parseInt(rE, 16);
|
||||||
gS = parseInt(gS, 16);
|
gE = parseInt(gE, 16);
|
||||||
bS = parseInt(bS, 16);
|
bE = parseInt(bE, 16);
|
||||||
|
|
||||||
let rE = GRANDIENT_END.slice(1, 3);
|
return ("#" + ("00" + (randomNumber(rS, rE)).toString(16)).substr(-2) + ("00" + (randomNumber(gS, gE)).toString(16)).substr(-2) + ("00" + (randomNumber(bS, bE)).toString(16)).substr(-2));
|
||||||
let gE = GRANDIENT_END.slice(3, 5);
|
|
||||||
let bE = GRANDIENT_END.slice(5, 7);
|
|
||||||
rE = parseInt(rE, 16);
|
|
||||||
gE = parseInt(gE, 16);
|
|
||||||
bE = parseInt(bE, 16);
|
|
||||||
|
|
||||||
return ('#' + ('00' + (randomNumber(rS, rE)).toString(16)).substr(-2) + ('00' + (randomNumber(gS, gE)).toString(16)).substr(-2) + ('00' + (randomNumber(bS, bE)).toString(16)).substr(-2));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function searchForItemID(searchString) {
|
async function searchForItemID (searchString) {
|
||||||
|
const response = await jellyfinClientManager.getJellyfinClient().getSearchHints({
|
||||||
|
searchTerm: searchString,
|
||||||
|
includeItemTypes: "Audio"
|
||||||
|
});
|
||||||
|
|
||||||
let response = await jellyfinClientManager.getJellyfinClient().getSearchHints({
|
if (response.TotalRecordCount < 1) {
|
||||||
searchTerm: searchString,
|
throw Error("Found no Song");
|
||||||
includeItemTypes: "Audio"
|
} else {
|
||||||
})
|
return response.SearchHints[0].ItemId;
|
||||||
|
}
|
||||||
if (response.TotalRecordCount < 1) {
|
|
||||||
throw "Found no Song"
|
|
||||||
} else {
|
|
||||||
return response.SearchHints[0].ItemId
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function summon(voiceChannel){
|
function summon (voiceChannel) {
|
||||||
voiceChannel.join()
|
voiceChannel.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
function summonMessage(message){
|
function summonMessage (message) {
|
||||||
if (!message.member.voice.channel) {
|
if (!message.member.voice.channel) {
|
||||||
message.reply('please join a voice channel to summon me!');
|
message.reply("please join a voice channel to summon me!");
|
||||||
}else if(message.channel.type === 'dm'){
|
} else if (message.channel.type === "dm") {
|
||||||
message.reply('no dms')
|
message.reply("no dms");
|
||||||
}
|
} else {
|
||||||
else{
|
summon(message.member.voice.channel);
|
||||||
summon(message.member.voice.channel)
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleChannelMessage(message) {
|
async function playThis (message) {
|
||||||
getRandomDiscordColor()
|
const indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + "play") + (CONFIG["discord-prefix"] + "play").length + 1;
|
||||||
|
const argument = message.content.slice(indexOfItemID);
|
||||||
|
let itemID;
|
||||||
|
// check if play command was used with itemID
|
||||||
|
const regexresults = checkJellyfinItemIDRegex(argument);
|
||||||
|
if (regexresults) {
|
||||||
|
itemID = regexresults[0];
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
itemID = await searchForItemID(argument);
|
||||||
|
} catch (e) {
|
||||||
|
message.reply(e.message);
|
||||||
|
playbackmanager.stop(discordClient.user.client.voice.connections.first());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (message.content.startsWith(CONFIG["discord-prefix"] + 'summon')) {
|
discordClient.user.client.voice.connections.forEach((element) => {
|
||||||
isSummendByPlay = false;
|
playbackmanager.startPlaying(element, itemID, isSummendByPlay);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
websocketHanler.openSocket();
|
function handleChannelMessage (message) {
|
||||||
|
getRandomDiscordColor();
|
||||||
|
|
||||||
summonMessage(message);
|
if (message.content.startsWith(CONFIG["discord-prefix"] + "summon")) {
|
||||||
|
isSummendByPlay = false;
|
||||||
|
|
||||||
|
websocketHanler.openSocket();
|
||||||
|
|
||||||
|
summonMessage(message);
|
||||||
|
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "disconnect")) {
|
||||||
|
playbackmanager.stop();
|
||||||
|
jellyfinClientManager.getJellyfinClient().closeWebSocket();
|
||||||
|
discordClient.user.client.voice.connections.forEach((element) => {
|
||||||
|
element.disconnect();
|
||||||
|
});
|
||||||
|
} else if ((message.content.startsWith(CONFIG["discord-prefix"] + "pause")) || (message.content.startsWith(CONFIG["discord-prefix"] + "resume"))) {
|
||||||
|
if (getAudioDispatcher() !== undefined) {
|
||||||
|
playbackmanager.playPause();
|
||||||
|
} else {
|
||||||
|
message.reply("there is nothing playing!");
|
||||||
|
}
|
||||||
|
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "play")) {
|
||||||
|
if (discordClient.user.client.voice.connections.size < 1) {
|
||||||
|
summonMessage(message);
|
||||||
|
isSummendByPlay = true;
|
||||||
|
}
|
||||||
|
|
||||||
} else if (message.content.startsWith(CONFIG["discord-prefix"] + 'disconnect')) {
|
playThis(message);
|
||||||
playbackmanager.stop()
|
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "stop")) {
|
||||||
jellyfinClientManager.getJellyfinClient().closeWebSocket();
|
if (isSummendByPlay) {
|
||||||
discordClient.user.client.voice.connections.forEach((element) => {
|
if (discordClient.user.client.voice.connections.size > 0) {
|
||||||
element.disconnect();
|
playbackmanager.stop(discordClient.user.client.voice.connections.first());
|
||||||
});
|
}
|
||||||
|
} else {
|
||||||
|
playbackmanager.stop();
|
||||||
} else if ((message.content.startsWith(CONFIG["discord-prefix"] + 'pause')) || (message.content.startsWith(CONFIG["discord-prefix"] + 'resume'))) {
|
}
|
||||||
if (getAudioDispatcher() !== undefined) {
|
} else if (message.content.startsWith(CONFIG["discord-prefix"] + "help")) {
|
||||||
playbackmanager.playPause();
|
const reply = new Discord.MessageEmbed()
|
||||||
} else {
|
.setColor(getRandomDiscordColor())
|
||||||
message.reply("there is nothing playing!")
|
.addFields({
|
||||||
}
|
name: `${CONFIG["discord-prefix"]}summon`,
|
||||||
|
value: "Join the channel the author of the message"
|
||||||
|
}, {
|
||||||
} else if (message.content.startsWith(CONFIG["discord-prefix"] + 'play')) {
|
name: `${CONFIG["discord-prefix"]}disconnect`,
|
||||||
|
value: "Disconnect from all current Voice Channels"
|
||||||
|
}, {
|
||||||
if (discordClient.user.client.voice.connections.size < 1) {
|
name: `${CONFIG["discord-prefix"]}play`,
|
||||||
summonMessage(message)
|
value: "Play the following item"
|
||||||
isSummendByPlay=true
|
}, {
|
||||||
}
|
name: `${CONFIG["discord-prefix"]}pause/resume`,
|
||||||
|
value: "Pause/Resume audio"
|
||||||
async function playThis(){
|
}, {
|
||||||
|
name: `${CONFIG["discord-prefix"]}help`,
|
||||||
let indexOfItemID = message.content.indexOf(CONFIG["discord-prefix"] + 'play') + (CONFIG["discord-prefix"] + 'play').length + 1;
|
value: "Display this help message"
|
||||||
let argument = message.content.slice(indexOfItemID);
|
});
|
||||||
let itemID;
|
message.channel.send(reply);
|
||||||
//check if play command was used with itemID
|
}
|
||||||
let regexresults = checkJellyfinItemIDRegex(argument);
|
|
||||||
if (regexresults) {
|
|
||||||
itemID = regexresults[0];
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
itemID = await searchForItemID(argument);
|
|
||||||
} catch (e) {
|
|
||||||
message.reply(e);
|
|
||||||
playbackmanager.stop(discordClient.user.client.voice.connections.first());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
discordClient.user.client.voice.connections.forEach((element) => {
|
|
||||||
playbackmanager.startPlaying(element,itemID,isSummendByPlay);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
playThis();
|
|
||||||
|
|
||||||
} else if (message.content.startsWith(CONFIG["discord-prefix"] + 'stop')) {
|
|
||||||
if(isSummendByPlay){
|
|
||||||
if(discordClient.user.client.voice.connections.size > 0){
|
|
||||||
playbackmanager.stop(discordClient.user.client.voice.connections.first());
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
playbackmanager.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (message.content.startsWith(CONFIG["discord-prefix"] + 'help')) {
|
|
||||||
const reply = new Discord.MessageEmbed()
|
|
||||||
.setColor(getRandomDiscordColor())
|
|
||||||
.addFields({
|
|
||||||
name: `${CONFIG['discord-prefix']}summon`,
|
|
||||||
value: 'Join the channel the author of the message'
|
|
||||||
}, {
|
|
||||||
name: `${CONFIG['discord-prefix']}disconnect`,
|
|
||||||
value: 'Disconnect from all current Voice Channels'
|
|
||||||
}, {
|
|
||||||
name: `${CONFIG['discord-prefix']}play`,
|
|
||||||
value: 'Play the following item'
|
|
||||||
}, {
|
|
||||||
name: `${CONFIG['discord-prefix']}pause/resume`,
|
|
||||||
value: 'Pause/Resume audio'
|
|
||||||
}, {
|
|
||||||
name: `${CONFIG['discord-prefix']}help`,
|
|
||||||
value: 'Display this help message'
|
|
||||||
})
|
|
||||||
message.channel.send(reply);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
handleChannelMessage
|
handleChannelMessage
|
||||||
}
|
};
|
||||||
|
@ -1,156 +1,146 @@
|
|||||||
const { default: fetch } = require('node-fetch');
|
|
||||||
const {
|
const {
|
||||||
getAudioDispatcher,
|
getAudioDispatcher,
|
||||||
setAudioDispatcher
|
setAudioDispatcher
|
||||||
} = require('./dispachermanager');
|
} = require("./dispachermanager");
|
||||||
|
|
||||||
var currentPlayingItemId;
|
var currentPlayingItemId;
|
||||||
var progressInterval;
|
var progressInterval;
|
||||||
var isPaused;
|
var isPaused;
|
||||||
|
|
||||||
const jellyfinClientManager = require('./jellyfinclientmanager');
|
const jellyfinClientManager = require("./jellyfinclientmanager");
|
||||||
function streamURLbuilder(itemID, bitrate) {
|
function streamURLbuilder (itemID, bitrate) {
|
||||||
//so the server transcodes. Seems appropriate as it has the source file.
|
// so the server transcodes. Seems appropriate as it has the source file.
|
||||||
let supportedCodecs = "opus"
|
const supportedCodecs = "opus";
|
||||||
let supportedContainers = "ogg,opus"
|
const supportedContainers = "ogg,opus";
|
||||||
return `${jellyfinClientManager.getJellyfinClient().serverAddress()}/Audio/${itemID}/universal?UserId=${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}&DeviceId=${jellyfinClientManager.getJellyfinClient().deviceId()}&MaxStreamingBitrate=${bitrate}&Container=${supportedContainers}&AudioCodec=${supportedCodecs}&api_key=${jellyfinClientManager.getJellyfinClient().accessToken()}&TranscodingContainer=ts&TranscodingProtocol=hls`;
|
return `${jellyfinClientManager.getJellyfinClient().serverAddress()}/Audio/${itemID}/universal?UserId=${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}&DeviceId=${jellyfinClientManager.getJellyfinClient().deviceId()}&MaxStreamingBitrate=${bitrate}&Container=${supportedContainers}&AudioCodec=${supportedCodecs}&api_key=${jellyfinClientManager.getJellyfinClient().accessToken()}&TranscodingContainer=ts&TranscodingProtocol=hls`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function startPlaying(voiceconnection, itemID, disconnectOnFinish) {
|
function startPlaying (voiceconnection, itemID, disconnectOnFinish) {
|
||||||
isPaused=false;
|
isPaused = false;
|
||||||
async function playasync() {
|
async function playasync () {
|
||||||
let url = streamURLbuilder(itemID, voiceconnection.channel.bitrate)
|
const url = streamURLbuilder(itemID, voiceconnection.channel.bitrate);
|
||||||
jellyfinClientManager.getJellyfinClient().reportPlaybackStart({ userID: `${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}`, itemID: `${itemID}` })
|
jellyfinClientManager.getJellyfinClient().reportPlaybackStart({ userID: `${jellyfinClientManager.getJellyfinClient().getCurrentUserId()}`, itemID: `${itemID}` });
|
||||||
currentPlayingItemId = itemID;
|
currentPlayingItemId = itemID;
|
||||||
setAudioDispatcher(voiceconnection.play(url));
|
setAudioDispatcher(voiceconnection.play(url));
|
||||||
let time = await jellyfinClientManager.getJellyfinClient().getItem(jellyfinClientManager.getJellyfinClient().getCurrentUserId(),currentPlayingItemId)
|
|
||||||
async function asfg(){
|
|
||||||
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload())
|
|
||||||
}
|
|
||||||
//progressInterval=setInterval(asfg,2000);
|
|
||||||
|
|
||||||
getAudioDispatcher().on("finish", () => {
|
getAudioDispatcher().on("finish", () => {
|
||||||
if (disconnectOnFinish) {
|
if (disconnectOnFinish) {
|
||||||
stop(voiceconnection);
|
stop(voiceconnection);
|
||||||
}else{
|
} else {
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
playasync().catch((rsn) => { console.log(rsn) });
|
playasync().catch((rsn) => { console.log(rsn); });
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {Object=} disconnectVoiceConnection - Optional The voice Connection do disconnect from
|
* @param {Object=} disconnectVoiceConnection - Optional The voice Connection do disconnect from
|
||||||
*/
|
*/
|
||||||
function stop(disconnectVoiceConnection) {
|
function stop (disconnectVoiceConnection) {
|
||||||
isPaused=true;
|
isPaused = true;
|
||||||
if (disconnectVoiceConnection) {
|
if (disconnectVoiceConnection) {
|
||||||
disconnectVoiceConnection.disconnect()
|
disconnectVoiceConnection.disconnect();
|
||||||
}
|
}
|
||||||
jellyfinClientManager.getJellyfinClient().reportPlaybackStopped({userId: jellyfinClientManager.getJellyfinClient().getCurrentUserId(),itemId:currentPlayingItemId})
|
jellyfinClientManager.getJellyfinClient().reportPlaybackStopped({ userId: jellyfinClientManager.getJellyfinClient().getCurrentUserId(), itemId: currentPlayingItemId });
|
||||||
if(getAudioDispatcher())
|
if (getAudioDispatcher()) { getAudioDispatcher().destroy(); }
|
||||||
getAudioDispatcher().destroy();
|
setAudioDispatcher(undefined);
|
||||||
setAudioDispatcher(undefined);
|
clearInterval(progressInterval);
|
||||||
clearInterval(progressInterval);
|
|
||||||
}
|
}
|
||||||
function pause() {
|
function pause () {
|
||||||
isPaused=true;
|
isPaused = true;
|
||||||
console.log('here paused is changed', isPaused);
|
console.log("here paused is changed", isPaused);
|
||||||
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload())
|
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload());
|
||||||
getAudioDispatcher().pause(true);
|
getAudioDispatcher().pause(true);
|
||||||
}
|
}
|
||||||
function resume() {
|
function resume () {
|
||||||
isPaused=false;
|
isPaused = false;
|
||||||
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload())
|
jellyfinClientManager.getJellyfinClient().reportPlaybackProgress(getProgressPayload());
|
||||||
getAudioDispatcher().resume();
|
getAudioDispatcher().resume();
|
||||||
}
|
}
|
||||||
function playPause() {
|
function playPause () {
|
||||||
if (getAudioDispatcher().paused)
|
if (getAudioDispatcher().paused) { resume(); } else { pause(); }
|
||||||
resume();
|
|
||||||
else
|
|
||||||
pause();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPostitionTicks(){
|
function getPostitionTicks () {
|
||||||
//this is very sketchy but i dont know how else to do it
|
// this is very sketchy but i dont know how else to do it
|
||||||
return (getAudioDispatcher().streamTime - getAudioDispatcher().pausedTime)*10000;
|
return (getAudioDispatcher().streamTime - getAudioDispatcher().pausedTime) * 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlayMethod(){
|
function getPlayMethod () {
|
||||||
//TODO figure out how to figure this out
|
// TODO figure out how to figure this out
|
||||||
return 'Transcode';
|
return "Transcode";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRepeatMode(){
|
function getRepeatMode () {
|
||||||
return 'RepeatNone';
|
return "RepeatNone";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlaylistItemId(){
|
function getPlaylistItemId () {
|
||||||
//as I curently dont support Playlists
|
// as I curently dont support Playlists
|
||||||
return 'playlistItem0'
|
return "playlistItem0";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPlaySessionId(){
|
function getPlaySessionId () {
|
||||||
//i think its just a number which you dont need to retrieve but need to report
|
// i think its just a number which you dont need to retrieve but need to report
|
||||||
return 'ae2436edc6b91b11d72aeaa67f84e0ea';
|
return "ae2436edc6b91b11d72aeaa67f84e0ea";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNowPLayingQueue(){
|
function getNowPLayingQueue () {
|
||||||
return [{
|
return [{
|
||||||
Id: currentPlayingItemId,
|
Id: currentPlayingItemId,
|
||||||
//as I curently dont support Playlists
|
// as I curently dont support Playlists
|
||||||
PlaylistItemId: getPlaylistItemId()
|
PlaylistItemId: getPlaylistItemId()
|
||||||
}]
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCanSeek(){
|
function getCanSeek () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIsMuted(){
|
function getIsMuted () {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVolumeLevel(){
|
function getVolumeLevel () {
|
||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getItemId(){
|
function getItemId () {
|
||||||
return currentPlayingItemId
|
return currentPlayingItemId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIsPaused(){
|
function getIsPaused () {
|
||||||
//AudioDispacker Paused is to slow
|
// AudioDispacker Paused is to slow
|
||||||
|
|
||||||
if(isPaused == undefined){
|
if (isPaused === undefined) {
|
||||||
isPaused=false;
|
isPaused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isPaused;
|
return isPaused;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getProgressPayload(){
|
function getProgressPayload () {
|
||||||
let payload= {
|
const payload = {
|
||||||
CanSeek: getCanSeek(),
|
CanSeek: getCanSeek(),
|
||||||
IsMuted: getIsMuted(),
|
IsMuted: getIsMuted(),
|
||||||
IsPaused: getIsPaused(),
|
IsPaused: getIsPaused(),
|
||||||
ItemId: getItemId(),
|
ItemId: getItemId(),
|
||||||
MediaSourceId: getItemId(),
|
MediaSourceId: getItemId(),
|
||||||
NowPlayingQueue: getNowPLayingQueue(),
|
NowPlayingQueue: getNowPLayingQueue(),
|
||||||
PlayMethod: getPlayMethod(),
|
PlayMethod: getPlayMethod(),
|
||||||
PlaySessionId: getPlaySessionId(),
|
PlaySessionId: getPlaySessionId(),
|
||||||
PlaylistItemId: getPlaylistItemId(),
|
PlaylistItemId: getPlaylistItemId(),
|
||||||
PositionTicks: getPostitionTicks(),
|
PositionTicks: getPostitionTicks(),
|
||||||
RepeatMode: getRepeatMode(),
|
RepeatMode: getRepeatMode(),
|
||||||
VolumeLevel: getVolumeLevel()
|
VolumeLevel: getVolumeLevel()
|
||||||
}
|
};
|
||||||
return payload
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
startPlaying,
|
startPlaying,
|
||||||
stop,
|
stop,
|
||||||
playPause,
|
playPause,
|
||||||
resume,
|
resume,
|
||||||
pause
|
pause
|
||||||
}
|
};
|
||||||
|
12
src/util.js
12
src/util.js
@ -1,8 +1,8 @@
|
|||||||
function checkJellyfinItemIDRegex(strgintomatch){
|
function checkJellyfinItemIDRegex (strgintomatch) {
|
||||||
let regexresult=strgintomatch.match(/([0-9]|[a-f]){32}/);
|
const regexresult = strgintomatch.match(/([0-9]|[a-f]){32}/);
|
||||||
return regexresult;
|
return regexresult;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports={
|
module.exports = {
|
||||||
checkJellyfinItemIDRegex
|
checkJellyfinItemIDRegex
|
||||||
}
|
};
|
||||||
|
@ -1,38 +1,37 @@
|
|||||||
const jellyfinClientManager = require('./jellyfinclientmanager');
|
const jellyfinClientManager = require("./jellyfinclientmanager");
|
||||||
const discordclientmanager = require('./discordclientmanager');
|
const discordclientmanager = require("./discordclientmanager");
|
||||||
const playbackmanager = require('./playbackmanager');
|
const playbackmanager = require("./playbackmanager");
|
||||||
|
|
||||||
|
function openSocket () {
|
||||||
function openSocket() {
|
jellyfinClientManager.getJellyfinClient().openWebSocket();
|
||||||
jellyfinClientManager.getJellyfinClient().openWebSocket();
|
jellyfinClientManager.getJellyfinClient().reportCapabilities(
|
||||||
jellyfinClientManager.getJellyfinClient().reportCapabilities(
|
{
|
||||||
{
|
PlayableMediaTypes: "Audio",
|
||||||
'PlayableMediaTypes': "Audio",
|
SupportsMediaControl: "True",
|
||||||
'SupportsMediaControl': "True",
|
SupportedCommands: "Play,Playstate"
|
||||||
'SupportedCommands': "Play,Playstate"
|
}
|
||||||
}
|
);
|
||||||
);
|
jellyfinClientManager.getJellyfinEvents().on(jellyfinClientManager.getJellyfinClient(), "message", (type, data) => {
|
||||||
jellyfinClientManager.getJellyfinEvents().on(jellyfinClientManager.getJellyfinClient(), "message", (type, data) => {
|
// console.log(data);
|
||||||
//console.log(data);
|
if (data.MessageType === "Play") {
|
||||||
if (data.MessageType == 'Play') {
|
if (data.Data.PlayCommand === "PlayNow") {
|
||||||
if (data.Data.PlayCommand == 'PlayNow') {
|
discordclientmanager.getDiscordClient().user.client.voice.connections.forEach((element) => {
|
||||||
discordclientmanager.getDiscordClient().user.client.voice.connections.forEach((element) => {
|
playbackmanager.startPlaying(element, data.Data.ItemIds[data.Data.StartIndex || 0], false);
|
||||||
playbackmanager.startPlaying(element, data.Data.ItemIds[data.Data.StartIndex||0], false);
|
element.on("error", (error) => {
|
||||||
element.on("error", (error) => {
|
console.error(error);
|
||||||
console.error(error);
|
});
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
} else if (data.MessageType === "Playstate") {
|
||||||
}else if(data.MessageType == 'Playstate'){
|
if (data.Data.Command === "PlayPause") {
|
||||||
if(data.Data.Command == 'PlayPause'){
|
playbackmanager.playPause();
|
||||||
playbackmanager.playPause();
|
} else if (data.Data.Command === "Stop") {
|
||||||
}else if(data.Data.Command == 'Stop'){
|
playbackmanager.stop();
|
||||||
playbackmanager.stop();
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
openSocket
|
openSocket
|
||||||
}
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user