Skip to content

Commit

Permalink
Merge pull request #18 from UnicornTranscoder/dev
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
Maxou44 authored Jul 8, 2019
2 parents c289268 + 48519a3 commit 35a5930
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
36 changes: 31 additions & 5 deletions src/core/sessions.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -22,15 +22,15 @@ let ffmpegCache = {};
let urls = {};

SessionsManager.chooseServer = async (session, ip = false) => {
if (urls[session])
if (session && urls[session])
return (urls[session]);
let url = '';
try {
url = await ServersManager.chooseServer(session, ip);
}
catch (err) { }
D('SERVER ' + session + ' [' + url + ']');
if (url.length)
if (session && url.length)
urls[session] = url;
return (url);
};
Expand Down Expand Up @@ -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_RESOURCES}'));
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
Expand Down Expand Up @@ -128,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);
};
Expand Down
4 changes: 0 additions & 4 deletions src/routes/transcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 8 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ export const mdir = (path) => (new Promise((resolve, reject) => {
return reject(err);
return resolve(path);
})
}));
}));

export const replaceAll = (input, search, replace) => {
let str = input;
while (str.indexOf(search) !== -1)
str = str.replace(search, replace);
return str
};

0 comments on commit 35a5930

Please sign in to comment.