Skip to content

Commit

Permalink
Give more information when title can be uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Dec 3, 2023
1 parent 8e3c6bb commit ef7c1eb
Show file tree
Hide file tree
Showing 33 changed files with 647 additions and 429 deletions.
284 changes: 167 additions & 117 deletions Find Unique Titles/dist/find.unique.titles.user.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Find Unique Titles/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "find.unique.titles",
"description": "Find unique titles to cross seed",
"version": "0.0.6",
"version": "0.0.7",
"author": {
"name": "Mea01"
},
Expand Down
3 changes: 2 additions & 1 deletion Find Unique Titles/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ You can generate it by running run `npm run dev`.
# Changelog
## 2023-12
- Add support for MTV
- Add support for using title and year when IMDB ID is not available. It only works with MTV and PTP right now
- Add support for using title and year when IMDB ID is not available when checking titles on PTP.
- The script now highlight the reason why a title can be uploaded
## 2023-11
- Some work is done to use IMDB Scout code for searching
- Add support for TSeeds
Expand Down
61 changes: 47 additions & 14 deletions Find Unique Titles/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as trackers from "./trackers";
import { tracker, Request, MetaData } from "./trackers/tracker";
import { existsInCache, addToCache, clearMemoryCache } from "./utils/cache";
import { MetaData, Request, SearchResult, tracker } from "./trackers/tracker";
import { addToCache, clearMemoryCache, existsInCache } from "./utils/cache";
import {
addCounter,
createTrackersSelect,
Expand All @@ -11,7 +11,7 @@ import {
import "./settings";
import { getSettings } from "./settings";
import { appendErrorMessage, showError } from "common/dom";
import { logger, LEVEL } from "common/logger"
import { LEVEL, logger } from "common/logger";

function hideTorrents(request: Request) {
for (let element of request.dom) {
Expand All @@ -23,18 +23,18 @@ function hideTorrents(request: Request) {
}

const setUpLogger = (debugMode: boolean) => {
logger.setPrefix("[Find Unique Titles]")
if (debugMode){
logger.setLevel(LEVEL.DEBUG)
logger.setPrefix("[Find Unique Titles]");
if (debugMode) {
logger.setLevel(LEVEL.DEBUG);
}
}
};

const main = async function () {
"use strict";

const settings = getSettings();

setUpLogger(settings.debug)
setUpLogger(settings.debug);

logger.info("Init User script");

Expand Down Expand Up @@ -78,19 +78,53 @@ const main = async function () {
updateCount(i++);
continue;
}
const response = await targetTracker.canUpload(
request,
settings.onlyNewTitles
);
const response = await targetTracker.search(request);
updateCount(i++);
if (!response) {
if (
response == SearchResult.EXIST ||
response == SearchResult.NOT_ALLOWED
) {
if (request.imdbId) {
await addToCache(targetTracker.name(), request.imdbId);
}
hideTorrents(request);
} else if (response == SearchResult.NOT_LOGGED_IN) {
alert(`You are not logged in ${targetTracker.name()}`);
break;
} else {
newContent++;
updateNewContent(newContent);
if (response == SearchResult.MAYBE_NOT_EXIST) {
request.dom[0].setAttribute(
"title",
"Title may not exist on target tracker"
);
request.dom[0].style.border = "2px solid #9b59b6";
} else if (response == SearchResult.NOT_EXIST_WITH_REQUEST) {
request.dom[0].setAttribute(
"title",
"Title was not found and has matching requests"
);
request.dom[0].style.border = "2px solid #2ecc71";
} else if (response == SearchResult.MAYBE_NOT_EXIST_WITH_REQUEST) {
request.dom[0].setAttribute(
"title",
"Title may not exists and there are matching requests"
);
request.dom[0].style.border = "2px solid #e67e22";
} else if (response == SearchResult.NOT_CHECKED) {
request.dom[0].setAttribute(
"title",
"Title was not checked on target tracker"
);
request.dom[0].style.border = "2px solid #e74c3c";
} else if (response != SearchResult.NOT_EXIST) {
request.dom[0].setAttribute(
"title",
"Title was not found on target tracker"
);
request.dom[0].style.border = "2px solid #3498db";
}
}
}
clearMemoryCache();
Expand All @@ -99,7 +133,6 @@ const main = async function () {
(sourceTracker as tracker).insertTrackersSelect(select);
};


appendErrorMessage();
main().catch((e) => {
showError(e.message);
Expand Down
15 changes: 9 additions & 6 deletions Find Unique Titles/src/trackers/Aither.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { parseSize } from "../utils/utils";
import { MetaData, Request, toGenerator, tracker } from "./tracker";
import { fetchAndParseHtml } from "common/http";
import { MetaData, Request, SearchResult, toGenerator, tracker } from "./tracker";
import { addChild, insertAfter } from "common/dom";
import { fetchAndParseHtml } from "common/http";


export default class Aither implements tracker {
canBeUsedAsSource(): boolean {
Expand Down Expand Up @@ -46,8 +47,8 @@ export default class Aither implements tracker {
return "Aither";
}

async canUpload(request: Request) {
if (!request.imdbId) return true;
async search(request: Request): Promise<SearchResult> {
if (!request.imdbId) return SearchResult.NOT_CHECKED;
const queryUrl =
"https://aither.xyz/torrents?perPage=25&imdbId=" +
request.imdbId +
Expand All @@ -57,7 +58,9 @@ export default class Aither implements tracker {

return result.textContent.includes(
"There is no result in database for query"
);
)
? SearchResult.NOT_EXIST
: SearchResult.EXIST;
}

insertTrackersSelect(select: HTMLElement): void {
Expand All @@ -69,4 +72,4 @@ export default class Aither implements tracker {
addChild(div, select);
insertAfter(div, parent.querySelector("h2"));
}
}
}
10 changes: 6 additions & 4 deletions Find Unique Titles/src/trackers/AvistaZ.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parseImdbIdFromLink } from "../utils/utils";
import { tracker, Request, MetaData, toGenerator } from "./tracker";
import { tracker, Request, MetaData, toGenerator, SearchResult } from "./tracker";
import { addChild } from "common/dom";
import { fetchAndParseHtml } from "common/http";

Expand Down Expand Up @@ -39,13 +39,15 @@ export default class AvistaZ implements tracker {
return "AvistaZ";
}

async canUpload(request: Request) {
if (!request.imdbId) return true;
async search(request: Request) : Promise<SearchResult> {
if (!request.imdbId) return SearchResult.NOT_CHECKED;
const queryUrl = "https://avistaz.to/movies?search=&imdb=" + request.imdbId;

const result = await fetchAndParseHtml(queryUrl);

return result.textContent?.includes("No Movie found!");
return result.textContent?.includes("No Movie found!")
? SearchResult.NOT_EXIST
: SearchResult.EXIST;
}

insertTrackersSelect(select: HTMLElement): void {
Expand Down
132 changes: 75 additions & 57 deletions Find Unique Titles/src/trackers/BHD.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,87 @@
import { parseImdbIdFromLink, parseResolution, parseSize } from "../utils/utils";
import { Category, MetaData, Request, toGenerator, Torrent, tracker } from "./tracker";
import {
parseImdbIdFromLink,
parseResolution,
parseSize,
} from "../utils/utils";
import {
Category,
MetaData,
Request,
SearchResult,
toGenerator,
Torrent,
tracker,
} from "./tracker";
import { insertBefore } from "common/dom";
import { fetchAndParseHtml } from "common/http";

const parseTorrents = (element: HTMLElement): Array<Torrent> => {
const torrents: Torrent[] = [];
element.querySelectorAll('tr[id^="resulttorrent"]').forEach((torrentElement) => {
const data = torrentElement.children[0].textContent.trim().split("/");
const size = parseSize(torrentElement.children[4].textContent.trim());
const tags = [];
if (torrentElement.textContent.includes("Remux")) {
tags.push("Remux");
}
const torrent: Torrent = {
container: data[0].trim(),
format: data[1].trim(),
resolution: data[3].trim(),
tags: tags,
size,
dom: torrentElement as HTMLElement,
};
torrents.push(torrent);
});
element
.querySelectorAll('tr[id^="resulttorrent"]')
.forEach((torrentElement) => {
const data = torrentElement.children[0].textContent.trim().split("/");
const size = parseSize(torrentElement.children[4].textContent.trim());
const tags = [];
if (torrentElement.textContent.includes("Remux")) {
tags.push("Remux");
}
const torrent: Torrent = {
container: data[0].trim(),
format: data[1].trim(),
resolution: data[3].trim(),
tags: tags,
size,
dom: torrentElement as HTMLElement,
};
torrents.push(torrent);
});
return torrents;
};

const parseCategory = (element: Element) => {
const html = element.children[0].innerHTML
if (html.includes("categories/tv")) return Category.TV
else if (html.includes("categories/movies")) return Category.MOVIE
const html = element.children[0].innerHTML;
if (html.includes("categories/tv")) return Category.TV;
else if (html.includes("categories/movies")) return Category.MOVIE;
return undefined;
}
};

const parseTorrentsFromTorrentsPage = (): Array<Request> => {
const requests = [];
document.querySelectorAll('tr[id^="torrentposter"]').forEach((element: HTMLElement) => {
let imdbId = null;
let libraryId = element.getAttribute("library");
if (libraryId) {
let imdbElement = document.querySelector(`#librarydiv${libraryId}`);
if (imdbElement) {
imdbId = parseImdbIdFromLink(imdbElement as HTMLElement)
document
.querySelectorAll('tr[id^="torrentposter"]')
.forEach((element: HTMLElement) => {
let imdbId = null;
let libraryId = element.getAttribute("library");
if (libraryId) {
let imdbElement = document.querySelector(`#librarydiv${libraryId}`);
if (imdbElement) {
imdbId = parseImdbIdFromLink(imdbElement as HTMLElement);
}
}
}
const tags = [];
const torrentName = element.children[1].querySelector('a[id^="torrent"]').textContent
if (torrentName.toUpperCase().includes("REMUX")) {
tags.push("Remux");
}
const torrent: Torrent = {
dom: element,
size: parseSize(element.children[5].textContent),
tags: tags,
resolution: parseResolution(torrentName)

}
const torrents = [torrent]

const request: Request = {
torrents: torrents,
dom: [element],
imdbId,
title: "",
category: parseCategory(element)
};
requests.push(request);
});
const tags = [];
const torrentName =
element.children[1].querySelector('a[id^="torrent"]').textContent;
if (torrentName.toUpperCase().includes("REMUX")) {
tags.push("Remux");
}
const torrent: Torrent = {
dom: element,
size: parseSize(element.children[5].textContent),
tags: tags,
resolution: parseResolution(torrentName),
};
const torrents = [torrent];

const request: Request = {
torrents: torrents,
dom: [element],
imdbId,
title: "",
category: parseCategory(element),
};
requests.push(request);
});
return requests;
};

Expand Down Expand Up @@ -119,14 +135,16 @@ export default class BHD implements tracker {
return "BHD";
}

async canUpload(request: Request) {
if (!request.imdbId) return true;
async search(request: Request): Promise<SearchResult> {
if (!request.imdbId) return SearchResult.NOT_CHECKED;
const queryUrl =
"https://beyond-hd.me/library/movies?activity=&q=" + request.imdbId;

const result = await fetchAndParseHtml(queryUrl);

return result.querySelectorAll(".bhd-meta-box").length === 0;
return result.querySelectorAll(".bhd-meta-box").length === 0
? SearchResult.NOT_EXIST
: SearchResult.EXIST;
}

insertTrackersSelect(select: HTMLElement): void {
Expand Down
18 changes: 13 additions & 5 deletions Find Unique Titles/src/trackers/BLU.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { parseSize } from "../utils/utils";
import { MetaData, Request, toGenerator, tracker } from "./tracker";
import { fetchAndParseHtml } from "common/http";
import {
MetaData,
Request,
SearchResult,
toGenerator,
tracker,
} from "./tracker";
import { addChild } from "common/dom";
import { fetchAndParseHtml } from "common/http";

export default class BLU implements tracker {
canBeUsedAsSource(): boolean {
Expand Down Expand Up @@ -48,16 +54,18 @@ export default class BLU implements tracker {
return "BLU";
}

async canUpload(request: Request) {
if (!request.imdbId) return true;
async search(request: Request): Promise<SearchResult> {
if (!request.imdbId) return SearchResult.NOT_CHECKED;
const queryUrl =
"https://blutopia.xyz/torrents?perPage=25&imdbId=" +
request.imdbId +
"&sortField=size";

const result = await fetchAndParseHtml(queryUrl);

return result.querySelector(".torrent-listings-no-result") !== null;
return result.querySelector(".torrent-listings-no-result") !== null
? SearchResult.NOT_EXIST
: SearchResult.EXIST;
}

insertTrackersSelect(select: HTMLElement): void {
Expand Down
Loading

0 comments on commit ef7c1eb

Please sign in to comment.