From a531fdd4021f1d7cab433b6ae9acd0286f2a741a Mon Sep 17 00:00:00 2001 From: Morea Date: Sun, 22 Oct 2023 16:41:58 +0200 Subject: [PATCH] Make PTP works on seeding page --- .../dist/find.unique.titles.user.js | 87 +++++++++++-------- Find Unique Titles/package.json | 2 +- Find Unique Titles/src/trackers/PTP.ts | 47 ++++++---- common/src/dom.ts | 12 ++- 4 files changed, 89 insertions(+), 59 deletions(-) diff --git a/Find Unique Titles/dist/find.unique.titles.user.js b/Find Unique Titles/dist/find.unique.titles.user.js index 73fc156..39bc470 100644 --- a/Find Unique Titles/dist/find.unique.titles.user.js +++ b/Find Unique Titles/dist/find.unique.titles.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name Find Unique Titles // @description Find unique titles to cross seed -// @version 0.0.1 +// @version 0.0.2 // @author Mea01 // @match https://cinemageddon.net/browse.php* // @match https://karagarga.in/browse.php* @@ -1714,7 +1714,7 @@ class KG { canUpload(request) { return _asyncToGenerator(function* () { if (!request.imdbId) return true; - var queryUrl = "https://karagarga.in/browse.php?sort=size&search=" + request.imdbId + "&search_type=imdb&d=DESC"; + var queryUrl = "https://karagarga.in/browse.php?sort=added&search=".concat(request.imdbId.replace("", ""), "&search_type=imdb&d=DESC"); var result = yield common__WEBPACK_IMPORTED_MODULE_2__["default"].http.fetchAndParseHtml(queryUrl); return result.querySelector("tr.oddrow") === null; })(); @@ -1906,6 +1906,9 @@ function isSupportedCategory(category) { } var parseTorrents = element => { var torrents = []; + if (element.classList.contains("cover-movie-list__movie")) { + return []; + } element.querySelectorAll("tr.basic-movie-list__torrent-row").forEach(element => { if (element.querySelector(".basic-movie-list__torrent-edition")) { return; @@ -1928,7 +1931,11 @@ var parseTorrents = element => { return torrents; }; var parseCategory = element => { - var categoryTitle = element.querySelector(".basic-movie-list__torrent-edition__main").textContent; + var _element$querySelecto; + var categoryTitle = (_element$querySelecto = element.querySelector(".basic-movie-list__torrent-edition__main")) === null || _element$querySelecto === void 0 ? void 0 : _element$querySelecto.textContent; + if (!categoryTitle) { + return null; + } if (categoryTitle.includes("Stand-up Comedy ")) { return _tracker__WEBPACK_IMPORTED_MODULE_2__.Category.STAND_UP; } else if (categoryTitle.includes("Live Performance ")) { @@ -1949,10 +1956,11 @@ class PTP { } getSearchRequest() { return _wrapAsyncGenerator(function* () { - var _document$querySelect; var requests = []; - (_document$querySelect = document.querySelectorAll("#torrents-movie-view table.torrent_table > tbody")) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.forEach(element => { - var imdbId = (0,_utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseImdbIdFromLink)(element.querySelector(".basic-movie-list__movie__ratings-and-tags")); + var nodes = common__WEBPACK_IMPORTED_MODULE_3__["default"].dom.findFirst("#torrents-movie-view table.torrent_table > tbody", ".cover-movie-list__movie"); + nodes === null || nodes === void 0 ? void 0 : nodes.forEach(element => { + var elements = common__WEBPACK_IMPORTED_MODULE_3__["default"].dom.findFirst(".basic-movie-list__movie__ratings-and-tags", ".cover-movie-list__movie__rating-and-tags"); + var imdbId = elements ? (0,_utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseImdbIdFromLink)(elements[0]) : null; var request = { torrents: parseTorrents(element), dom: element, @@ -2894,26 +2902,6 @@ __webpack_require__.r(__webpack_exports__); /* harmony import */ var _trim21_gm_fetch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @trim21/gm-fetch */ "../node_modules/@trim21/gm-fetch/dist/index.mjs"); -const parser = new DOMParser(); -const fetchUrl = async (url, wait = 1000) => { - await sleep(wait); - const res = await (0,_trim21_gm_fetch__WEBPACK_IMPORTED_MODULE_0__["default"])(url); - return await res.text(); -}; -const fetchAndParseHtml = async (query_url) => { - const response = await fetchUrl(query_url); - return parser.parseFromString(response, "text/html").body; -}; -const sleep = (ms) => { - return new Promise(resolve => setTimeout(resolve, ms)); -}; - -var http = /*#__PURE__*/Object.freeze({ - __proto__: null, - fetchAndParseHtml: fetchAndParseHtml, - fetchUrl: fetchUrl -}); - const insertBefore = (newNode, existingNode) => { existingNode.parentNode.insertBefore(newNode, existingNode); }; @@ -2924,10 +2912,11 @@ const addChild = (parent, child) => { parent.appendChild(child); }; const appendErrorMessage = () => { - const div = document.createElement('div'); - div.innerHTML = '×' + - ''; - div.style.position = 'fixed'; + const div = document.createElement("div"); + div.innerHTML = + '×' + + ''; + div.style.position = "fixed"; div.style.bottom = "50px"; div.style.left = "50%"; div.style.display = "none"; @@ -2938,24 +2927,48 @@ const appendErrorMessage = () => { div.style.color = "white"; addChild(document.body, div); }; -const showError = (message) => { - const element = document.querySelector('#message'); - element.innerHTML = "Error occurred in Fin Unique titles script: " + message; - element.parentElement.style.display = "block"; +const findFirst = (...selectors) => { + for (let selector of selectors) { + let elements = document.querySelectorAll(selector); + if (elements.length > 0) { + return elements; + } + } + return null; }; var dom = /*#__PURE__*/Object.freeze({ __proto__: null, addChild: addChild, appendErrorMessage: appendErrorMessage, + findFirst: findFirst, insertAfter: insertAfter, - insertBefore: insertBefore, - showError: showError + insertBefore: insertBefore +}); + +const parser = new DOMParser(); +const fetchUrl = async (url, wait = 1000) => { + await sleep(wait); + const res = await (0,_trim21_gm_fetch__WEBPACK_IMPORTED_MODULE_0__["default"])(url); + return await res.text(); +}; +const fetchAndParseHtml = async (query_url) => { + const response = await fetchUrl(query_url); + return parser.parseFromString(response, "text/html").body; +}; +const sleep = (ms) => { + return new Promise((resolve) => setTimeout(resolve, ms)); +}; + +var http = /*#__PURE__*/Object.freeze({ + __proto__: null, + fetchAndParseHtml: fetchAndParseHtml, + fetchUrl: fetchUrl }); const tracker_tools = { http, - dom + dom, }; diff --git a/Find Unique Titles/package.json b/Find Unique Titles/package.json index b739810..ba4905b 100644 --- a/Find Unique Titles/package.json +++ b/Find Unique Titles/package.json @@ -1,7 +1,7 @@ { "name": "find.unique.titles", "description": "Find unique titles to cross seed", - "version": "0.0.2", + "version": "0.0.3", "author": { "name": "Mea01" }, diff --git a/Find Unique Titles/src/trackers/PTP.ts b/Find Unique Titles/src/trackers/PTP.ts index 8751c71..0b79882 100644 --- a/Find Unique Titles/src/trackers/PTP.ts +++ b/Find Unique Titles/src/trackers/PTP.ts @@ -29,6 +29,9 @@ function isSupportedCategory(category: Category) { const parseTorrents = (element: HTMLElement) => { const torrents = []; + if (element.classList.contains("cover-movie-list__movie")) { + return []; + } element .querySelectorAll("tr.basic-movie-list__torrent-row") .forEach((element: HTMLElement) => { @@ -56,7 +59,10 @@ const parseTorrents = (element: HTMLElement) => { const parseCategory = (element: HTMLElement): Category => { const categoryTitle = element.querySelector( ".basic-movie-list__torrent-edition__main" - ).textContent; + )?.textContent; + if (!categoryTitle) { + return null + } if (categoryTitle.includes("Stand-up Comedy ")) { return Category.STAND_UP; } else if (categoryTitle.includes("Live Performance ")) { @@ -81,22 +87,29 @@ export default class PTP implements tracker { async *getSearchRequest(): AsyncGenerator { const requests: Array = []; - document - .querySelectorAll("#torrents-movie-view table.torrent_table > tbody") - ?.forEach((element: HTMLElement) => { - const imdbId = parseImdbIdFromLink( - element.querySelector(".basic-movie-list__movie__ratings-and-tags") - ); - - const request: Request = { - torrents: parseTorrents(element), - dom: element as HTMLElement, - imdbId, - query: "", - category: parseCategory(element), - }; - requests.push(request); - }); + const nodes = tracker_tools.dom.findFirst( + "#torrents-movie-view table.torrent_table > tbody", + ".cover-movie-list__movie" + ); + nodes?.forEach((element: HTMLElement) => { + let elements = tracker_tools.dom.findFirst( + ".basic-movie-list__movie__ratings-and-tags", + ".cover-movie-list__movie__rating-and-tags" + ); + + const imdbId = elements + ? parseImdbIdFromLink(elements[0] as HTMLElement) + : null; + + const request: Request = { + torrents: parseTorrents(element), + dom: element as HTMLElement, + imdbId, + query: "", + category: parseCategory(element), + }; + requests.push(request); + }); yield* toGenerator(requests); } diff --git a/common/src/dom.ts b/common/src/dom.ts index b123d29..b33315d 100644 --- a/common/src/dom.ts +++ b/common/src/dom.ts @@ -34,8 +34,12 @@ export const appendErrorMessage = () => { addChild(document.body, div); }; -export const showError = (message: string) => { - const element = document.querySelector("#message")! as HTMLElement; - element.innerHTML = "Error occurred in Fin Unique titles script: " + message; - element.parentElement!.style.display = "block"; +export const findFirst = (...selectors: string[]) => { + for (let selector of selectors) { + let elements = document.querySelectorAll(selector); + if (elements.length > 0) { + return elements; + } + } + return null; };