Skip to content

Commit

Permalink
Catch error when parsing torrent
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Dec 31, 2023
1 parent 89bf02e commit a75b569
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 37 deletions.
21 changes: 11 additions & 10 deletions Find Unique Titles/dist/find.unique.titles.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,13 @@
(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) {
(0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateCount)(i++);
continue;
}
if (null == item) continue;
const request = item;
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);
Expand Down Expand Up @@ -948,8 +944,9 @@
});
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_3__ = __webpack_require__("../common/dist/dom/index.mjs");
var common_http__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("../common/dist/http/index.mjs");
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");
const isExclusive = element => {
const exclusiveLink = element.querySelector('a[href="/browse.php?exclusive=1"]');
return null != exclusiveLink;
Expand Down Expand Up @@ -1004,7 +1001,7 @@
yield {
total: elements.length
};
for (let element of elements) {
for (let element of elements) try {
if (isExclusive(element)) {
element.style.display = "none";
yield null;
Expand All @@ -1019,6 +1016,10 @@
year,
category: parseCategory(element)
};
} catch (e) {
console.trace(e);
common_logger__WEBPACK_IMPORTED_MODULE_2__.logger.info("{0} Error occurred while parsing torrent: " + e, this.name());
yield null;
}
}
name() {
Expand All @@ -1027,12 +1028,12 @@
async search(request) {
if (!request.imdbId) return _tracker__WEBPACK_IMPORTED_MODULE_1__.SearchResult.NOT_CHECKED;
const queryUrl = "https://hdbits.org/browse.php?c3=1&c1=1&c2=1&tagsearchtype=or&imdb=" + request.imdbId + "&sort=size&h=8&d=DESC";
const result = await (0, common_http__WEBPACK_IMPORTED_MODULE_2__.fetchAndParseHtml)(queryUrl);
const result = await (0, common_http__WEBPACK_IMPORTED_MODULE_3__.fetchAndParseHtml)(queryUrl);
return result.querySelector("#resultsarea").textContent.includes("Nothing here!") ? _tracker__WEBPACK_IMPORTED_MODULE_1__.SearchResult.NOT_EXIST : _tracker__WEBPACK_IMPORTED_MODULE_1__.SearchResult.EXIST;
}
insertTrackersSelect(select) {
document.querySelector("#moresearch3 > td:nth-child(2)").innerHTML += "<br><br>Find unique for:<br>";
(0, common_dom__WEBPACK_IMPORTED_MODULE_3__.addChild)(document.querySelector("#moresearch3 > td:nth-child(2)"), select);
(0, common_dom__WEBPACK_IMPORTED_MODULE_4__.addChild)(document.querySelector("#moresearch3 > td:nth-child(2)"), select);
}
}
},
Expand Down
2 changes: 0 additions & 2 deletions Find Unique Titles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const main = async function () {
logger.debug(`[{0}] Parsing titles to check`, sourceTracker!!.name());
for await (const item of requestGenerator) {
if (item == null) {
updateCount(i++);
continue;
}
const request = item as Request;
Expand All @@ -87,7 +86,6 @@ const main = async function () {
) {
logger.debug("Title exists in target tracker, found using cache");
hideTorrents(request);
updateCount(i++);
continue;
}
const response = await targetTracker.search(request);
Expand Down
59 changes: 34 additions & 25 deletions Find Unique Titles/src/trackers/HDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import {
parseYearAndTitle,
} from "../utils/utils";
import {
tracker,
Request,
toGenerator,
MetaData,
Torrent,
Category,
MetaData,
Request,
SearchResult,
Torrent,
tracker,
} from "./tracker";
import { addChild } from "common/dom";
import { fetchAndParseHtml } from "common/http";
import { logger } from "common/logger";

const isExclusive = (element: HTMLElement) => {
const exclusiveLink = element.querySelector(
Expand Down Expand Up @@ -86,28 +86,37 @@ export default class HDB implements tracker {
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")
);
try {
if (isExclusive(element)) {
element.style.display = "none";
yield null;
}
const imdbId = parseImdbId(
element
.querySelector("a[data-imdb-link]")
?.getAttribute("data-imdb-link")
);

const { title, year } = parseYearAndTitle(
element.children[2].querySelector("a")!!.textContent
);
const { title, year } = parseYearAndTitle(
element.children[2].querySelector("a")!!.textContent
);

yield {
torrents: [parseTorrent(element)],
dom: [element as HTMLElement],
imdbId,
title,
year,
category: parseCategory(element),
};
yield {
torrents: [parseTorrent(element)],
dom: [element as HTMLElement],
imdbId,
title,
year,
category: parseCategory(element),
};
} catch (e) {
console.trace(e);
logger.info(
"{0} Error occurred while parsing torrent: " + e,
this.name()
);
yield null;
}
}
}

Expand Down

0 comments on commit a75b569

Please sign in to comment.