From 37f3457d2b18b540fbcbf9ae8d8afb83af322cc4 Mon Sep 17 00:00:00 2001 From: Maxime BACONNAIS Date: Mon, 8 Jul 2019 20:06:26 +0200 Subject: [PATCH 1/6] Fix Chromecast jump issues --- src/routes/transcode.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/routes/transcode.js b/src/routes/transcode.js index 79e3c7a..557bdc4 100644 --- a/src/routes/transcode.js +++ b/src/routes/transcode.js @@ -65,10 +65,6 @@ RoutesTranscode.lpStart = (req, res) => { // Log D('START ' + sessionId + ' [LP]'); - // If sessionId is defined - if (sessionId) - SessionsManager.cleanSession(sessionId); - // Redirect RoutesTranscode.redirect(req, res); } From e0547e74ec4a61b2385504c7b6b9137caff5d3bb Mon Sep 17 00:00:00 2001 From: Maxime Baconnais Date: Mon, 8 Jul 2019 20:15:08 +0200 Subject: [PATCH 2/6] API update: INTERNAL_RESOURCES to INTERNAL_PLEX_SETUP --- src/core/sessions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/sessions.js b/src/core/sessions.js index 3714797..7832e1a 100644 --- a/src/core/sessions.js +++ b/src/core/sessions.js @@ -88,7 +88,7 @@ SessionsManager.parseFFmpegParameters = async (args = [], env = {}, optimizeMode return (e.replace(plexUrl(), '{INTERNAL_TRANSCODER}')); // Other - return (e.replace(plexUrl(), publicUrl()).replace(config.plex.path.sessions, publicUrl() + 'api/sessions/').replace(config.plex.path.usr, '{INTERNAL_RESOURCES}')); + return (e.replace(plexUrl(), publicUrl()).replace(config.plex.path.sessions, publicUrl() + 'api/sessions/').replace(config.plex.path.usr, '{INTERNAL_PLEX_SETUP}')); }); // Add seglist to arguments if needed and resolve links if needed From 149fd614989a9cb68dd727ce13f63f9f65264faf Mon Sep 17 00:00:00 2001 From: Maxime Baconnais Date: Mon, 8 Jul 2019 20:26:02 +0200 Subject: [PATCH 3/6] Fix multi arguments to replace (Subtitles issue) --- src/core/sessions.js | 6 +++++- src/utils.js | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/sessions.js b/src/core/sessions.js index 7832e1a..540e3df 100644 --- a/src/core/sessions.js +++ b/src/core/sessions.js @@ -88,7 +88,11 @@ SessionsManager.parseFFmpegParameters = async (args = [], env = {}, optimizeMode return (e.replace(plexUrl(), '{INTERNAL_TRANSCODER}')); // Other - return (e.replace(plexUrl(), publicUrl()).replace(config.plex.path.sessions, publicUrl() + 'api/sessions/').replace(config.plex.path.usr, '{INTERNAL_PLEX_SETUP}')); + let parsed = e; + parsed = replaceAll(parsed, plexUrl(), publicUrl()) + parsed = replaceAll(parsed, config.plex.path.sessions, publicUrl() + 'api/sessions/') + parsed = replaceAll(parsed, config.plex.path.usr, '{INTERNAL_PLEX_SETUP}') + return parsed; }); // Add seglist to arguments if needed and resolve links if needed diff --git a/src/utils.js b/src/utils.js index 27ab30e..be9b159 100644 --- a/src/utils.js +++ b/src/utils.js @@ -53,4 +53,11 @@ export const mdir = (path) => (new Promise((resolve, reject) => { return reject(err); return resolve(path); }) -})); \ No newline at end of file +})); + +export const replaceAll = (input, search, replace) => { + let str = input; + while (str.indexOf(search) !== -1) + str = str.replace(search, replace); + return str +}; \ No newline at end of file From 84500f8e9ee95491534afc4b0d067fbd53e49d1e Mon Sep 17 00:00:00 2001 From: Maxime Baconnais Date: Mon, 8 Jul 2019 20:39:09 +0200 Subject: [PATCH 4/6] Fix import --- src/core/sessions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/sessions.js b/src/core/sessions.js index 540e3df..bce3fb4 100644 --- a/src/core/sessions.js +++ b/src/core/sessions.js @@ -1,6 +1,6 @@ import debug from 'debug'; import config from '../config'; -import { publicUrl, plexUrl, download, mdir } from '../utils'; +import { publicUrl, plexUrl, download, mdir, replaceAll } from '../utils'; import { dirname } from 'path'; import SessionStore from '../store'; import ServersManager from './servers'; From beb8516c23b7ccc696b7c0a35c28ffad7b34171c Mon Sep 17 00:00:00 2001 From: Maxime Baconnais Date: Mon, 8 Jul 2019 21:02:23 +0200 Subject: [PATCH 5/6] Fix download load balancing --- src/core/sessions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/sessions.js b/src/core/sessions.js index bce3fb4..dfe67cd 100644 --- a/src/core/sessions.js +++ b/src/core/sessions.js @@ -22,7 +22,7 @@ let ffmpegCache = {}; let urls = {}; SessionsManager.chooseServer = async (session, ip = false) => { - if (urls[session]) + if (session && urls[session]) return (urls[session]); let url = ''; try { @@ -30,7 +30,7 @@ SessionsManager.chooseServer = async (session, ip = false) => { } catch (err) { } D('SERVER ' + session + ' [' + url + ']'); - if (url.length) + if (session && url.length) urls[session] = url; return (url); }; From 48519a3e41f5f95444cc5775ba140cc334856be3 Mon Sep 17 00:00:00 2001 From: Maxime Baconnais Date: Mon, 8 Jul 2019 21:28:41 +0200 Subject: [PATCH 6/6] Replace Plex URL by direct file --- src/core/sessions.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/core/sessions.js b/src/core/sessions.js index dfe67cd..fc30b73 100644 --- a/src/core/sessions.js +++ b/src/core/sessions.js @@ -132,12 +132,34 @@ SessionsManager.parseFFmpegParameters = async (args = [], env = {}, optimizeMode if (typeof (data.id) !== 'undefined') file = `${publicUrl()}library/parts/${data.id}/0/file.stream?download=1`; } catch (e) { - file = parsedArgs[i] + file = parsedArgs[i]; } finalArgs.push(file); continue; } + // Link resolver (Replace Plex file url by direct file) + if (i > 0 && parsedArgs[i - 1] === '-i' && config.custom.download.forward) { + let file = parsedArgs[i]; + let partId = false; + if (file.indexOf('library/parts/') !== -1) { + partId = file.split('library/parts/')[1].split('/')[0]; + } + if (!partId) { + finalArgs.push(file); + continue; + } + try { + const data = await Database.getPartFromId(partId); + if (typeof (data.file) !== 'undefined' && data.file.length) + file = data.file; + } catch (e) { + file = parsedArgs[i]; + } + finalArgs.push(file); + continue + } + // Ignore parameter finalArgs.push(e); };