Add ordered chapter detection, better inclusion of external subs when another subtitle exists on file

This commit is contained in:
DataHoarder 2021-11-21 16:26:00 +01:00
parent cab5aec529
commit 4cb70e0604

View file

@ -1,7 +1,7 @@
// ==UserScript==
// @name AnimeBytes Mediainfo Improvements
// @author WeebDataHoarder
// @version 1.5.0
// @version 1.6.0
// @downloadURL https://git.gammaspectra.live/WeebDataHoarder/userscripts/raw/branch/master/AnimeBytes/ab-mediainfo.user.js
// @updateURL https://git.gammaspectra.live/WeebDataHoarder/userscripts/raw/branch/master/AnimeBytes/ab-mediainfo.user.js
// @description AnimeBytes Mediainfo Improvements. Adds several listing and matching releases against mediainfo utilities. MIT license
@ -725,6 +725,10 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
tags.videoEncoder = "x265";
}else if(video.writing_library.match(/x264/) !== null){
tags.videoEncoder = "x264";
let versionMatch = video.writing_library.match(/ r(?<version>[0-9]+) /)
if(versionMatch !== null){
tags.videoEncoderVersion = parseInt(versionMatch.groups.version);
}
}else if(video.writing_library.match(/_nvenc/) !== null){
tags.videoEncoder = "NVENC";
warnings.video.push(["danger", "Found NVENC hardware-encoded stream"]);
@ -899,26 +903,29 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
let text = englishSubs !== null ? englishSubs : (defaultSubs !== null ? defaultSubs : (("text" in mediainfo && mediainfo.text.length > 0) ? mediainfo.text[0] : null));
let isTrackExternal = false;
let externalTrackFormat = null;
torrent.filelist.every((file) => {
const ext = file.path.split(".").slice(-1)[0].toUpperCase();
if(ext === "ASS" || ext === "SRT" || ext === "SSA" || ext === "MKS" || ext === "VTT" || ext === "SUB"){
isTrackExternal = true;
externalTrackFormat = ext;
}
return !isTrackExternal;
});
if(text !== null){
tags.subtitleCodec = text.format;
tags.subtitleTitle = "title" in text;
tags.subtitleTitle = "title" in text ? text.title : "";
if(tags.subtitleType === "Softsubs" && englishSubs === null){
if(isTrackExternal === false && torrent.tags.subtitleType === "Softsubs" && englishSubs === null){
warnings.text.push(["warning", "Could not find English labeled subtitles, but labeled Softsubs"]);
}else{
tags.subtitleType = "Softsubs";
}
}else{
let isTrackExternal = false;
let externalTrackFormat = null;
torrent.filelist.every((file) => {
const ext = file.path.split(".").slice(-1)[0].toUpperCase();
if(ext === "ASS" || ext === "SRT" || ext === "SSA" || ext === "MKS" || ext === "VTT" || ext === "SUB"){
isTrackExternal = true;
externalTrackFormat = ext;
}
return !isTrackExternal;
});
}
if(tags.subtitleType === "Softsubs" && (text === null || englishSubs === null)){
if(isTrackExternal){
tags.subtitleType = "Softsubs";
tags.subtitleCodec = "External " + externalTrackFormat;
@ -928,6 +935,30 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
}
}
if("menu" in mediainfo){
//Check for ordered chapters
for(const [key, value] of Object.entries(mediainfo.menu)){
let entryCount = 0;
value.split(" / ").forEach((i) => {
i = i.trim();
if(i.indexOf(":") !== -1){
entryCount++;
}
});
if(entryCount > 1){
tags.orderedChapters = true;
warnings.general.push(["danger", "Found Ordered Chapters"]);
}
}
}
for(const [key, value] of Object.entries(torrent.tags)){
if(!(key in tags)){
@ -939,6 +970,11 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
torrent.tags.aspectRatio = tags.aspectRatio;
}
let oldTagLine = getComparisonLine(torrent.tags);
let newTagLine = getComparisonLine(tags);