Added torrent highlighter compatibility layer
This commit is contained in:
parent
cca5d411a8
commit
be4450fff6
|
@ -1,7 +1,7 @@
|
|||
// ==UserScript==
|
||||
// @name AnimeBytes Mediainfo Improvements
|
||||
// @author WeebDataHoarder
|
||||
// @version 1.26.4
|
||||
// @version 1.27.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
|
||||
|
@ -15,7 +15,7 @@
|
|||
// @grant GM_setValue
|
||||
// @grant GM_getValue
|
||||
// @require deps/compat.js?1
|
||||
// @require deps/resources.js?1
|
||||
// @require deps/resources.js?2
|
||||
// @require deps/settings.js?1
|
||||
// @require deps/mediainfo.js?10
|
||||
// @require deps/ab-class.js?1
|
||||
|
@ -48,6 +48,27 @@ function getComparisonLine(tags, legacy = true){
|
|||
return entries.join(" | ");
|
||||
}
|
||||
|
||||
function wrap(...e) {
|
||||
let span = document.createElement("span");
|
||||
e.forEach((i) => {
|
||||
span.append(i);
|
||||
})
|
||||
return span;
|
||||
}
|
||||
|
||||
function wrapStyleClass(e, classType) {
|
||||
let span = document.createElement("span");
|
||||
if(settings.getSetting("script_evaHighlightEmulation") || settings.getSetting("script_abHighlights2Emulation")){
|
||||
span.setAttribute("data-" + classType, typeof e === 'string' ? e : e.textContent);
|
||||
}
|
||||
if(settings.getSetting("script_abHighlights2Emulation")){
|
||||
span.classList.add("userscript-highlight", "torrent-field");
|
||||
span.setAttribute("data-field", typeof e === 'string' ? e : e.textContent);
|
||||
}
|
||||
span.append(e);
|
||||
return span;
|
||||
}
|
||||
|
||||
function getEntryLine(tags, messages){
|
||||
// Source + container + remux | Codec / Resolution / HDR | Audio + Dual + commentary | Text | OtherTags | icons
|
||||
let entries = {
|
||||
|
@ -59,8 +80,14 @@ function getEntryLine(tags, messages){
|
|||
icons: []
|
||||
};
|
||||
|
||||
entries.source.push(getLineTagEntry(tags.source, false) + ("sourceName" in tags ? " (" + tags.sourceName + ")" : ""));
|
||||
entries.source.push(getLineTagEntry(tags.container, false) + ("region" in tags ? " (" + tags.region + ")" : ""));
|
||||
entries.source.push(wrap(
|
||||
wrapStyleClass(getLineTagEntry(tags.source, false), "media"),
|
||||
("sourceName" in tags ? wrap(" (", wrapStyleClass(tags.sourceName, "source"), ")") : "")
|
||||
));
|
||||
entries.source.push(wrap(
|
||||
wrapStyleClass(getLineTagEntry(tags.container, false), "container"),
|
||||
("region" in tags ? wrap(" (", wrapStyleClass(tags.region, "region"), ")") : "")
|
||||
));
|
||||
|
||||
if("videoCodec" in tags){
|
||||
let span = document.createElement("span");
|
||||
|
@ -70,19 +97,29 @@ function getEntryLine(tags, messages){
|
|||
let codec = document.createElement("span");
|
||||
codec.classList.add("entry_codec");
|
||||
codec.textContent = getLineTagEntry(tags.videoCodec, false);
|
||||
span.append(codec);
|
||||
span.append(wrapStyleClass(codec, "codec"));
|
||||
if("videoEncoder" in tags && settings.getSetting("showEncodingDetails")){
|
||||
span.append(" (" + tags.videoEncoder + ("videoEncodeMode" in tags ? " " + tags.videoEncodeMode : "") + ("videoEncodeRateControl" in tags ? " " + tags.videoEncodeRateControl : "") + ")");
|
||||
span.append(wrap(
|
||||
" (",
|
||||
wrapStyleClass(tags.videoEncoder, "encoder"),
|
||||
("videoEncodeMode" in tags ? wrap(" ", wrapStyleClass(tags.videoEncodeMode, "encode-mode")) : ""),
|
||||
("videoEncodeRateControl" in tags ? wrap(" ",wrapStyleClass(tags.videoEncodeRateControl, "encode-rc")) : ""),
|
||||
")"
|
||||
));
|
||||
}
|
||||
entries.video.push(span);
|
||||
}
|
||||
|
||||
entries.video.push(getLineTagEntry(tags.resolution, false) + ("aspectRatio" in tags ? " " + tags.aspectRatio : "") /* + ("videoFrameRate" in tags ? " @ " + tags.videoFrameRate : "")*/);
|
||||
entries.video.push(wrap(
|
||||
wrapStyleClass(getLineTagEntry(tags.resolution, false), "resolution"),
|
||||
("aspectRatio" in tags ? wrap(" ", wrapStyleClass(tags.aspectRatio, "aspect-ratio")) : "")
|
||||
/* ("videoFrameRate" in tags ? " @ " + tags.videoFrameRate : "")*/
|
||||
));
|
||||
if("videoHDR" in tags){
|
||||
entries.video.push(getLineTagEntry(tags.videoHDR, false));
|
||||
entries.video.push(wrapStyleClass(getLineTagEntry(tags.videoHDR, false), "hdr"));
|
||||
}
|
||||
if(tags.videoCount > 1){
|
||||
entries.video.push(tags.videoCount === 2 ? "Dual" : "Multi (" + tags.videoCount + ")");
|
||||
entries.video.push(wrapStyleClass(tags.videoCount === 2 ? "Dual" : "Multi (" + tags.videoCount + ")", "dual-video"));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -93,35 +130,35 @@ function getEntryLine(tags, messages){
|
|||
let codec = document.createElement("span");
|
||||
codec.classList.add("entry_codec");
|
||||
codec.textContent = getLineTagEntry(tags.audioCodec, false);
|
||||
span.append(codec);
|
||||
span.append(wrapStyleClass(codec, "audio-codec"));
|
||||
if(settings.getSetting("showAudioDetails") && "audioBitrate" in tags){
|
||||
span.append(" " + tags.audioBitrate);
|
||||
span.append(" ", wrapStyleClass(tags.audioBitrate, "audio-bitrate"));
|
||||
}
|
||||
span.append(" " + Mediainfo.getAudioChannels(tags.audioChannels));
|
||||
span.append(" ", wrapStyleClass(Mediainfo.getAudioChannels(tags.audioChannels), "audio-channels"));
|
||||
entries.audio.push(span);
|
||||
}
|
||||
|
||||
if(tags.audioCount > 1){
|
||||
if((!("audioLanguages" in tags) || "English" in tags.audioLanguages)){
|
||||
entries.audio.push(tags.audioCount === 2 ? "Dual" : "Dual Multi (" + ("audioLanguages" in tags ? Object.keys(tags.audioLanguages).length + "x" : "") + tags.audioCount + ")");
|
||||
entries.audio.push(wrapStyleClass(tags.audioCount === 2 ? "Dual" : "Dual Multi (" + ("audioLanguages" in tags ? Object.keys(tags.audioLanguages).length + "x" : "") + tags.audioCount + ")", "dual-audio"));
|
||||
}else{
|
||||
entries.audio.push("Multi (" + ("audioLanguages" in tags ? Object.keys(tags.audioLanguages).length + "x" : "") + tags.audioCount + ")");
|
||||
entries.audio.push(wrapStyleClass("Multi (" + ("audioLanguages" in tags ? Object.keys(tags.audioLanguages).length + "x" : "") + tags.audioCount + ")", "dual-audio"));
|
||||
}
|
||||
}
|
||||
|
||||
if("audioCommentary" in tags && tags.audioCommentary){
|
||||
entries.audio.push("Commentary");
|
||||
entries.audio.push(wrapStyleClass("Commentary", "audio-commentary"));
|
||||
}
|
||||
|
||||
if("remux" in tags){
|
||||
if(tags.remux === true){
|
||||
entries.source.push("REMUX");
|
||||
entries.source.push(wrapStyleClass("REMUX", "remux"));
|
||||
}else if(tags.remux === "probably"){
|
||||
entries.source.push("REMUX*");
|
||||
entries.source.push(wrapStyleClass("REMUX*", "remux"));
|
||||
}
|
||||
}
|
||||
|
||||
entries.text.push(("subtitleCodec" in tags ? tags.subtitleCodec + " " : "") + ("subtitleType" in tags ? getLineTagEntry(tags.subtitleType, false) : "RAW") + ("group" in tags ? " (" + tags.group + ")" : ""));
|
||||
entries.text.push(wrapStyleClass(("subtitleCodec" in tags ? tags.subtitleCodec + " " : ""), "subbing-codec"), wrapStyleClass(("subtitleType" in tags ? getLineTagEntry(tags.subtitleType, false) : "RAW"), "subbing"), wrapStyleClass(("group" in tags ? " (" + tags.group + ")" : ""), "group"));
|
||||
|
||||
if(tags.remastered){
|
||||
entries.other.push(createImage("remastered"));
|
||||
|
@ -134,7 +171,7 @@ function getEntryLine(tags, messages){
|
|||
}
|
||||
|
||||
if(tags.freeleech){
|
||||
entries.other.push(createImage("freeleech"));
|
||||
entries.other.push(wrapStyleClass(createImage("freeleech"), "freeleech"));
|
||||
}
|
||||
|
||||
if("chapters" in tags){
|
||||
|
@ -295,7 +332,7 @@ function extractTagsFromFilename(fileName, sourceTags, source = ""){
|
|||
function extractFromMediainfo(tags, mediainfo, warnings, fileName, fileList, sourceTags, isLiveActionType = false){
|
||||
|
||||
tags.openFormat = false;
|
||||
|
||||
|
||||
let japaneseAudio = null;
|
||||
let otherAudio = null;
|
||||
let defaultAudio = null;
|
||||
|
@ -982,7 +1019,7 @@ function extractFromMediainfo(tags, mediainfo, warnings, fileName, fileList, sou
|
|||
console.log(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return tags;
|
||||
}
|
||||
|
||||
|
@ -1409,8 +1446,10 @@ settings.addSetting("showEncodingDetails", "Show Encoding Details", "Display enc
|
|||
settings.addSetting("showAudioDetails", "Show Audio Details", "Display extra audio details such as bit-depth, bitrate.", "bool", false);
|
||||
settings.addSetting("handleAnamorphicVideo", "Handle Anamorphic Video", "Use Display Aspect Ratio information to calculate display resolution.", "bool", true);
|
||||
settings.addSetting("regexpFilter", "RegExp Filter", "Any entry that matches one of these RegExp (without delimiters) will be filtered out. Can enter a different one per line. Empty to disable", "text", "");
|
||||
settings.addSetting("extraStyles", "CSS Styles", "Extra CSS styles to add to Torrent pages. Empty to disable. One group entry per line.", "text", "");
|
||||
settings.addSetting("extraStyles", "CSS Styles", "Extra CSS styles to add to Torrent pages. Empty to disable.", "text", "");
|
||||
settings.addSetting("script_deliciousCompatMode", "Enable Delicious Compatibility", "Enable workarounds to make output compatible with AnimeBytes Delicious user scripts Bundle", "bool", true);
|
||||
settings.addSetting("script_evaHighlightEmulation", "Enable Eva's torrent highlighter emulation", "Create classes and data tags similar to Eva's torrent highlighter, without breaking this script functions.", "bool", true);
|
||||
settings.addSetting("script_abHighlights2Emulation", "Enable AB Highlights 2 emulation", "Create classes and data tags similar to AB Highlights 2, without breaking this script functions.", "bool", true);
|
||||
|
||||
|
||||
settings.addSetting("warning_mediainfoSource", "General: Mediainfo Source", "Alert when Mediainfo was found on Description and not on Mediainfo tab.", "bool", true);
|
||||
|
@ -1677,12 +1716,7 @@ if(
|
|||
GM_addStyle("div.torrent_filter_box { width: fit-content !important; float: none !important; min-width: calc(950px - 240px); }");
|
||||
}
|
||||
|
||||
settings.getSetting("extraStyles").split("\n").forEach((l) => {
|
||||
l = l.trim();
|
||||
if(l !== ""){
|
||||
GM_addStyle(l);
|
||||
}
|
||||
});
|
||||
GM_addStyle(settings.getSetting("extraStyles"));
|
||||
|
||||
const torrentTableElement = document.querySelector("div#content table.torrent_table");
|
||||
|
||||
|
@ -1703,10 +1737,10 @@ if(
|
|||
torrentListing.forEach((torrent) => {
|
||||
try {
|
||||
let tags = {
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
let warnings = {
|
||||
general: [],
|
||||
audio: [],
|
||||
|
@ -1766,7 +1800,7 @@ if(
|
|||
}
|
||||
|
||||
extractFromMediainfo(tags, mediainfo, warnings, fileName, torrent.filelist, torrent.tags, isLiveActionType);
|
||||
|
||||
|
||||
}else{
|
||||
torrent.elements.item.style["font-style"] = "italic";
|
||||
if(settings.getSetting("warning_mediainfoInvalid")){
|
||||
|
@ -1889,6 +1923,7 @@ if(
|
|||
if(tags.snatched){
|
||||
a.classList.add("snatched-torrent");
|
||||
}
|
||||
|
||||
a.setAttribute("href", torrent.elements.entry.href);
|
||||
|
||||
a.addEventListener("click", (e) => e.preventDefault());
|
||||
|
@ -1901,6 +1936,26 @@ if(
|
|||
a.append(e);
|
||||
});
|
||||
|
||||
if(settings.getSetting("script_evaHighlightEmulation")){
|
||||
a.classList.add("userscript-highlight");
|
||||
}
|
||||
|
||||
if(settings.getSetting("script_abHighlights2Emulation")){
|
||||
a.classList.add("userscript-highlight", "torrent-page");
|
||||
|
||||
a.querySelectorAll("span.userscript-highlight").forEach((e) => {
|
||||
let fields = [];
|
||||
e.getAttributeNames().forEach((name) => {
|
||||
if(name.match(/^data-/) !== null){
|
||||
let attr = e.getAttribute(name);
|
||||
a.setAttribute(name, e.getAttribute(name));
|
||||
fields.push(attr);
|
||||
}
|
||||
});
|
||||
a.setAttribute("data-fields", fields.join(" "))
|
||||
});
|
||||
}
|
||||
|
||||
td.append(a);
|
||||
|
||||
lastTd.insertAdjacentElement("afterend", td)
|
||||
|
|
Loading…
Reference in a new issue