From 816d3a6accf04963f603fe4a51e46747a17d3979 Mon Sep 17 00:00:00 2001 From: Morea Date: Sun, 3 Dec 2023 20:14:21 +0100 Subject: [PATCH] Fix issue with PTP --- .../dist/find.unique.titles.user.js | 163 +++++++++++------- Find Unique Titles/src/index.ts | 120 +++++++------ Find Unique Titles/src/trackers/KG.ts | 5 +- Find Unique Titles/src/trackers/PTP.ts | 4 +- Find Unique Titles/src/trackers/SC.ts | 13 +- Find Unique Titles/src/trackers/TL.ts | 60 +++++-- 6 files changed, 227 insertions(+), 138 deletions(-) diff --git a/Find Unique Titles/dist/find.unique.titles.user.js b/Find Unique Titles/dist/find.unique.titles.user.js index 2e2c769..ba8893e 100644 --- a/Find Unique Titles/dist/find.unique.titles.user.js +++ b/Find Unique Titles/dist/find.unique.titles.user.js @@ -92,40 +92,49 @@ const metadata = (await requestGenerator.next()).value; (0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.addCounter)(); (0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateTotalCount)(metadata.total); + common_logger__WEBPACK_IMPORTED_MODULE_0__.logger.debug("[{0}] Parsing titles to check", sourceTracker.name()); for await (const item of requestGenerator) { const request = item; - if (settings.useCache && request.imdbId && (0, _utils_cache__WEBPACK_IMPORTED_MODULE_4__.existsInCache)(targetTracker.name(), request.imdbId)) { - hideTorrents(request); + common_logger__WEBPACK_IMPORTED_MODULE_0__.logger.debug("[{0}] Search request: {1}", sourceTracker.name(), request); + try { + if (settings.useCache && request.imdbId && (0, _utils_cache__WEBPACK_IMPORTED_MODULE_4__.existsInCache)(targetTracker.name(), request.imdbId)) { + common_logger__WEBPACK_IMPORTED_MODULE_0__.logger.debug("Title exists in target tracker, found using cache"); + hideTorrents(request); + (0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateCount)(i++); + continue; + } + const response = await targetTracker.search(request); (0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateCount)(i++); - continue; - } - const response = await targetTracker.search(request); - (0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateCount)(i++); - if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.EXIST || response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_ALLOWED) { - if (request.imdbId) await (0, _utils_cache__WEBPACK_IMPORTED_MODULE_4__.addToCache)(targetTracker.name(), request.imdbId); - hideTorrents(request); - } else if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_LOGGED_IN) { - alert(`You are not logged in ${targetTracker.name()}`); - break; - } else { - newContent++; - (0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateNewContent)(newContent); - if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.MAYBE_NOT_EXIST) { - request.dom[0].setAttribute("title", "Title may not exist on target tracker"); - request.dom[0].style.border = "2px solid #9b59b6"; - } else if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_EXIST_WITH_REQUEST) { - request.dom[0].setAttribute("title", "Title was not found and has matching requests"); - request.dom[0].style.border = "2px solid #2ecc71"; - } else if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.MAYBE_NOT_EXIST_WITH_REQUEST) { - request.dom[0].setAttribute("title", "Title may not exists and there are matching requests"); - request.dom[0].style.border = "2px solid #e67e22"; - } else if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_CHECKED) { - request.dom[0].setAttribute("title", "Title was not checked on target tracker"); - request.dom[0].style.border = "2px solid #e74c3c"; - } else if (response != _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_EXIST) { - request.dom[0].setAttribute("title", "Title was not found on target tracker"); - request.dom[0].style.border = "2px solid #3498db"; + if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.EXIST || response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_ALLOWED) { + if (request.imdbId) await (0, _utils_cache__WEBPACK_IMPORTED_MODULE_4__.addToCache)(targetTracker.name(), request.imdbId); + hideTorrents(request); + } else if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_LOGGED_IN) { + alert(`You are not logged in ${targetTracker.name()}`); + break; + } else { + newContent++; + (0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateNewContent)(newContent); + if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.MAYBE_NOT_EXIST) { + request.dom[0].setAttribute("title", "Title may not exist on target tracker"); + request.dom[0].style.border = "2px solid #9b59b6"; + } else if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_EXIST_WITH_REQUEST) { + request.dom[0].setAttribute("title", "Title was not found and has matching requests"); + request.dom[0].style.border = "2px solid #2ecc71"; + } else if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.MAYBE_NOT_EXIST_WITH_REQUEST) { + request.dom[0].setAttribute("title", "Title may not exists and there are matching requests"); + request.dom[0].style.border = "2px solid #e67e22"; + } else if (response == _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_CHECKED) { + request.dom[0].setAttribute("title", "Title was not checked on target tracker"); + request.dom[0].style.border = "2px solid #e74c3c"; + } else if (response != _trackers_tracker__WEBPACK_IMPORTED_MODULE_5__.SearchResult.NOT_EXIST) { + request.dom[0].setAttribute("title", "Title was not found on target tracker"); + request.dom[0].style.border = "2px solid #3498db"; + } } + } catch (e) { + common_logger__WEBPACK_IMPORTED_MODULE_0__.logger.info("Error occurred when checking {0}, {1]", request, e); + request.dom[0].setAttribute("title", "Title was not checked due to an error"); + request.dom[0].style.border = "2px solid red"; } } (0, _utils_cache__WEBPACK_IMPORTED_MODULE_4__.clearMemoryCache)(); @@ -1177,10 +1186,9 @@ }); var _utils_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/utils/utils.ts"); var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/trackers/tracker.ts"); - var common_dom__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("../common/dist/dom/index.mjs"); - var common_logger__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../common/dist/logger/index.mjs"); - var common_searcher__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("../common/dist/searcher/index.mjs"); - var common_trackers__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("../common/dist/trackers/index.mjs"); + var common_dom__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("../common/dist/dom/index.mjs"); + var common_searcher__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../common/dist/searcher/index.mjs"); + var common_trackers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("../common/dist/trackers/index.mjs"); const parseCategory = element => { const category = _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MOVIE; let img = element.querySelectorAll("td img")[0]; @@ -1224,7 +1232,6 @@ return url.includes("karagarga.in"); } async* getSearchRequest() { - common_logger__WEBPACK_IMPORTED_MODULE_2__.logger.debug("[{0}] Parsing titles to check", this.name()); let elements = Array.from(document.querySelectorAll("#browse > tbody tr")).filter((element => null != element.querySelector("td:nth-child(2) > div > span:nth-child(1)"))); yield { total: elements.length @@ -1242,7 +1249,6 @@ year, category: parseCategory(element) }; - common_logger__WEBPACK_IMPORTED_MODULE_2__.logger.debug("[{0}] Search request: {1}", this.name(), request); yield request; } } @@ -1251,15 +1257,15 @@ } async search(request) { if (!request.imdbId) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_CHECKED; - const result = await (0, common_searcher__WEBPACK_IMPORTED_MODULE_3__.search)(common_trackers__WEBPACK_IMPORTED_MODULE_4__.KG, { + const result = await (0, common_searcher__WEBPACK_IMPORTED_MODULE_2__.search)(common_trackers__WEBPACK_IMPORTED_MODULE_3__.KG, { movie_title: "", movie_imdb_id: request.imdbId }); - if (result == common_searcher__WEBPACK_IMPORTED_MODULE_3__.SearchResult.LOGGED_OUT) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_LOGGED_IN; - return result == common_searcher__WEBPACK_IMPORTED_MODULE_3__.SearchResult.NOT_FOUND ? _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_EXIST : _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.EXIST; + if (result == common_searcher__WEBPACK_IMPORTED_MODULE_2__.SearchResult.LOGGED_OUT) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_LOGGED_IN; + return result == common_searcher__WEBPACK_IMPORTED_MODULE_2__.SearchResult.NOT_FOUND ? _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_EXIST : _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.EXIST; } insertTrackersSelect(select) { - (0, common_dom__WEBPACK_IMPORTED_MODULE_5__.insertBefore)(select, document.getElementById("showdead")); + (0, common_dom__WEBPACK_IMPORTED_MODULE_4__.insertBefore)(select, document.getElementById("showdead")); } } }, @@ -1541,7 +1547,7 @@ const query_url = `https://passthepopcorn.me/torrents.php?action=advanced&searchstr=${encodeURIComponent(request.title)}&year=${request.year}`; result = await (0, common_http__WEBPACK_IMPORTED_MODULE_4__.fetchAndParseHtml)(query_url); torrents = parseAvailableTorrents(result); - } + } else return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_CHECKED; } else { torrents = (0, _utils_cache__WEBPACK_IMPORTED_MODULE_5__.getFromMemoryCache)(request.imdbId); if (!torrents) { @@ -1553,7 +1559,7 @@ } let notFound = !torrents.length; if (notFound) { - if (hasRequests(result)) if (request.imdbId) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_EXIST_WITH_REQUEST; else return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.MAYBE_NOT_EXIST_WITH_REQUEST; + if (result && hasRequests(result)) if (request.imdbId) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_EXIST_WITH_REQUEST; else return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.MAYBE_NOT_EXIST_WITH_REQUEST; if (request.imdbId) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_EXIST; else return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.MAYBE_NOT_EXIST; } let searchResult = _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.EXIST; @@ -1742,9 +1748,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_dom__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__("../common/dist/dom/index.mjs"); - var common_http__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__("../common/dist/http/index.mjs"); - var common_logger__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../common/dist/logger/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"); 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); @@ -1789,7 +1794,6 @@ return url.includes("secret-cinema.pw") && !url.includes("torrents.php?id"); } async* getSearchRequest() { - common_logger__WEBPACK_IMPORTED_MODULE_2__.logger.debug("[{0}] Parsing titles to check", this.name()); const elements = Array.from(document.querySelectorAll(".torrent_card")).filter((element => null != element.querySelector(".torrent_tags"))); yield { total: elements.length @@ -1806,7 +1810,6 @@ year, category: parseCategory(element) }; - common_logger__WEBPACK_IMPORTED_MODULE_2__.logger.debug("[{0}] Search request: {1}", this.name(), request); yield request; } } @@ -1816,11 +1819,11 @@ async search(request) { if (!request.imdbId) return _tracker__WEBPACK_IMPORTED_MODULE_1__.SearchResult.NOT_CHECKED; const queryUrl = `https://secret-cinema.pw/torrents.php?action=advanced&searchsubmit=1&cataloguenumber=${request.imdbId}&order_by=time&order_way=desc&tags_type=0`; - const result = await (0, common_http__WEBPACK_IMPORTED_MODULE_3__.fetchAndParseHtml)(queryUrl); + const result = await (0, common_http__WEBPACK_IMPORTED_MODULE_2__.fetchAndParseHtml)(queryUrl); return null === result.querySelector(".torrent_card_container") ? _tracker__WEBPACK_IMPORTED_MODULE_1__.SearchResult.NOT_EXIST : _tracker__WEBPACK_IMPORTED_MODULE_1__.SearchResult.EXIST; } insertTrackersSelect(select) { - (0, common_dom__WEBPACK_IMPORTED_MODULE_4__.addChild)(document.querySelector("#ft_container p"), select); + (0, common_dom__WEBPACK_IMPORTED_MODULE_3__.addChild)(document.querySelector("#ft_container p"), select); } } }, @@ -1828,9 +1831,36 @@ __webpack_require__.d(__webpack_exports__, { default: () => TL }); - 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_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../common/dist/dom/index.mjs"); + var _utils_utils__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./src/utils/utils.ts"); + var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/trackers/tracker.ts"); + 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"); + 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; + }; + 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; @@ -1842,10 +1872,18 @@ return url.includes("torrentleech.org"); } async* getSearchRequest() { - const requests = []; - document.querySelectorAll(".torrent")?.forEach((element => { - const imdbId = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseImdbIdFromLink)(element); - const size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseSize)(element.querySelector(".td-size")?.textContent); + common_logger__WEBPACK_IMPORTED_MODULE_1__.logger.debug("[{0}] Parsing titles to check", this.name()); + const elements = document.querySelectorAll(".torrent"); + yield { + total: elements.length + }; + for (let element of elements) { + const imdbId = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_2__.parseImdbIdFromLink)(element); + const size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_2__.parseSize)(element.querySelector(".td-size")?.textContent); + const category = parseCategory(element); + let title; + let year; + if (category == _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MOVIE) ({title, year} = parseYearAndTitle(element)); const request = { torrents: [ { size, @@ -1854,23 +1892,24 @@ } ], dom: [ element ], imdbId, - title: "" + title, + year, + category }; - requests.push(request); - })); - yield* (0, _tracker__WEBPACK_IMPORTED_MODULE_1__.toGenerator)(requests); + yield request; + } } name() { return "TL"; } async search(request) { - return _tracker__WEBPACK_IMPORTED_MODULE_1__.SearchResult.NOT_CHECKED; + return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_CHECKED; } insertTrackersSelect(select) { select.style.margin = "20px 0"; select.style.padding = "2px 2px 3px 2px"; select.style.color = "#111"; - (0, common_dom__WEBPACK_IMPORTED_MODULE_2__.addChild)(document.querySelector(".sub-navbar"), select); + (0, common_dom__WEBPACK_IMPORTED_MODULE_3__.addChild)(document.querySelector(".sub-navbar"), select); } } }, diff --git a/Find Unique Titles/src/index.ts b/Find Unique Titles/src/index.ts index 1394755..5e861fb 100644 --- a/Find Unique Titles/src/index.ts +++ b/Find Unique Titles/src/index.ts @@ -67,64 +67,76 @@ const main = async function () { const metadata = (await requestGenerator.next()).value as MetaData; addCounter(); updateTotalCount(metadata.total); + logger.debug(`[{0}] Parsing titles to check`, sourceTracker!!.name()); for await (const item of requestGenerator) { const request = item as Request; - if ( - settings.useCache && - request.imdbId && - existsInCache(targetTracker.name(), request.imdbId) - ) { - hideTorrents(request); - updateCount(i++); - continue; - } - const response = await targetTracker.search(request); - updateCount(i++); - if ( - response == SearchResult.EXIST || - response == SearchResult.NOT_ALLOWED - ) { - if (request.imdbId) { - await addToCache(targetTracker.name(), request.imdbId); + logger.debug(`[{0}] Search request: {1}`, sourceTracker!!.name(), request); + try { + if ( + settings.useCache && + request.imdbId && + existsInCache(targetTracker.name(), request.imdbId) + ) { + logger.debug("Title exists in target tracker, found using cache") + hideTorrents(request); + updateCount(i++); + continue; } - hideTorrents(request); - } else if (response == SearchResult.NOT_LOGGED_IN) { - alert(`You are not logged in ${targetTracker.name()}`); - break; - } else { - newContent++; - updateNewContent(newContent); - if (response == SearchResult.MAYBE_NOT_EXIST) { - request.dom[0].setAttribute( - "title", - "Title may not exist on target tracker" - ); - request.dom[0].style.border = "2px solid #9b59b6"; - } else if (response == SearchResult.NOT_EXIST_WITH_REQUEST) { - request.dom[0].setAttribute( - "title", - "Title was not found and has matching requests" - ); - request.dom[0].style.border = "2px solid #2ecc71"; - } else if (response == SearchResult.MAYBE_NOT_EXIST_WITH_REQUEST) { - request.dom[0].setAttribute( - "title", - "Title may not exists and there are matching requests" - ); - request.dom[0].style.border = "2px solid #e67e22"; - } else if (response == SearchResult.NOT_CHECKED) { - request.dom[0].setAttribute( - "title", - "Title was not checked on target tracker" - ); - request.dom[0].style.border = "2px solid #e74c3c"; - } else if (response != SearchResult.NOT_EXIST) { - request.dom[0].setAttribute( - "title", - "Title was not found on target tracker" - ); - request.dom[0].style.border = "2px solid #3498db"; + const response = await targetTracker.search(request); + updateCount(i++); + if ( + response == SearchResult.EXIST || + response == SearchResult.NOT_ALLOWED + ) { + if (request.imdbId) { + await addToCache(targetTracker.name(), request.imdbId); + } + hideTorrents(request); + } else if (response == SearchResult.NOT_LOGGED_IN) { + alert(`You are not logged in ${targetTracker.name()}`); + break; + } else { + newContent++; + updateNewContent(newContent); + if (response == SearchResult.MAYBE_NOT_EXIST) { + request.dom[0].setAttribute( + "title", + "Title may not exist on target tracker" + ); + request.dom[0].style.border = "2px solid #9b59b6"; + } else if (response == SearchResult.NOT_EXIST_WITH_REQUEST) { + request.dom[0].setAttribute( + "title", + "Title was not found and has matching requests" + ); + request.dom[0].style.border = "2px solid #2ecc71"; + } else if (response == SearchResult.MAYBE_NOT_EXIST_WITH_REQUEST) { + request.dom[0].setAttribute( + "title", + "Title may not exists and there are matching requests" + ); + request.dom[0].style.border = "2px solid #e67e22"; + } else if (response == SearchResult.NOT_CHECKED) { + request.dom[0].setAttribute( + "title", + "Title was not checked on target tracker" + ); + request.dom[0].style.border = "2px solid #e74c3c"; + } else if (response != SearchResult.NOT_EXIST) { + request.dom[0].setAttribute( + "title", + "Title was not found on target tracker" + ); + request.dom[0].style.border = "2px solid #3498db"; + } } + } catch (e) { + logger.info("Error occurred when checking {0}, {1]", request, e); + request.dom[0].setAttribute( + "title", + "Title was not checked due to an error" + ); + request.dom[0].style.border = "2px solid red"; } } clearMemoryCache(); diff --git a/Find Unique Titles/src/trackers/KG.ts b/Find Unique Titles/src/trackers/KG.ts index 3775440..c58bb41 100644 --- a/Find Unique Titles/src/trackers/KG.ts +++ b/Find Unique Titles/src/trackers/KG.ts @@ -8,7 +8,6 @@ import { tracker, } from "./tracker"; import { insertBefore } from "common/dom"; -import { logger } from "common/logger"; import { search, SearchResult as SR } from "common/searcher"; import { KG as KGTracker } from "common/trackers"; @@ -68,7 +67,6 @@ export default class KG implements tracker { } async *getSearchRequest(): AsyncGenerator { - logger.debug(`[{0}] Parsing titles to check`, this.name()); let elements = Array.from( document.querySelectorAll("#browse > tbody tr") ).filter( @@ -95,7 +93,6 @@ export default class KG implements tracker { year, category: parseCategory(element as HTMLElement), }; - logger.debug(`[{0}] Search request: {1}`, this.name(), request); yield request; } } @@ -117,4 +114,4 @@ export default class KG implements tracker { insertTrackersSelect(select: HTMLElement): void { insertBefore(select, document.getElementById("showdead") as HTMLElement); } -} +} \ No newline at end of file diff --git a/Find Unique Titles/src/trackers/PTP.ts b/Find Unique Titles/src/trackers/PTP.ts index bdc183f..6045569 100644 --- a/Find Unique Titles/src/trackers/PTP.ts +++ b/Find Unique Titles/src/trackers/PTP.ts @@ -145,6 +145,8 @@ export default class PTP implements tracker { )}&year=${request.year}`; result = await fetchAndParseHtml(query_url); torrents = parseAvailableTorrents(result); + } else { + return SearchResult.NOT_CHECKED } } else { torrents = getFromMemoryCache(request.imdbId); @@ -158,7 +160,7 @@ export default class PTP implements tracker { } let notFound = !torrents.length; if (notFound) { - if (hasRequests(result)) { + if (result && hasRequests(result)) { if (request.imdbId) { return SearchResult.NOT_EXIST_WITH_REQUEST; } else { diff --git a/Find Unique Titles/src/trackers/SC.ts b/Find Unique Titles/src/trackers/SC.ts index 27e447d..99d56d9 100644 --- a/Find Unique Titles/src/trackers/SC.ts +++ b/Find Unique Titles/src/trackers/SC.ts @@ -1,9 +1,14 @@ import { parseImdbIdFromLink, parseSize } from "../utils/utils"; -import { Category, MetaData, Request, SearchResult, Torrent, tracker } from "./tracker"; +import { + Category, + MetaData, + Request, + SearchResult, + Torrent, + tracker, +} from "./tracker"; import { addChild } from "common/dom"; import { fetchAndParseHtml } from "common/http"; -import { logger } from "common/logger"; - function parseTorrent(element: HTMLElement): Torrent { let infos = element @@ -66,7 +71,6 @@ export default class SC implements tracker { } async *getSearchRequest(): AsyncGenerator { - logger.debug(`[{0}] Parsing titles to check`, this.name()); const elements = Array.from( document.querySelectorAll(".torrent_card") ).filter((element) => element.querySelector(".torrent_tags") != null); @@ -88,7 +92,6 @@ export default class SC implements tracker { year, category: parseCategory(element as HTMLElement), }; - logger.debug(`[{0}] Search request: {1}`, this.name(), request); yield request; } } diff --git a/Find Unique Titles/src/trackers/TL.ts b/Find Unique Titles/src/trackers/TL.ts index e387073..cd10090 100644 --- a/Find Unique Titles/src/trackers/TL.ts +++ b/Find Unique Titles/src/trackers/TL.ts @@ -1,13 +1,39 @@ import { parseImdbIdFromLink, parseSize } from "../utils/utils"; import { + Category, MetaData, Request, SearchResult, - toGenerator, tracker, } from "./tracker"; import { addChild } from "common/dom"; +import { logger } from "common/logger"; +const parseCategory = (element: Element) => { + const category = element + .querySelector(".info a.category")!! + .getAttribute("data-ccid"); + if (category == "animation") return Category.ANIME; + if (category == "tv") return Category.TV; + if (category == "music") return Category.MUSIC; + if (category == "games") return Category.GAME; + if (category == "movies") return Category.MOVIE; + if (category == "books") return Category.BOOK; +}; +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; @@ -22,29 +48,39 @@ export default class TL implements tracker { } async *getSearchRequest(): AsyncGenerator { - const requests: Array = []; - document.querySelectorAll(".torrent")?.forEach((element: HTMLElement) => { - const imdbId = parseImdbIdFromLink(element); + logger.debug(`[{0}] Parsing titles to check`, this.name()); + const elements = document.querySelectorAll(".torrent"); + yield { + total: elements.length, + }; + for (let element of elements) { + const imdbId = parseImdbIdFromLink(element as HTMLElement); const size = parseSize( element.querySelector(".td-size")?.textContent as string ); + const category = parseCategory(element); + let title; + let year = undefined; + if (category == Category.MOVIE) { + ({ title, year } = parseYearAndTitle(element)); + } const request: Request = { torrents: [ { size, tags: [], - dom: element, + dom: element as HTMLElement, }, ], - dom: [element], + dom: [element as HTMLElement], imdbId, - title: "", + title, + year, + category, }; - requests.push(request); - }); - - yield* toGenerator(requests); + yield request; + } } name(): string { @@ -61,4 +97,4 @@ export default class TL implements tracker { select.style.color = "#111"; addChild(document.querySelector(".sub-navbar") as HTMLElement, select); } -} \ No newline at end of file +}