diff --git a/Find Unique Titles/dist/find.unique.titles.user.js b/Find Unique Titles/dist/find.unique.titles.user.js index 2f002b8..4ed51d1 100644 --- a/Find Unique Titles/dist/find.unique.titles.user.js +++ b/Find Unique Titles/dist/find.unique.titles.user.js @@ -1210,9 +1210,15 @@ 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 = _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.SD; + let resolution; let format; - 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"; + 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"]')) { + resolution = _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.SD; + format = "VOB IFO"; + } else if (element.querySelector('td img[src*="bluray.png"]')) { + resolution = _tracker__WEBPACK_IMPORTED_MODULE_0__.Resolution.FHD; + format = "m2ts"; + } torrents.push({ size, format, @@ -1748,26 +1754,29 @@ return url.includes("pterclub.com"); } async* getSearchRequest() { - const requests = []; - const elements = document.querySelectorAll("#torrenttable > tbody > tr"); - Array.from(elements).slice(1).forEach((element => { + const elements = Array.from(document.querySelectorAll("#torrenttable > tbody > tr")).slice(1); + yield { + total: elements.length + }; + for (let element of elements) { if (isExclusive(element)) { element.style.display = "none"; - return; + continue; } const spanElement = element.querySelector("span[data-imdbid]"); let imdbId = spanElement ? spanElement.getAttribute("data-imdbid").trim() : null; if (imdbId) imdbId = "tt" + imdbId; else imdbId = null; + const {title, year} = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseYearAndTitle)(element.querySelector(".torrentname a").textContent.trim()); const request = { torrents: [ parseTorrent(element) ], dom: [ element ], imdbId, - title: "", + title, + year, category: parseCategory(element) }; - requests.push(request); - })); - yield* (0, _tracker__WEBPACK_IMPORTED_MODULE_1__.toGenerator)(requests); + yield request; + } } name() { return "Pter"; @@ -1780,6 +1789,7 @@ } insertTrackersSelect(select) { const targetLine = document.querySelector(".searchbox > tbody:last-child table tr"); + if (!targetLine) return; const td = document.createElement("td"); td.classList.add("embedded"); td.appendChild(select); @@ -1891,23 +1901,6 @@ 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; - const regex = /^(.*?)\s+(\d{4})\s+(.*)$/; - const match = name.match(regex); - if (match) { - const title = match[1].trim(); - const year = parseInt(match[2], 10); - return { - title, - year - }; - } - return { - title: void 0, - year: void 0 - }; - }; class TL { canBeUsedAsSource() { return true; @@ -1932,7 +1925,8 @@ const category = parseCategory(element); let title; let year; - if (category == _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MOVIE) ({title, year} = parseYearAndTitle(element)); + if (category == _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MOVIE) ({title, year} = (0, + _utils_utils__WEBPACK_IMPORTED_MODULE_2__.parseYearAndTitle)(element.querySelector(".name a").childNodes[0].textContent)); const request = { torrents: [ { size, @@ -2415,6 +2409,7 @@ parseResolution: () => parseResolution, parseSize: () => parseSize, parseTags: () => parseTags, + parseYearAndTitle: () => parseYearAndTitle, parseYearAndTitleFromReleaseName: () => parseYearAndTitleFromReleaseName }); var _trackers_tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/trackers/tracker.ts"); @@ -2493,6 +2488,22 @@ if (title.includes("DV")) tags.push("DV"); return tags; }; + const parseYearAndTitle = title => { + const regex = /^(.*?)\s+(\d{4})\s+(.*)$/; + const match = title.match(regex); + if (match) { + const title = match[1].trim(); + const year = parseInt(match[2], 10); + return { + title, + year + }; + } + return { + title: void 0, + year: void 0 + }; + }; }, "../common/dist/dom/index.mjs": (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { __webpack_require__.d(__webpack_exports__, { diff --git a/Find Unique Titles/src/trackers/KG.ts b/Find Unique Titles/src/trackers/KG.ts index b329f6c..610273c 100644 --- a/Find Unique Titles/src/trackers/KG.ts +++ b/Find Unique Titles/src/trackers/KG.ts @@ -33,15 +33,17 @@ const parseTorrent = (element: HTMLElement): Array => { .querySelector("td:nth-child(11)") ?.textContent?.replace(",", "") as string ); - let resolution = Resolution.SD; + let resolution = undefined; let format = undefined; if (element.querySelector('td img[src*="hdrip1080.png"]')) { resolution = Resolution.FHD; } else if (element.querySelector('td img[src*="hdrip720.png"]')) { resolution = Resolution.HD; } else if (element.querySelector('td img[src*="dvdr.png"]')) { + resolution = Resolution.SD format = "VOB IFO"; } else if (element.querySelector('td img[src*="bluray.png"]')) { + resolution = Resolution.FHD format = "m2ts"; } torrents.push({ diff --git a/Find Unique Titles/src/trackers/Pter.ts b/Find Unique Titles/src/trackers/Pter.ts index af9d588..147b636 100644 --- a/Find Unique Titles/src/trackers/Pter.ts +++ b/Find Unique Titles/src/trackers/Pter.ts @@ -1,4 +1,4 @@ -import { parseResolution, parseSize } from "../utils/utils"; +import { parseResolution, parseSize, parseYearAndTitle } from "../utils/utils"; import { Category, MetaData, @@ -26,7 +26,7 @@ function parseTorrent(element: HTMLElement): Torrent { function parseCategory(element: HTMLElement) { let linkElement = element.querySelector('a[href^="?cat"]'); - let hrefValue = linkElement ? linkElement.getAttribute("href").trim() : null; + let hrefValue = linkElement ? linkElement.getAttribute("href")!!.trim() : null; if (hrefValue) { hrefValue = hrefValue.replace("?cat=", ""); } @@ -91,36 +91,41 @@ export default class Pter implements tracker { } async *getSearchRequest(): AsyncGenerator { - const requests: Array = []; - const elements = document.querySelectorAll("#torrenttable > tbody > tr"); - Array.from(elements) - .slice(1) - .forEach((element: HTMLElement) => { - if (isExclusive(element)) { - element.style.display = "none"; - return; - } - const spanElement = element.querySelector("span[data-imdbid]"); - let imdbId = spanElement - ? spanElement.getAttribute("data-imdbid").trim() - : null; - if (imdbId) { - imdbId = "tt" + imdbId; - } else { - imdbId = null; - } + const elements = Array.from( + document.querySelectorAll("#torrenttable > tbody > tr") + ).slice(1) as HTMLElement[]; + yield { + total: elements.length, + }; + for (let element of elements) { + if (isExclusive(element)) { + element.style.display = "none"; + continue; + } + const spanElement = element.querySelector("span[data-imdbid]"); + let imdbId = spanElement + ? spanElement.getAttribute("data-imdbid")!!.trim() + : null; + if (imdbId) { + imdbId = "tt" + imdbId; + } else { + imdbId = null; + } - const request: Request = { - torrents: [parseTorrent(element)], - dom: [element], - imdbId, - title: "", - category: parseCategory(element), - }; - requests.push(request); - }); + const { title, year } = parseYearAndTitle( + element.querySelector(".torrentname a")!!.textContent!!.trim() + ); - yield* toGenerator(requests); + const request: Request = { + torrents: [parseTorrent(element)], + dom: [element], + imdbId, + title, + year, + category: parseCategory(element), + }; + yield request; + } } name(): string { @@ -140,10 +145,11 @@ export default class Pter implements tracker { const targetLine = document.querySelector( ".searchbox > tbody:last-child table tr" ); + if (!targetLine) return const td = document.createElement("td"); td.classList.add("embedded"); td.appendChild(select); - addChild(targetLine, td); + addChild(targetLine as HTMLElement, td); } } diff --git a/Find Unique Titles/src/trackers/TL.ts b/Find Unique Titles/src/trackers/TL.ts index 4241c39..19722ce 100644 --- a/Find Unique Titles/src/trackers/TL.ts +++ b/Find Unique Titles/src/trackers/TL.ts @@ -3,7 +3,7 @@ import { parseImdbIdFromLink, parseResolution, parseSize, - parseTags, + parseTags, parseYearAndTitle } from "../utils/utils"; import { Category, MetaData, Request, SearchResult, tracker } from "./tracker"; import { addChild } from "common/dom"; @@ -22,20 +22,6 @@ const parseCategory = (element: Element) => { 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!!; - const regex = /^(.*?)\s+(\d{4})\s+(.*)$/; - const match = name.match(regex); - - if (match) { - const title = match[1].trim(); - const year = parseInt(match[2], 10); - - return { title, year }; - } - - return { title: undefined, year: undefined }; -}; export default class TL implements tracker { canBeUsedAsSource(): boolean { return true; @@ -66,7 +52,7 @@ export default class TL implements tracker { let title; let year = undefined; if (category == Category.MOVIE) { - ({ title, year } = parseYearAndTitle(element)); + ({ title, year } = parseYearAndTitle(element.querySelector(".name a")!!.childNodes[0].textContent!!)); } const request: Request = { diff --git a/Find Unique Titles/src/utils/utils.ts b/Find Unique Titles/src/utils/utils.ts index 8af0e62..ec09fef 100644 --- a/Find Unique Titles/src/utils/utils.ts +++ b/Find Unique Titles/src/utils/utils.ts @@ -103,3 +103,17 @@ export const parseTags = (title: string) => { return tags; }; + +export const parseYearAndTitle = (title: string) => { + const regex = /^(.*?)\s+(\d{4})\s+(.*)$/; + const match = title.match(regex); + + if (match) { + const title = match[1].trim(); + const year = parseInt(match[2], 10); + + return { title, year }; + } + + return { title: undefined, year: undefined }; +}; \ No newline at end of file