Skip to content

Commit

Permalink
Fix HDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Dec 14, 2023
1 parent 360d8d9 commit 830e37a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
23 changes: 14 additions & 9 deletions Find Unique Titles/dist/find.unique.titles.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
(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) {
if (null == item) continue;
const request = item;
common_logger__WEBPACK_IMPORTED_MODULE_0__.logger.debug("[{0}] Search request: {1}", sourceTracker.name(), request);
try {
Expand Down Expand Up @@ -937,7 +938,7 @@
};
function parseTorrent(element) {
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 title = element.querySelector(".browse_td_name_cell a")?.textContent.trim();
const resolution = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseResolution)(title);
const tags = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseTags)(title);
return {
Expand Down Expand Up @@ -981,23 +982,26 @@
return url.includes("hdbits.org");
}
async* getSearchRequest() {
const requests = [];
document.querySelectorAll("#torrent-list > tbody tr")?.forEach((element => {
const elements = Array.from(document.querySelectorAll("#torrent-list > tbody tr"));
yield {
total: elements.length
};
for (let element of elements) {
if (isExclusive(element)) {
element.style.display = "none";
return;
yield null;
}
const imdbId = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseImdbId)(element.querySelector("a[data-imdb-link]")?.getAttribute("data-imdb-link"));
const request = {
const {title, year} = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseYearAndTitle)(element.children[2].querySelector("a").textContent);
yield {
torrents: [ parseTorrent(element) ],
dom: [ element ],
imdbId,
title: "",
title,
year,
category: parseCategory(element)
};
requests.push(request);
}));
yield* (0, _tracker__WEBPACK_IMPORTED_MODULE_1__.toGenerator)(requests);
}
}
name() {
return "HDB";
Expand Down Expand Up @@ -2508,6 +2512,7 @@
};
const parseTags = title => {
const tags = [];
if (!title) return tags;
if (title.toLowerCase().includes("remux")) tags.push("Remux");
if (title.replaceAll(new RegExp("HDRip", "gi"), "").includes("HDR")) tags.push("HDR");
if (title.includes("DV")) tags.push("DV");
Expand Down
1 change: 1 addition & 0 deletions Find Unique Titles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const main = async function () {
updateTotalCount(metadata.total);
logger.debug(`[{0}] Parsing titles to check`, sourceTracker!!.name());
for await (const item of requestGenerator) {
if (item == null) continue;
const request = item as Request;
logger.debug(
`[{0}] Search request: {1}`,
Expand Down
56 changes: 31 additions & 25 deletions Find Unique Titles/src/trackers/HDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
parseResolution,
parseSize,
parseTags,
parseYearAndTitle,
} from "../utils/utils";
import {
tracker,
Expand All @@ -28,8 +29,8 @@ 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 = parseTags(title);

Expand Down Expand Up @@ -78,31 +79,36 @@ export default class HDB implements tracker {
}

async *getSearchRequest(): AsyncGenerator<MetaData | Request, void, void> {
const requests: Array<Request> = [];
document
.querySelectorAll("#torrent-list > tbody tr")
?.forEach((element: HTMLElement) => {
if (isExclusive(element)) {
element.style.display = "none";
return;
}
const imdbId = parseImdbId(
element
.querySelector("a[data-imdb-link]")
?.getAttribute("data-imdb-link")
);
const elements = Array.from(
document.querySelectorAll("#torrent-list > tbody tr")
) as Array<HTMLElement>;
yield {
total: elements.length,
};
for (let element of elements) {
if (isExclusive(element)) {
element.style.display = "none";
yield null;
}
const imdbId = parseImdbId(
element
.querySelector("a[data-imdb-link]")
?.getAttribute("data-imdb-link")
);

const request: Request = {
torrents: [parseTorrent(element)],
dom: [element as HTMLElement],
imdbId,
title: "",
category: parseCategory(element),
};
requests.push(request);
});
const { title, year } = parseYearAndTitle(
element.children[2].querySelector("a")!!.textContent
);

yield* toGenerator(requests);
yield {
torrents: [parseTorrent(element)],
dom: [element as HTMLElement],
imdbId,
title,
year,
category: parseCategory(element),
};
}
}

name(): string {
Expand Down
1 change: 1 addition & 0 deletions Find Unique Titles/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export const parseCodec = (title: string) => {

export const parseTags = (title: string) => {
const tags: string[] = [];
if (!title) return tags
if (title.toLowerCase().includes("remux")) tags.push("Remux");
if (title.replaceAll(new RegExp("HDRip", "gi"), "").includes("HDR"))
tags.push("HDR");
Expand Down

0 comments on commit 830e37a

Please sign in to comment.