diff --git a/Find Unique Titles/config/webpack.config.ts b/Find Unique Titles/config/webpack.config.ts index 13467d1..d5368bb 100644 --- a/Find Unique Titles/config/webpack.config.ts +++ b/Find Unique Titles/config/webpack.config.ts @@ -2,7 +2,6 @@ import { UserScriptConfig } from "./userscript.config"; import CopyWebpackPlugin from "copy-webpack-plugin"; import path from "path"; import TerserPlugin from "terser-webpack-plugin"; -import url from "url"; import * as webpack from "webpack"; import "webpack-dev-server"; import WebpackUserscript from "webpack-userscript"; diff --git a/Find Unique Titles/dist/find.unique.titles.user.js b/Find Unique Titles/dist/find.unique.titles.user.js index 13acc53..2f002b8 100644 --- a/Find Unique Titles/dist/find.unique.titles.user.js +++ b/Find Unique Titles/dist/find.unique.titles.user.js @@ -341,12 +341,11 @@ element.querySelectorAll('tr[id^="resulttorrent"]').forEach((torrentElement => { const data = torrentElement.children[0].textContent.trim().split("/"); const size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseSize)(torrentElement.children[4].textContent.trim()); - const tags = []; - if (torrentElement.textContent.includes("Remux")) tags.push("Remux"); + const tags = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseTags)(torrentElement.textContent); const torrent = { container: data[0].trim(), format: data[1].trim(), - resolution: data[3].trim(), + resolution: (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseResolution)(data[3].trim()), tags, size, dom: torrentElement @@ -566,9 +565,9 @@ const size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseSize)(element.querySelector("td:nth-child(5)")?.textContent); let container; let format; - let resolution = "SD"; + let resolution = _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.SD; const text = element.textContent.toLowerCase(); - if (text.includes("1080p")) resolution = "1080p"; else if (text.includes("720p")) resolution = "720p"; else if (text.includes("dvd-r")) format = "VOB IFO"; + if (text.includes("1080p")) resolution = _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.FHD; else if (text.includes("720p")) resolution = _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.HD; else if (text.includes("dvd-r")) format = "VOB IFO"; return [ { size, tags: [], @@ -867,7 +866,7 @@ container, dom: torrentElement, format: "", - resolution: torrentElement.querySelector("span.TorrentTitle-item.resolution").textContent.trim(), + resolution: (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseResolution)(torrentElement.querySelector("span.TorrentTitle-item.resolution").textContent.trim()), size: (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseSize)(torrentElement.querySelector("td.TableTorrent-cellStatSize").textContent), tags }; @@ -905,8 +904,8 @@ }); var _utils_utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/utils/utils.ts"); var _tracker__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/trackers/tracker.ts"); - var common_http__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../common/dist/http/index.mjs"); var common_dom__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("../common/dist/dom/index.mjs"); + var common_http__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../common/dist/http/index.mjs"); const isExclusive = element => { const exclusiveLink = element.querySelector('a[href="/browse.php?exclusive=1"]'); return null != exclusiveLink; @@ -915,8 +914,7 @@ const size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseSize)(element.querySelector("td:nth-child(6)")?.textContent); const title = element.querySelector(".browse_td_name_cell a").textContent.trim(); const resolution = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseResolution)(title); - const tags = []; - if (element.querySelector("#codec1 .medium5")) tags.push("Remux"); + const tags = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseTags)(title); return { size, tags, @@ -1212,9 +1210,9 @@ const parseTorrent = element => { const torrents = []; const size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseSize)(element.querySelector("td:nth-child(11)")?.textContent?.replace(",", "")); - let resolution = "SD"; + let resolution = _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.SD; let format; - if (element.querySelector('td img[src*="hdrip1080.png"]')) resolution = "1080p"; else if (element.querySelector('td img[src*="hdrip720.png"]')) resolution = "720p"; else if (element.querySelector('td img[src*="dvdr.png"]')) format = "VOB IFO"; else if (element.querySelector('td img[src*="bluray.png"]')) format = "m2ts"; + if (element.querySelector('td img[src*="hdrip1080.png"]')) resolution = _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.FHD; else if (element.querySelector('td img[src*="hdrip720.png"]')) resolution = _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.HD; else if (element.querySelector('td img[src*="dvdr.png"]')) format = "VOB IFO"; else if (element.querySelector('td img[src*="bluray.png"]')) format = "m2ts"; torrents.push({ size, format, @@ -1510,7 +1508,7 @@ }; const hasRequests = element => true === element.querySelector("#no_results_message")?.textContent?.trim().includes("Your search did not match any torrents, however it did match these requests."); const isAllowedTorrent = torrent => { - if ("x265" == torrent.container && "2160p" != torrent.resolution && !isHDR(torrent)) { + if ("x265" == torrent.container && torrent.resolution != _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.UHD && !isHDR(torrent)) { common_logger__WEBPACK_IMPORTED_MODULE_2__.logger.debug("[PTP] Torrent not allowed: non HDR X265 and not 2160p"); return false; } @@ -1619,7 +1617,7 @@ const torrent = { container: data[0].split("]")[1].trim(), format: data[1].trim(), - resolution: data[3].trim(), + resolution: (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseResolution)(data[3].trim()), tags, size, dom: line @@ -1631,18 +1629,9 @@ function sameContainer(first, second) { return first === second || "H.264" === first && "x264" === second || "x264" === first && "H.264" === second || "H.265" === first && "x265" === second || "x265" === first && "H.265" === second || "UHD100" === first && "BD100" === second || "BD100" === first && "UHD100" === second || "UHD66" === first && "BD66" === second || "BD66" === first && "UHD66" === second; } - function isSD(resolution) { - const sdResolutions = [ "SD", "PAL", "NTSC" ]; - if (sdResolutions.indexOf(resolution.toUpperCase())) return true; - let height = resolution.replace("p", ""); - if (resolution.includes("x")) height = resolution.split("x")[1]; - if (parseInt(height) && parseInt(height) < 720) return true; - } function sameResolution(first, second) { if (!first.resolution || !second.resolution) return true; - if (first.resolution === second.resolution) return true; - if ("SD" === first.resolution) return isSD(second.resolution); - if ("SD" === second.resolution) return isSD(first.resolution); + return first.resolution === second.resolution; } const isHDR = torrent => torrent.tags?.includes("HDR") || torrent.tags?.includes("DV"); const searchTorrent = (torrent, availableTorrents) => { @@ -1809,18 +1798,18 @@ function parseTorrent(element) { let infos = element.querySelector(".torrent_info .activity_info").querySelectorAll("div"); let size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseSize)(infos[1].textContent); - let resolution = infos[0].textContent.trim(); + let resolution = infos[0]?.textContent?.trim(); if ("CD" == resolution || "WEB" == resolution) resolution = void 0; let format; if ("DVD-R" === resolution) { - resolution = "SD"; + resolution = _tracker__WEBPACK_IMPORTED_MODULE_1__.Resolution.SD; format = "VOB IFO"; } return { size, tags: [], dom: element, - resolution, + resolution: resolution ? (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseResolution)(resolution) : void 0, format }; } @@ -1892,13 +1881,15 @@ var common_dom__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("../common/dist/dom/index.mjs"); var common_logger__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("../common/dist/logger/index.mjs"); const parseCategory = element => { - const category = element.querySelector(".info a.category").getAttribute("data-ccid"); + let categoryLink = element.querySelector(".info a.category"); + const category = categoryLink.getAttribute("data-ccid"); if ("animation" == category) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.ANIME; if ("tv" == category) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.TV; if ("music" == category) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MUSIC; if ("games" == category) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.GAME; if ("movies" == category) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MOVIE; if ("books" == category) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.BOOK; + if (categoryLink.textContent.trim().includes("TV")) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.TV; }; const parseYearAndTitle = element => { const name = element.querySelector(".name a").childNodes[0].textContent; @@ -2270,24 +2261,32 @@ "./src/trackers/tracker.ts": (__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.d(__webpack_exports__, { Category: () => Category, + Resolution: () => Resolution, SearchResult: () => SearchResult, toGenerator: () => toGenerator }); + let Resolution = function(Resolution) { + Resolution.SD = "SD"; + Resolution.HD = "HD"; + Resolution.FHD = "FHD"; + Resolution.UHD = "UHD"; + return Resolution; + }({}); let Category = function(Category) { - Category[Category.TV = 0] = "TV"; - Category[Category.MOVIE = 1] = "MOVIE"; - Category[Category.MUSIC = 2] = "MUSIC"; - Category[Category.BOOK = 3] = "BOOK"; - Category[Category.AUDIOBOOK = 4] = "AUDIOBOOK"; - Category[Category.SPORT = 5] = "SPORT"; - Category[Category.ANIME = 6] = "ANIME"; - Category[Category.MV = 7] = "MV"; - Category[Category.LIVE_PERFORMANCE = 8] = "LIVE_PERFORMANCE"; - Category[Category.STAND_UP = 9] = "STAND_UP"; - Category[Category.DOCUMENTARY = 10] = "DOCUMENTARY"; - Category[Category.GAME = 11] = "GAME"; - Category[Category.XXX = 12] = "XXX"; - Category[Category.OTHER = 13] = "OTHER"; + Category.TV = "TV"; + Category.MOVIE = "MOVIE"; + Category.MUSIC = "MUSIC"; + Category.BOOK = "BOOK"; + Category.AUDIOBOOK = "AUDIOBOOK"; + Category.SPORT = "SPORT"; + Category.ANIME = "ANIME"; + Category.MV = "MV"; + Category.LIVE_PERFORMANCE = "PERFORMANCE"; + Category.STAND_UP = "UP"; + Category.DOCUMENTARY = "DOCUMENTARY"; + Category.GAME = "GAME"; + Category.XXX = "XXX"; + Category.OTHER = "OTHER"; return Category; }({}); let SearchResult = function(SearchResult) { @@ -2418,6 +2417,7 @@ parseTags: () => parseTags, parseYearAndTitleFromReleaseName: () => parseYearAndTitleFromReleaseName }); + var _trackers_tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/trackers/tracker.ts"); const parseSize = text => { let size = null; text = text.replace("GiB", "GB").replace("MiB", "MB"); @@ -2437,21 +2437,26 @@ }; const parseResolution = text => { const resolutionsAndAliases = { - "720p": [ "720p", "hd" ], - "1080p": [ "1080p", "fhd", "full_hd" ], - "2160p": [ "2160p", "uhd", "4k" ], - SD: [ "sd", "pal", "ntsc" ] + SD: [ "sd", "pal", "ntsc" ], + HD: [ "720p", "hd" ], + FHD: [ "1080p", "fhd", "full_hd" ], + UHD: [ "2160p", "uhd", "4k" ] }; - if (!text) return null; + if (!text) return; for (let resolution in resolutionsAndAliases) { let aliases = resolutionsAndAliases[resolution]; for (let alias of aliases) if (text.includes(alias)) return resolution; - if (text.includes(resolution)) return resolution; } - const regex = /\b(\d{3})x(\d{3})\b/; + const regex = /\b(\d{3,4})x(\d{3,4})\b/; const match = text.match(regex); - if (match) return match[0]; - return null; + if (match) { + const height = parseInt(match[2]); + if (height < 720) return _trackers_tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.SD; + if (height < 1080) return _trackers_tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.HD; + if (height < 2160) return _trackers_tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.FHD; + return _trackers_tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.UHD; + } + return; }; const parseYearAndTitleFromReleaseName = releaseName => { const regex = /^(.+?)\.(\d{4})\./; diff --git a/Find Unique Titles/package.json b/Find Unique Titles/package.json index 7c1b317..0c246a0 100644 --- a/Find Unique Titles/package.json +++ b/Find Unique Titles/package.json @@ -8,7 +8,8 @@ "scripts": { "dev": "webpack server --node-env development --config config/webpack.config.ts", "build": "webpack --node-env production --progress --config config/webpack.config.ts", - "format": "prettier --write --ignore-unknown src" + "format": "prettier --write --ignore-unknown src", + "check-types": "tsc --noEmit" }, "repository": { "type": "git", diff --git a/Find Unique Titles/src/trackers/BHD.ts b/Find Unique Titles/src/trackers/BHD.ts index 2706ceb..f45938f 100644 --- a/Find Unique Titles/src/trackers/BHD.ts +++ b/Find Unique Titles/src/trackers/BHD.ts @@ -1,7 +1,7 @@ import { parseImdbIdFromLink, parseResolution, - parseSize, + parseSize, parseTags } from "../utils/utils"; import { Category, @@ -22,14 +22,11 @@ const parseTorrents = (element: HTMLElement): Array => { .forEach((torrentElement) => { const data = torrentElement.children[0].textContent.trim().split("/"); const size = parseSize(torrentElement.children[4].textContent.trim()); - const tags = []; - if (torrentElement.textContent.includes("Remux")) { - tags.push("Remux"); - } + const tags = parseTags(torrentElement.textContent); const torrent: Torrent = { container: data[0].trim(), format: data[1].trim(), - resolution: data[3].trim(), + resolution: parseResolution(data[3].trim()), tags: tags, size, dom: torrentElement as HTMLElement, diff --git a/Find Unique Titles/src/trackers/CG.ts b/Find Unique Titles/src/trackers/CG.ts index ebfd0d3..c2498f3 100644 --- a/Find Unique Titles/src/trackers/CG.ts +++ b/Find Unique Titles/src/trackers/CG.ts @@ -1,5 +1,5 @@ import { parseImdbIdFromLink, parseSize } from "../utils/utils"; -import { Category, MetaData, Request, SearchResult, toGenerator, tracker } from "./tracker"; +import { Category, MetaData, Request, Resolution, SearchResult, toGenerator, tracker } from "./tracker"; import { addChild } from "common/dom"; import { fetchAndParseHtml } from "common/http"; @@ -18,12 +18,12 @@ function parseTorrents(element: HTMLElement) { ); let container = undefined; let format = undefined; - let resolution = "SD"; - const text = element.textContent.toLowerCase(); + let resolution = Resolution.SD; + const text = element.textContent!!.toLowerCase(); if (text.includes("1080p")) { - resolution = "1080p"; + resolution = Resolution.FHD; } else if (text.includes("720p")) { - resolution = "720p"; + resolution = Resolution.HD; } else if (text.includes("dvd-r")) { format = "VOB IFO"; } diff --git a/Find Unique Titles/src/trackers/GPW.ts b/Find Unique Titles/src/trackers/GPW.ts index ec84484..c83ade9 100644 --- a/Find Unique Titles/src/trackers/GPW.ts +++ b/Find Unique Titles/src/trackers/GPW.ts @@ -1,5 +1,16 @@ -import { parseImdbIdFromLink, parseSize } from "../utils/utils"; -import { MetaData, Request, SearchResult, toGenerator, Torrent, tracker } from "./tracker"; +import { + parseImdbIdFromLink, + parseResolution, + parseSize, +} from "../utils/utils"; +import { + MetaData, + Request, + SearchResult, + toGenerator, + Torrent, + tracker, +} from "./tracker"; import { addChild } from "common/dom"; import { fetchAndParseHtml } from "common/http"; @@ -16,7 +27,7 @@ export default class GPW implements tracker { return url.includes("greatposterwall.com"); } -async *getSearchRequest(): AsyncGenerator { + async *getSearchRequest(): AsyncGenerator { const requests: Array = []; document .querySelectorAll("#torrent_table tr.TableTorrent-rowMovieInfo") @@ -46,11 +57,14 @@ async *getSearchRequest(): AsyncGenerator { container, dom: torrentElement, format: "", - resolution: torrentElement - .querySelector("span.TorrentTitle-item.resolution") - .textContent.trim(), + resolution: parseResolution( + torrentElement + .querySelector("span.TorrentTitle-item.resolution") + .textContent.trim() + ), size: parseSize( - torrentElement.querySelector("td.TableTorrent-cellStatSize").textContent + torrentElement.querySelector("td.TableTorrent-cellStatSize") + .textContent ), tags, }; @@ -67,7 +81,7 @@ async *getSearchRequest(): AsyncGenerator { requests.push(request); }); - yield* toGenerator(requests) + yield* toGenerator(requests); } name(): string { @@ -80,15 +94,13 @@ async *getSearchRequest(): AsyncGenerator { const result = await fetchAndParseHtml(queryUrl); - return result.querySelector(".torrent-listings-no-result") !== null ? SearchResult.NOT_EXIST + return result.querySelector(".torrent-listings-no-result") !== null + ? SearchResult.NOT_EXIST : SearchResult.EXIST; } insertTrackersSelect(select: HTMLElement): void { - select.classList.add('Input') - addChild( - document.querySelector(".SearchPageFooter-actions"), - select - ); + select.classList.add("Input"); + addChild(document.querySelector(".SearchPageFooter-actions"), select); } } diff --git a/Find Unique Titles/src/trackers/HDB.ts b/Find Unique Titles/src/trackers/HDB.ts index d3164c0..93efaac 100644 --- a/Find Unique Titles/src/trackers/HDB.ts +++ b/Find Unique Titles/src/trackers/HDB.ts @@ -2,6 +2,7 @@ import { parseImdbId, parseResolution, parseSize, + parseTags, } from "../utils/utils"; import { tracker, @@ -9,10 +10,11 @@ import { toGenerator, MetaData, Torrent, - Category, SearchResult + Category, + SearchResult, } from "./tracker"; -import { fetchAndParseHtml } from "common/http"; import { addChild } from "common/dom"; +import { fetchAndParseHtml } from "common/http"; const isExclusive = (element: HTMLElement) => { const exclusiveLink = element.querySelector( @@ -26,13 +28,10 @@ function parseTorrent(element: HTMLElement): Torrent { element.querySelector("td:nth-child(6)")?.textContent as string ); const title = element - .querySelector(".browse_td_name_cell a") - .textContent.trim(); + .querySelector(".browse_td_name_cell a")!! + .textContent!!.trim(); const resolution = parseResolution(title); - const tags = []; - if (element.querySelector("#codec1 .medium5")) { - tags.push("Remux"); - } + const tags = parseTags(title); return { size, @@ -121,7 +120,8 @@ export default class HDB implements tracker { return result .querySelector("#resultsarea") - .textContent.includes("Nothing here!") ? SearchResult.NOT_EXIST + .textContent.includes("Nothing here!") + ? SearchResult.NOT_EXIST : SearchResult.EXIST; } diff --git a/Find Unique Titles/src/trackers/KG.ts b/Find Unique Titles/src/trackers/KG.ts index c58bb41..b329f6c 100644 --- a/Find Unique Titles/src/trackers/KG.ts +++ b/Find Unique Titles/src/trackers/KG.ts @@ -3,6 +3,7 @@ import { Category, MetaData, Request, + Resolution, SearchResult, Torrent, tracker, @@ -32,12 +33,12 @@ const parseTorrent = (element: HTMLElement): Array => { .querySelector("td:nth-child(11)") ?.textContent?.replace(",", "") as string ); - let resolution = "SD"; + let resolution = Resolution.SD; let format = undefined; if (element.querySelector('td img[src*="hdrip1080.png"]')) { - resolution = "1080p"; + resolution = Resolution.FHD; } else if (element.querySelector('td img[src*="hdrip720.png"]')) { - resolution = "720p"; + resolution = Resolution.HD; } else if (element.querySelector('td img[src*="dvdr.png"]')) { format = "VOB IFO"; } else if (element.querySelector('td img[src*="bluray.png"]')) { diff --git a/Find Unique Titles/src/trackers/PTP.ts b/Find Unique Titles/src/trackers/PTP.ts index 7e021fc..575f1b5 100644 --- a/Find Unique Titles/src/trackers/PTP.ts +++ b/Find Unique Titles/src/trackers/PTP.ts @@ -10,6 +10,7 @@ import { Category, MetaData, Request, + Resolution, SearchResult, toGenerator, Torrent, @@ -87,7 +88,7 @@ const hasRequests = (element: Element): boolean => { const isAllowedTorrent = (torrent: Torrent) => { if ( torrent.container == "x265" && - torrent.resolution != "2160p" && + torrent.resolution != Resolution.UHD && !isHDR(torrent) ) { logger.debug("[PTP] Torrent not allowed: non HDR X265 and not 2160p"); @@ -271,7 +272,7 @@ const parseTorrentsFromLines = (lines: Array) => { const torrent: Torrent = { container: data[0].split("]")[1].trim(), format: data[1].trim(), - resolution: data[3].trim(), + resolution: parseResolution(data[3].trim()), tags: tags, size, dom: line as HTMLElement, @@ -295,21 +296,13 @@ function sameContainer(first: string, second: string) { ); } -function isSD(resolution: string) { - const sdResolutions = ["SD", "PAL", "NTSC"]; - if (sdResolutions.indexOf(resolution.toUpperCase())) return true; - let height = resolution.replace("p", ""); - if (resolution.includes("x")) { - height = resolution.split("x")[1]; - } - if (parseInt(height) && parseInt(height) < 720) return true; -} +const isSD = (resolution: Resolution) => { + return resolution === Resolution.SD; +}; function sameResolution(first: Torrent, second: Torrent) { if (!first.resolution || !second.resolution) return true; - if (first.resolution === second.resolution) return true; - if (first.resolution === "SD") return isSD(second.resolution); - if (second.resolution === "SD") return isSD(first.resolution); + return first.resolution === second.resolution; } const isHDR = (torrent: Torrent) => { diff --git a/Find Unique Titles/src/trackers/Pter.ts b/Find Unique Titles/src/trackers/Pter.ts index 622fcb1..af9d588 100644 --- a/Find Unique Titles/src/trackers/Pter.ts +++ b/Find Unique Titles/src/trackers/Pter.ts @@ -13,7 +13,7 @@ import { fetchAndParseHtml } from "common/http"; function parseTorrent(element: HTMLElement): Torrent { const size = parseSize(element.childNodes[6].textContent); - const title = element.querySelector(".torrentname a").textContent.trim(); + const title = element.querySelector(".torrentname a")!!.textContent!!.trim(); let resolution = parseResolution(title); return { diff --git a/Find Unique Titles/src/trackers/SC.ts b/Find Unique Titles/src/trackers/SC.ts index 99d56d9..36c33ca 100644 --- a/Find Unique Titles/src/trackers/SC.ts +++ b/Find Unique Titles/src/trackers/SC.ts @@ -1,8 +1,9 @@ -import { parseImdbIdFromLink, parseSize } from "../utils/utils"; +import { parseImdbIdFromLink, parseResolution, parseSize } from "../utils/utils"; import { Category, MetaData, Request, + Resolution, SearchResult, Torrent, tracker, @@ -15,20 +16,20 @@ function parseTorrent(element: HTMLElement): Torrent { .querySelector(".torrent_info .activity_info")!! .querySelectorAll("div"); let size = parseSize(infos[1].textContent as string); - let resolution: string | undefined = infos[0].textContent.trim(); + let resolution: string | undefined = infos[0]?.textContent?.trim(); if (resolution == "CD" || resolution == "WEB") { resolution = undefined; } let format = undefined; if (resolution === "DVD-R") { - resolution = "SD"; + resolution = Resolution.SD; format = "VOB IFO"; } return { size, tags: [], dom: element, - resolution, + resolution: resolution ? parseResolution(resolution) : undefined, format, }; } @@ -112,4 +113,4 @@ export default class SC implements tracker { insertTrackersSelect(select: HTMLElement): void { addChild(document.querySelector("#ft_container p") as HTMLElement, select); } -} \ No newline at end of file +} diff --git a/Find Unique Titles/src/trackers/TL.ts b/Find Unique Titles/src/trackers/TL.ts index 8fbb3c8..4241c39 100644 --- a/Find Unique Titles/src/trackers/TL.ts +++ b/Find Unique Titles/src/trackers/TL.ts @@ -10,8 +10,9 @@ import { addChild } from "common/dom"; import { logger } from "common/logger"; const parseCategory = (element: Element) => { - const category = element - .querySelector(".info a.category")!! + let categoryLink = element + .querySelector(".info a.category")!!; + const category = categoryLink .getAttribute("data-ccid"); if (category == "animation") return Category.ANIME; if (category == "tv") return Category.TV; @@ -19,6 +20,7 @@ const parseCategory = (element: Element) => { if (category == "games") return Category.GAME; if (category == "movies") return Category.MOVIE; if (category == "books") return Category.BOOK; + if (categoryLink.textContent!!.trim().includes("TV")) return Category.TV }; const parseYearAndTitle = (element: Element) => { const name = element.querySelector(".name a")!!.childNodes[0].textContent!!; diff --git a/Find Unique Titles/src/trackers/tracker.ts b/Find Unique Titles/src/trackers/tracker.ts index c6bec16..02ea99d 100644 --- a/Find Unique Titles/src/trackers/tracker.ts +++ b/Find Unique Titles/src/trackers/tracker.ts @@ -3,10 +3,17 @@ export interface Torrent { size: number | null; tags: Array | null; format?: string | null; - resolution?: string | null; + resolution?: Resolution; dom: HTMLElement; } +export enum Resolution { + SD = "SD", + HD = "HD", + FHD = "FHD", + UHD = "UHD", +} + export enum Category { TV = "TV", MOVIE = "MOVIE", @@ -46,7 +53,7 @@ export enum SearchResult { MAYBE_NOT_EXIST_WITH_REQUEST, NOT_CHECKED, NOT_LOGGED_IN, - NOT_ALLOWED + NOT_ALLOWED, } export interface tracker { diff --git a/Find Unique Titles/src/utils/dom.ts b/Find Unique Titles/src/utils/dom.ts index f07970c..38547e2 100644 --- a/Find Unique Titles/src/utils/dom.ts +++ b/Find Unique Titles/src/utils/dom.ts @@ -22,7 +22,7 @@ const createMessageBox = () => { div = document.createElement("div"); div.id = "message-box"; addStyle(div); - div.addEventListener("click", () => (div.style.display = "none")); + div.addEventListener("click", () => (div!!.style.display = "none")); document.body.appendChild(div); return div; }; @@ -47,12 +47,6 @@ const addStyle = (messageBox: HTMLElement) => { messageBox.style.border = "2px solid #111"; messageBox.style.zIndex = "4591363"; }; -export const hideMessageBox = () => { - let messageBox = document.getElementById("message-box"); - if (messageBox) { - messageBox.style.display = "none"; - } -}; export const updateCount = (count: number) => { document.querySelector(".checked_count")!!.textContent = String(count); }; diff --git a/Find Unique Titles/src/utils/utils.ts b/Find Unique Titles/src/utils/utils.ts index cee5adf..8af0e62 100644 --- a/Find Unique Titles/src/utils/utils.ts +++ b/Find Unique Titles/src/utils/utils.ts @@ -1,3 +1,5 @@ +import { Resolution } from "../trackers/tracker"; + export const parseSize = (text: string): number | null => { let size: number | null = null; text = text.replace("GiB", "GB").replace("MiB", "MB"); @@ -33,30 +35,33 @@ export const parseImdbId = (text: string) => { return results[0]; }; -export const parseResolution = (text: string) => { - const resolutionsAndAliases: Record = { - "720p": ["720p", "hd"], - "1080p": ["1080p", "fhd", "full_hd"], - "2160p": ["2160p", "uhd", "4k"], +export const parseResolution = (text: string): Resolution | undefined => { + const resolutionsAndAliases: Record = { SD: ["sd", "pal", "ntsc"], + HD: ["720p", "hd"], + FHD: ["1080p", "fhd", "full_hd"], + UHD: ["2160p", "uhd", "4k"], }; - if (!text) return null; + if (!text) return undefined; for (let resolution in resolutionsAndAliases) { - let aliases = resolutionsAndAliases[resolution]; + let aliases = resolutionsAndAliases[resolution as keyof typeof Resolution]; for (let alias of aliases) { if (text.includes(alias)) { - return resolution; + return resolution as Resolution; } } - if (text.includes(resolution)) return resolution; } - const regex = /\b(\d{3})x(\d{3})\b/; + const regex = /\b(\d{3,4})x(\d{3,4})\b/; const match = text.match(regex); if (match) { - return match[0]; + const height = parseInt(match[2]); + if (height < 720) return Resolution.SD; + if (height < 1080) return Resolution.HD; + if (height < 2160) return Resolution.FHD; + return Resolution.UHD; } - return null; + return undefined; }; export const parseYearAndTitleFromReleaseName = (releaseName: string) => {