Skip to content

Commit

Permalink
Pter: parse title and year
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Dec 10, 2023
1 parent b55636d commit 333ed2d
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 76 deletions.
67 changes: 39 additions & 28 deletions Find Unique Titles/dist/find.unique.titles.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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__, {
Expand Down
4 changes: 3 additions & 1 deletion Find Unique Titles/src/trackers/KG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ const parseTorrent = (element: HTMLElement): Array<Torrent> => {
.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({
Expand Down
68 changes: 37 additions & 31 deletions Find Unique Titles/src/trackers/Pter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseResolution, parseSize } from "../utils/utils";
import { parseResolution, parseSize, parseYearAndTitle } from "../utils/utils";
import {
Category,
MetaData,
Expand Down Expand Up @@ -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=", "");
}
Expand Down Expand Up @@ -91,36 +91,41 @@ export default class Pter implements tracker {
}

async *getSearchRequest(): AsyncGenerator<MetaData | Request, void, void> {
const requests: Array<Request> = [];
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 {
Expand All @@ -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);
}
}
18 changes: 2 additions & 16 deletions Find Unique Titles/src/trackers/TL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down
14 changes: 14 additions & 0 deletions Find Unique Titles/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};

0 comments on commit 333ed2d

Please sign in to comment.