Skip to content

Commit

Permalink
Improve CLAN-SUD
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Dec 16, 2023
1 parent 830e37a commit f4bd176
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 70 deletions.
66 changes: 41 additions & 25 deletions Find Unique Titles/dist/find.unique.titles.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@
(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;
if (null == item) {
(0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateCount)(i++);
continue;
}
const request = item;
common_logger__WEBPACK_IMPORTED_MODULE_0__.logger.debug("[{0}] Search request: {1}", sourceTracker.name(), request);
try {
Expand All @@ -104,7 +107,7 @@
continue;
}
const response = await targetTracker.search(request);
(0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateCount)(i++);
common_logger__WEBPACK_IMPORTED_MODULE_0__.logger.debug("Search response: {0}", response);
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);
Expand Down Expand Up @@ -139,6 +142,8 @@
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";
} finally {
(0, _utils_dom__WEBPACK_IMPORTED_MODULE_3__.updateCount)(i++);
}
}
(0, _utils_cache__WEBPACK_IMPORTED_MODULE_4__.clearMemoryCache)();
Expand Down Expand Up @@ -718,26 +723,36 @@
return url.includes("www.clan-sudamerica.net/invision/") && !url.includes("forums/topic/");
}
async* getSearchRequest() {
const topics = document.querySelectorAll('div[data-tableid="topics"] table');
const topics = Array.from(document.querySelectorAll('div[data-tableid="topics"] table')).filter((topic => {
if (null != topic.getAttribute("bgColor") && null != !topic.getAttribute("bgcolor")) return false;
if (0 === topic.querySelectorAll("img").length) return false;
if (3 != topic.querySelectorAll("img").length) return false;
if ("peliscr.jpg" !== topic.querySelectorAll("img")[2].alt) {
topic.style.display = "none";
return false;
}
return true;
}));
yield {
total: topics.length
};
for (const topic of topics) {
if (null != topic.getAttribute("bgColor") && null != !topic.getAttribute("bgcolor")) continue;
if (0 === topic.querySelectorAll("img").length) continue;
if (3 != topic.querySelectorAll("img").length) continue;
if ("peliscr.jpg" !== topic.querySelectorAll("img")[2].alt) {
topic.style.display = "none";
continue;
}
const link = topic.querySelector("a").href;
let response = await (0, common_http__WEBPACK_IMPORTED_MODULE_0__.fetchAndParseHtml)(link);
const imdbId = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseImdbIdFromLink)(response);
const fullTitle = topic.querySelectorAll("tr td")[1]?.textContent?.trim()?.split("\n")[0];
const {title, year} = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseYearAndTitle)(fullTitle);
const request = {
torrents: [],
torrents: [ {
resolution: (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseResolution)(fullTitle),
tags: [],
dom: topic
} ],
dom: [ topic ],
imdbId,
title: ""
title,
year,
category: _tracker__WEBPACK_IMPORTED_MODULE_2__.Category.MOVIE
};
yield request;
}
Expand All @@ -749,7 +764,8 @@
return _tracker__WEBPACK_IMPORTED_MODULE_2__.SearchResult.NOT_CHECKED;
}
insertTrackersSelect(select) {
(0, common_dom__WEBPACK_IMPORTED_MODULE_3__.insertBefore)(select, document.querySelector('div[data-tableid="topics"]'));
const parent = document.querySelector('div[data-tableid="topics"]');
if (parent) (0, common_dom__WEBPACK_IMPORTED_MODULE_3__.insertBefore)(select, parent);
}
}
},
Expand Down Expand Up @@ -1591,7 +1607,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);
let searchResultsCount = result.querySelector("span.search-form__footer__results");
if (searchResultsCount) {
if (searchResultsCount && "0" !== searchResultsCount.textContent?.trim()?.split(" ")[0]) {
common_logger__WEBPACK_IMPORTED_MODULE_2__.logger.debug("[PTP] Multiple results found: {0}", searchResultsCount.textContent);
const torrentsData = extractJsonData(result);
for (let movie of torrentsData.Movies) {
Expand Down Expand Up @@ -1690,7 +1706,7 @@
}
}
}
console.error(`No script element containing '${variableName}' found.`);
console.error("No script element containing PageData found.");
return null;
}
__webpack_async_result__();
Expand Down Expand Up @@ -2313,15 +2329,15 @@
return Category;
}({});
let SearchResult = function(SearchResult) {
SearchResult[SearchResult.EXIST = 0] = "EXIST";
SearchResult[SearchResult.EXIST_BUT_MISSING_SLOT = 1] = "EXIST_BUT_MISSING_SLOT";
SearchResult[SearchResult.NOT_EXIST = 2] = "NOT_EXIST";
SearchResult[SearchResult.MAYBE_NOT_EXIST = 3] = "MAYBE_NOT_EXIST";
SearchResult[SearchResult.NOT_EXIST_WITH_REQUEST = 4] = "NOT_EXIST_WITH_REQUEST";
SearchResult[SearchResult.MAYBE_NOT_EXIST_WITH_REQUEST = 5] = "MAYBE_NOT_EXIST_WITH_REQUEST";
SearchResult[SearchResult.NOT_CHECKED = 6] = "NOT_CHECKED";
SearchResult[SearchResult.NOT_LOGGED_IN = 7] = "NOT_LOGGED_IN";
SearchResult[SearchResult.NOT_ALLOWED = 8] = "NOT_ALLOWED";
SearchResult.EXIST = "EXIST";
SearchResult.EXIST_BUT_MISSING_SLOT = "EXIST_BUT_MISSING_SLOT";
SearchResult.NOT_EXIST = "NOT_EXIST";
SearchResult.MAYBE_NOT_EXIST = "MAYBE_NOT_EXIST";
SearchResult.NOT_EXIST_WITH_REQUEST = "NOT_EXIST_WITH_REQUEST";
SearchResult.MAYBE_NOT_EXIST_WITH_REQUEST = "MAYBE_NOT_EXIST_WITH_REQUEST";
SearchResult.NOT_CHECKED = "NOT_CHECKED";
SearchResult.NOT_LOGGED_IN = "NOT_LOGGED_IN";
SearchResult.NOT_ALLOWED = "NOT_ALLOWED";
return SearchResult;
}({});
const toGenerator = async function*(requests) {
Expand Down Expand Up @@ -2519,7 +2535,7 @@
return tags;
};
const parseYearAndTitle = title => {
const regex = /^(.*?)\s+(\d{4})\s+(.*)$/;
const regex = /^(.*?)\s+\(?(\d{4})\)?\s+(.*)/;
const match = title.match(regex);
if (match) {
const title = match[1].trim();
Expand Down
9 changes: 7 additions & 2 deletions Find Unique Titles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ 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;
if (item == null) {
updateCount(i++);
continue;
}
const request = item as Request;
logger.debug(
`[{0}] Search request: {1}`,
Expand All @@ -88,7 +91,7 @@ const main = async function () {
continue;
}
const response = await targetTracker.search(request);
updateCount(i++);
logger.debug("Search response: {0}", response)
if (
response == SearchResult.EXIST ||
response == SearchResult.NOT_ALLOWED
Expand Down Expand Up @@ -149,6 +152,8 @@ const main = async function () {
"Title was not checked due to an error"
);
request.dom[0].style.border = "2px solid red";
} finally {
updateCount(i++);
}
}
clearMemoryCache();
Expand Down
64 changes: 41 additions & 23 deletions Find Unique Titles/src/trackers/CLAN-SUD.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseImdbIdFromLink } from "../utils/utils";
import { MetaData, Request, SearchResult, tracker } from "./tracker";
import { parseImdbIdFromLink, parseResolution, parseYearAndTitle } from "../utils/utils";
import { MetaData, Request, SearchResult, tracker, Category } from "./tracker";
import { insertBefore } from "common/dom";
import { fetchAndParseHtml } from "common/http";

Expand All @@ -20,35 +20,53 @@ export default class CLANSUD implements tracker {
}

async *getSearchRequest(): AsyncGenerator<MetaData | Request, void, void> {
const requests: Array<Request> = [];
const topics = document.querySelectorAll(
'div[data-tableid="topics"] table'
);
yield {
total: topics.length,
};
for (const topic of topics) {
const topics = (
Array.from(
document.querySelectorAll('div[data-tableid="topics"] table')
) as Array<HTMLElement>
).filter((topic) => {
if (
topic.getAttribute("bgColor") != null &&
!topic.getAttribute("bgcolor") != null
) {
continue;
return false;
}
if (topic.querySelectorAll("img").length === 0) {
return false;
}
if (topic.querySelectorAll("img").length === 0) continue;

if (topic.querySelectorAll("img").length != 3) continue;
if (topic.querySelectorAll("img").length != 3) {
return false;
}
if (topic.querySelectorAll("img")[2].alt !== "peliscr.jpg") {
(topic as HTMLElement).style.display = "none";
continue;
topic.style.display = "none";
return false;
}
return true;
});
yield {
total: topics.length,
};
for (const topic of topics) {
const link = (topic.querySelector("a") as HTMLAnchorElement).href;
let response = await fetchAndParseHtml(link);
const imdbId = parseImdbIdFromLink(response);
const fullTitle = topic
.querySelectorAll("tr td")!![1]
?.textContent?.trim()
?.split("\n")[0];
const { title, year } = parseYearAndTitle(fullTitle);
const request: Request = {
torrents: [],
dom: [topic as HTMLElement],
torrents: [{
resolution: parseResolution(fullTitle),
tags: [],
dom: topic
}],
dom: [topic],
imdbId,
title: "",
title,
year,
category: Category.MOVIE,
};
yield request;
}
Expand All @@ -63,9 +81,9 @@ export default class CLANSUD implements tracker {
}

insertTrackersSelect(select: HTMLElement): void {
insertBefore(
select,
document.querySelector('div[data-tableid="topics"]') as HTMLElement
);
const parent = document.querySelector(
'div[data-tableid="topics"]'
) as HTMLElement;
if (parent) insertBefore(select, parent);
}
}
}
20 changes: 10 additions & 10 deletions Find Unique Titles/src/trackers/PTP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
parseImdbIdFromLink,
parseResolution,
parseSize,
parseTags,
parseTags
} from "../utils/utils";
import {
Category,
Expand All @@ -14,7 +14,7 @@ import {
SearchResult,
toGenerator,
Torrent,
tracker,
tracker
} from "./tracker";
import { findFirst, insertBefore } from "common/dom";
import { fetchAndParseHtml } from "common/http";
Expand Down Expand Up @@ -51,7 +51,7 @@ const parseTorrents = (element: HTMLElement) => {
dom: [element],
size,
tags,
resolution,
resolution
};
torrents.push(torrent);
});
Expand Down Expand Up @@ -110,7 +110,7 @@ export default class PTP implements tracker {
return url.includes("passthepopcorn.me");
}

async *getSearchRequest(): AsyncGenerator<MetaData | Request, void, void> {
async* getSearchRequest(): AsyncGenerator<MetaData | Request, void, void> {
const requests: Array<Request> = [];
const nodes = findFirst(
document,
Expand All @@ -134,7 +134,7 @@ export default class PTP implements tracker {
dom: [element as HTMLElement],
imdbId,
title: "",
category: parseCategory(element),
category: parseCategory(element)
};
requests.push(request);
});
Expand Down Expand Up @@ -171,7 +171,7 @@ export default class PTP implements tracker {
let searchResultsCount = result.querySelector(
"span.search-form__footer__results"
);
if (searchResultsCount) {
if (searchResultsCount && searchResultsCount.textContent?.trim()?.split(" ")[0] !== "0") {
logger.debug(
"[PTP] Multiple results found: {0}",
searchResultsCount.textContent
Expand All @@ -190,7 +190,7 @@ export default class PTP implements tracker {
size: parseSize(torrent["Size"]),
tags: parseTags(torrent["Title"]),
resolution: parseResolution(torrent["Title"]),
container: parseCodec(torrent["Title"]),
container: parseCodec(torrent["Title"])
});
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ export default class PTP implements tracker {

const parseAvailableTorrents = (result: HTMLElement): Array<Torrent> => {
const lines = Array.from(
result.querySelectorAll('#torrent-table tr[id^="group_torrent_header_"]')
result.querySelectorAll("#torrent-table tr[id^=\"group_torrent_header_\"]")
);
return parseTorrentsFromLines(lines);
};
Expand All @@ -275,7 +275,7 @@ const parseTorrentsFromLines = (lines: Array<Element>) => {
resolution: parseResolution(data[3].trim()),
tags: tags,
size,
dom: line as HTMLElement,
dom: line as HTMLElement
};
torrents.push(torrent);
}
Expand Down Expand Up @@ -353,6 +353,6 @@ function extractJsonData(doc: Element) {
}
}

console.error(`No script element containing '${variableName}' found.`);
console.error(`No script element containing PageData found.`);
return null;
}
18 changes: 9 additions & 9 deletions Find Unique Titles/src/trackers/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ export interface MetaData {
}

export enum SearchResult {
EXIST,
EXIST_BUT_MISSING_SLOT,
NOT_EXIST,
MAYBE_NOT_EXIST,
NOT_EXIST_WITH_REQUEST,
MAYBE_NOT_EXIST_WITH_REQUEST,
NOT_CHECKED,
NOT_LOGGED_IN,
NOT_ALLOWED,
EXIST = "EXIST",
EXIST_BUT_MISSING_SLOT = "EXIST_BUT_MISSING_SLOT",
NOT_EXIST = "NOT_EXIST",
MAYBE_NOT_EXIST = "MAYBE_NOT_EXIST",
NOT_EXIST_WITH_REQUEST = "NOT_EXIST_WITH_REQUEST",
MAYBE_NOT_EXIST_WITH_REQUEST = "MAYBE_NOT_EXIST_WITH_REQUEST",
NOT_CHECKED = "NOT_CHECKED",
NOT_LOGGED_IN = "NOT_LOGGED_IN",
NOT_ALLOWED = "NOT_ALLOWED",
}

export interface tracker {
Expand Down
2 changes: 1 addition & 1 deletion Find Unique Titles/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const parseTags = (title: string) => {
};

export const parseYearAndTitle = (title: string) => {
const regex = /^(.*?)\s+(\d{4})\s+(.*)$/;
const regex = /^(.*?)\s+\(?(\d{4})\)?\s+(.*)/;
const match = title.match(regex);

if (match) {
Expand Down

0 comments on commit f4bd176

Please sign in to comment.