From 48519a3e41f5f95444cc5775ba140cc334856be3 Mon Sep 17 00:00:00 2001 From: Maxime Baconnais Date: Mon, 8 Jul 2019 21:28:41 +0200 Subject: [PATCH] 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); };