version 1.2

* Added aspect ratio listing
* Audio commentary track detection
* Put back FL/remastered tags if any
* Detect DTS-HD MA from old mediainfo
* Add PCM / high bitDepth bloat warnings
* Better 720p/1080p detection
* Detect external subtitles
This commit is contained in:
DataHoarder 2021-11-21 14:15:27 +01:00
parent f0a34dcdb4
commit dd1889cc8b

View file

@ -1,7 +1,7 @@
// ==UserScript==
// @name AnimeBytes Mediainfo Improvements
// @author WeebDataHoarder
// @version 1.1
// @version 1.2
// @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
@ -113,16 +113,38 @@ function getEntryLine(tags){
if("videoHDR" in tags){
entries.push(getLineTagEntry(tags.videoHDR, false));
}
entries.push(tags.resolution);
entries.push(tags.resolution + ("aspectRatio" in tags ? " " + tags.aspectRatio : "") /* + ("videoFrameRate" in tags ? " @ " + tags.videoFrameRate : "")*/);
entries.push(getLineTagEntry(tags.audioCodec, false) + " " + getAudioChannels(tags.audioChannels));
if(tags.audioCount > 1){
entries.push("Dual Audio");
}
if("audioCommentary" in tags && tags.audioCommentary){
entries.push("Commentary");
}
if(tags.remastered){
let img = document.createElement("img");
img.src = "/static/common/rmstr.png";
img.alt = "Remastered";
img.title = "This torrent is from a remastered source!";
entries.push(img);
}
entries.push(("subtitleCodec" in tags ? tags.subtitleCodec + " " : "") + ("subtitleType" in tags ? getLineTagEntry(tags.subtitleType, false) : "RAW") + ("group" in tags ? " (" + tags.group + ")" : ""));
return entries.join(" | ");
if(tags.freeleech){
let img = document.createElement("img");
img.src = "/static/common/flicon.png";
img.alt = "Freeleech!";
img.title = "This torrent is freeleech. Remember to seed!";
entries.push(img);
}
return entries;
}
const allowedVideoTypes = [
@ -230,6 +252,7 @@ const audioCodecs = [
legacy: "TrueHD",
lossless: true
},
{
name: "DTS:X MA",
match: {
@ -249,6 +272,16 @@ const audioCodecs = [
},
legacy: "DTS-HD MA",
lossless: true
},
{ //Old way of identifying
name: "DTS-HD MA",
match: {
codec_id: "A_DTS",
format_profile: "MA / Core",
channels_original: null,
},
legacy: "DTS-HD MA",
lossless: true
}
];
@ -396,7 +429,8 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
let tags = {
audioCount: 1,
freeleech: torrentEntry.querySelector("img") !== null,
freeleech: torrentEntry.querySelector("img[alt^='Freeleech!']") !== null,
remastered: torrentEntry.querySelector("img[alt^='Remastered']") !== null,
snatched: torrentEntry.textContent.match(/ - Snatched/) !== null
};
torrentEntry.textContent.replace("»", "").replace(" - Snatched", "").split(" | ").forEach((t) => {
@ -564,14 +598,17 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
}
});
mediainfo.audio.forEach((audio) => {
mediainfo.audio.forEach((audio, index) => {
const isDefault = audio.default === "Yes";
if(isDefault){
defaultAudio = audio;
}
if("language" in audio && audio.language !== "Japanese" && audio.language !== "Unknown" && isDefault && torrentType.match(/Live Action/) === null){
warnings.audio.push(["info", "Default audio is not in Japanese"]);
warnings.audio.push(["info", "Default audio #"+(index+1)+" is not in Japanese"]);
}
if("title" in audio && audio.title.match(/comment/i) !== null){
tags.audioCommentary = true;
}
@ -585,8 +622,10 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
japaneseAudio = audio;
}
}
}else if(mediainfo.audio.length === 1 && (audio.language === "Unknown" || !("language" in audio))){
japaneseAudio = audio;
}else if(audio.language === "Unknown" || !("language" in audio)){
if(mediainfo.audio.length === 1){
japaneseAudio = audio;
}
}else{
if(otherAudio === null){ // Pick first
otherAudio = audio;
@ -598,6 +637,17 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
}
}
}
if(audio.format === "PCM"){
warnings.audio.push(["warning", "BLOAT: Audio track #"+(index+1)+" is uncompressed PCM."]);
}
if(audio.format === "FLAC" || audio.format.match(/^DTS/) !== null){
let bitDepth = parseInt(audio.bit_depth.replace(/[^0-9]/g, ""));
if(bitDepth > 16){
warnings.audio.push(["warning", "BLOAT: Audio track #"+(index+1)+" is "+audio.format+" with bit depth greater than 16-bit, found "+bitDepth+"-bit."]);
}
}
});
if(japaneseAudio !== otherAudio && otherAudio !== null && japaneseAudio !== null){
@ -640,22 +690,18 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
if(value === null){
if(key in audio){
match = false;
console.log("audio[" + key + "] exists but value was null");
break;
}
continue;
}
if(!(key in audio)){
match = false;
console.log("audio[" + key + "] does not exist but value was not null");
break;
}else if (value instanceof RegExp && audio[key].match(value) === null){
match = false;
console.log("audio[" + key + "] ("+ audio[key] +") ~= " + value.toString());
break;
}else if (!(value instanceof RegExp) && audio[key] !== value){
match = false;
console.log("audio[" + key + "] ("+ audio[key] +") !== " + value);
break;
}
}
@ -700,19 +746,29 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
return !match;
});
if("frame_rate" in video){
tags.videoFrameRate = video.frame_rate.split(" ")[0];
}else
if("original_frame_rate" in video){
tags.videoFrameRate = video.original_frame_rate.split(" ")[0];
}
let width = parseInt(video.width.replace(/[^0-9]/g, ""));
let height = parseInt(video.height.replace(/[^0-9]/g, ""));
if(width === 1280 && height > 480 && height <= 720){
if(((width <= 1280 && width >= 1200) || (width <= 960 && width >= 900)) && height > 480 && height <= 720){
tags.resolution = "720" + ((!("scan_type" in video) || video.scan_type === "Progressive") ? "p" : "i");
}else if(width === 1920 && height > 720 && height <= 1080){
}else if(((width <= 1920 && width >= 1820) || (width <= 1440 && width >= 1340)) && height > 720 && height <= 1080){
tags.resolution = "1080" + ((!("scan_type" in video) || video.scan_type === "Progressive") ? "p" : "i");
}else if(width === 3840 && height > 1080 && height <= 2160){
}else if((width <= 3840 && width >= 3640) && height > 1080 && height <= 2160){
tags.resolution = "4K";
}else{
tags.resolution = width + "x" + height;
}
tags.aspectRatio = video.display_aspect_ratio;
if("color_primaries" in video && video.color_primaries === "BT.2020"){
tags.videoHDR = "HDR";
}
@ -781,6 +837,24 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
tags.subtitleCodec = text.format;
tags.subtitleTitle = "title" in text;
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"){
isTrackExternal = true;
externalTrackFormat = ext;
}
return !isTrackExternal;
});
if(isTrackExternal){
tags.subtitleType = "Softsubs";
tags.subtitleCodec = "External " + externalTrackFormat;
warnings.text.push(["info", "Subtitle track is external"]);
}else if("subtitleType" in torrent.tags && torrent.tags.subtitleType !== "Hardsubs"){
warnings.text.push(["warning", "Could not find subtitles either on file listing or disk, probably hardsubbed?"]);
}
}
@ -790,6 +864,10 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
}
}
if(!("aspectRatio" in torrent.tags)){
torrent.tags.aspectRatio = tags.aspectRatio;
}
let oldTagLine = getComparisonLine(torrent.tags);
let newTagLine = getComparisonLine(tags);
@ -797,59 +875,89 @@ if(allowedVideoTypes.indexOf(torrentType.replace("Live Action ", "")) !== -1){
warnings.general.push(["danger", "Tag mismatch:\nold: " + oldTagLine + " !=\nnew: " + newTagLine]);
}
if(tags.freeleech){
let fl = torrent.elements.entry.querySelector("img");
torrent.elements.entry.textContent = getEntryLine(tags) + " | ";
torrent.elements.entry.append(fl);
}else{
torrent.elements.entry.textContent = getEntryLine(tags);
while(torrent.elements.entry.firstChild){
torrent.elements.entry.firstChild.remove();
}
getEntryLine(tags).forEach((e) => {
if(torrent.elements.entry.firstChild){
torrent.elements.entry.append(" | ");
}
torrent.elements.entry.append(e);
});
if(tags.snatched){
torrent.elements.entry.append(" - Snatched");
}
let warningText = "";
let infoCount = 0;
let warningCount = 0;
let dangerCount = 0;
let messages = document.createElement("div");
messages.append(document.createElement("br"));
let h2 = document.createElement("h2");
h2.textContent = "Warning Messages";
messages.append(h2);
for(const [key, value] of Object.entries(warnings)){
if(value.length > 0){
warningText += key.toUpperCase() + ":\n";
let h3 = document.createElement("h3");
h3.textContent = key.toUpperCase();
messages.append(h3);
let messageList = document.createElement("ul");
for(let v of value){
let li = document.createElement("li");
li.style.float = "inherit";
let value = "";
if(Array.isArray(v)){
switch (v[0]){
case "info":
infoCount++;
warningText += " info: " + v[1] + "\n";
value = "info: " + v[1];
break;
case "warning":
warningCount++;
warningText += " warning: " + v[1] + "\n";
value = "warning: " + v[1];
break;
case "danger":
dangerCount++;
warningText += " danger: " + v[1] + "\n";
value = "danger: " + v[1];
break;
}
}else{
warningText += " " + v + "\n";
++warningCount;
value = v;
}
if(value.includes("\n")){
let pre = document.createElement("pre");
pre.textContent = value;
li.append(pre);
}else{
li.textContent = value;
}
messageList.append(li);
}
warningText += "\n";
messages.append(messageList);
messages.append(document.createElement("br"));
}
}
messages.append(document.createElement("hr"));
if(warningText !== ""){
if(infoCount > 0 || warningCount > 0 || dangerCount > 0){
torrent.elements.item.style["font-style"] = "italic";
let pre = document.createElement("pre");
pre.textContent = "== WARNINGS ==\n\n" + warningText + "\n";
if("description" in torrent.elements){
torrent.elements.description.prepend(pre);
torrent.elements.description.prepend(messages);
}
torrent.elements.entry.prepend(" - ");