Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix db validation movie #11

Merged
merged 8 commits into from
Mar 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SERVER_PORT=3000
SERVER_HOST=http://localhost
SERVER_SUB_FOLDER=
NEXT_PUBLIC_SERVER_URL=$SERVER_HOST:$SERVER_PORT$SERVER_SUB_FOLDER
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
9 changes: 4 additions & 5 deletions MovieServer/movieserver/lib/ffmpeg-presets/1080P.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
exports.load = function(ffmpeg) {
ffmpeg
//.withVideoCodec('h264_nvenc')
.withVideoBitrate(8000)
.withAudioCodec('libmp3lame')
.withVideoCodec('h264_nvenc')
.withVideoCodec('libx264')
.withVideoBitrate(6000)
.withAudioCodec('aac')
.inputOption([
'-re'
])
Expand All @@ -23,4 +22,4 @@ exports.load = function(ffmpeg) {
'-max_muxing_queue_size 9999'
])
.outputFormat('mp4')
};
};
31 changes: 27 additions & 4 deletions MovieServer/movieserver/lib/ffmpeg-presets/720P.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
exports.load = function(ffmpeg) {
ffmpeg
.withVideoCodec('h264_nvenc')
ffmpeg
.withVideoCodec('libx264')
.withVideoBitrate(4000)
.withAudioCodec('libmp3lame')
.inputOption([
'-re'
])
.outputOption([
/* .outputOption([
'-g 52',
'-map 0',
'-map -v',
Expand All @@ -20,6 +20,29 @@ exports.load = function(ffmpeg) {
'-vf scale=-1:720',
'-movflags frag_keyframe+empty_moov+faststart',
'-pix_fmt yuv420p'
])*/
.outputOption([
/*
'-movflags frag_keyframe+empty_moov+faststart',
'-pix_fmt yuv420p',
'-preset ultrafast',
'-deadline realtime',
'-crf 30'
*/
'-g 52',
'-map 0',
'-map -v',
'-map 0:V',
'-sn',
'-deadline realtime',
'-lag-in-frames 0',
'-static-thresh 0',
'-frame-parallel 1',
'-crf 25',
'-movflags frag_keyframe+empty_moov+faststart',
'-pix_fmt yuv420p',
'-preset ultrafast'

])
.outputFormat('mp4')
};
};
3 changes: 2 additions & 1 deletion MovieServer/movieserver/lib/library/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class Library {
])
.output(outputPath)
.on('start', function(commandLine) {
console.log(commandLine);
})
.on('error', function(err, stdout, stderr) {
console.log('an error happened converting subtitle: ' + err.message);
Expand Down Expand Up @@ -241,4 +242,4 @@ class Library {
}
}

module.exports = Library;
module.exports = Library;
49 changes: 21 additions & 28 deletions MovieServer/movieserver/lib/library/movieLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,27 @@ class MovieLibrary extends Library {
if (result.length === 0) {
console.log(` > Found a new movie (${path} for library: '${this.name}')`);

// Try to convert the subtitles from the movie
//new Promise(async (resolve, reject) => {
// resolve();
//});



// Insert to the movie table (contining the path of the movie)
db.one('INSERT INTO movie (path, library, name) VALUES ($1, $2, $3) RETURNING id', [path, this.id, movieName]).then(async (internal_movie_id) => {
internal_movie_id = internal_movie_id.id;

console.log(` > Trying to convert subtitles, this may take a while...`);
let subtitleConvertionResult = await this.convertSubtitles(movieName, path);
// CURRENTLY DISABLED
//console.log(` > Trying to convert subtitles, this may take a while...`);
//let subtitleConvertionResult = await this.convertSubtitles(movieName, path);

// If the conversion failed (because the file was busy), try again.
while(!subtitleConvertionResult) {
await new Promise(r => setTimeout(r, 2000));
subtitleConvertionResult = await this.convertSubtitles(movieName, path);
}
//while(!subtitleConvertionResult) {
// await new Promise(r => setTimeout(r, 2000));
// subtitleConvertionResult = await this.convertSubtitles(movieName, path);
//}

// Find all the audio streams (languages) for the movie

let audio_streams = await this.findAudioStreams(movieName, path);
console.log(audio_streams);
for (let stream of audio_streams) {
db.none('INSERT INTO movie_language (movie_id, language, stream_index) VALUES ($1, $2, $3)', [internal_movie_id, stream.language, stream.stream]);
if (audio_streams) {
for (let stream of audio_streams) {
db.none('INSERT INTO movie_language (movie_id, language, stream_index) VALUES ($1, $2, $3)', [internal_movie_id, stream.language, stream.stream]);
}
}

db.one('SELECT id FROM movie WHERE path = $1 AND library = $2', [path, this.id]).then(result => {
Expand Down Expand Up @@ -148,17 +144,14 @@ class MovieLibrary extends Library {
return;
}
let t = this;
lock.acquire("abcdefg", async function(done) {

if (type === 'MOVIE') {
await t.addMovieIfNotSaved(movieName, path);
} else if (type === 'SUBTITLE') {
t.addSubtitleIfNotSaved(movieName, path, parentFolder);
}
done();
}, function() {

});
lock.enter(async function (token) {
if (type === 'MOVIE') {
await t.addMovieIfNotSaved(movieName, path);
} else if (type === 'SUBTITLE') {
t.addSubtitleIfNotSaved(movieName, path, parentFolder);
}
lock.leave(token);
});
}

/**
Expand All @@ -184,4 +177,4 @@ class MovieLibrary extends Library {
}
}

module.exports = MovieLibrary;
module.exports = MovieLibrary;
25 changes: 12 additions & 13 deletions MovieServer/movieserver/lib/library/tvLibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,20 @@ class TvLibrary extends Library {
let internal_episode_id = await t.one('INSERT INTO serie_episode (season_number, serie_id, episode, path) VALUES ($1, (SELECT id FROM serie WHERE name = $2 AND path = $3), $4, $5) RETURNING id', [seasonNumber, serieName, showPath, episodeNumber, episodePath]);
internal_episode_id = internal_episode_id.id;

console.log(` > Trying to convert subtitles, this may take a while...`);
// CURENTLY DISABLED
//console.log(` > Trying to convert subtitles, this may take a while...`);
// Try to convert the subtitles from the movie
let subtitleConvertionResult = await this.convertSubtitles(serieName, episodePath, episodeNumber, seasonNumber);
//let subtitleConvertionResult = await this.convertSubtitles(serieName, episodePath, episodeNumber, seasonNumber);

// If the conversion failed (because the file was busy), try again.
while(!subtitleConvertionResult) {
subtitleConvertionResult = await this.convertSubtitles(serieName, episodePath, episodeNumber, seasonNumber);
}
//while(!subtitleConvertionResult) {
// subtitleConvertionResult = await this.convertSubtitles(serieName, episodePath, episodeNumber, seasonNumber);
//}

let audio_streams = await this.findAudioStreams(serieName, episodePath);
console.log(audio_streams);
for (let stream of audio_streams) {
db.none('INSERT INTO serie_episode_language (serie_episode_id, language, stream_index) VALUES ($1, $2, $3)', [internal_episode_id, stream.language, stream.stream]);
t.none('INSERT INTO serie_episode_language (serie_episode_id, language, stream_index) VALUES ($1, $2, $3)', [internal_episode_id, stream.language, stream.stream]);
}

// Get the internal serie id for the episode
Expand Down Expand Up @@ -339,7 +340,7 @@ class TvLibrary extends Library {
async removeEntry(path) {
return new Promise(async (resolve, reject) => {
let t = this;
lock.acquire(this.id, async function(done) {
lock.enter(async function (token) {
// Remove the subtitle if that is what we are removing
db.any('SELECT * FROM serie_episode_subtitle WHERE path = $1 AND library_id = $2', [path, t.id])
.then(result => {
Expand Down Expand Up @@ -378,21 +379,19 @@ class TvLibrary extends Library {
await db.none('DELETE FROM serie WHERE id = $1', [episodeInformation[0].serie_id]);
await db.none('DELETE FROM serie_metadata WHERE serie_id = $1', [episodeInformation[0].serie_id]);
}
done();
lock.leave(token);
});
} else {
done();
lock.leave(token);
}
});
} else {
done();
lock.leave(token);
}
});
}, function() {
resolve();
});
});
}
}

module.exports = TvLibrary;
module.exports = TvLibrary;
4 changes: 2 additions & 2 deletions MovieServer/movieserver/lib/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Watcher {
await library.newEntry(filePath);
//console.log("mer efter")
} else {
//library.newEntry(filePath);
library.newEntry(filePath);
}
})
.on('unlink', (filePath) => {
Expand Down Expand Up @@ -175,4 +175,4 @@ class Watcher {
}
}

module.exports = Watcher;
module.exports = Watcher;
Loading