Skip to content

Commit

Permalink
Improve IPT
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Dec 17, 2023
1 parent cc1ac67 commit 89bf02e
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 90 deletions.
2 changes: 1 addition & 1 deletion Find Unique Titles/config/userscript.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const UserScriptConfig: IWebpackUserScript = {
"https://filelist.io/browse.php*",
"https://jptv.club/torrents*",
"https://hd-torrents.org/torrents.php*",
"https://iptorrents.com/movies*",
"https://iptorrents.com/t?*",
"https://kp.m-team.cc/*",
"https://ncore.pro/torrents.php*",
"https://greatposterwall.com/torrents.php*",
Expand Down
124 changes: 88 additions & 36 deletions Find Unique Titles/dist/find.unique.titles.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
// @match https://filelist.io/browse.php*
// @match https://jptv.club/torrents*
// @match https://hd-torrents.org/torrents.php*
// @match https://iptorrents.com/movies*
// @match https://iptorrents.com/t?*
// @match https://kp.m-team.cc/*
// @match https://ncore.pro/torrents.php*
// @match https://greatposterwall.com/torrents.php*
Expand Down Expand Up @@ -1138,9 +1138,23 @@
__webpack_require__.d(__webpack_exports__, {
default: () => CG
});
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_2__ = __webpack_require__("../common/dist/dom/index.mjs");
var _utils_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("./src/utils/utils.ts");
var _tracker__WEBPACK_IMPORTED_MODULE_0__ = __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");
const parseCategory = element => {
let categoryImg = element.children[0].querySelector("img");
const categoryLogo = categoryImg.src;
const alt = categoryImg.alt;
if (categoryLogo.includes("Movies-") || alt.includes("Movie")) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MOVIE;
if (categoryLogo.includes("TV-")) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.TV;
if (categoryLogo.includes("Music-")) return _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MUSIC;
};
const parseYear = title => {
const regex = /-(\d{4})-/;
const match = title.match(regex);
if (match) return match[1];
};
class CG {
canBeUsedAsSource() {
return true;
Expand All @@ -1149,32 +1163,69 @@
return false;
}
canRun(url) {
return url.includes("iptorrents.com/movies");
return url.includes("ptorrents.com/t?");
}
async* getSearchRequest() {
const requests = [];
document.querySelectorAll(".mBox table")?.forEach((element => {
const imdbId = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_0__.parseImdbIdFromLink)(element);
const request = {
torrents: [],
dom: [ element.parentElement ],
imdbId,
title: ""
const elements = Array.from(document.querySelectorAll("#torrents tbody tr"));
yield {
total: elements.length
};
for (let element of elements) {
const category = parseCategory(element);
let request = {
dom: [ element ],
category
};
requests.push(request);
}));
yield* (0, _tracker__WEBPACK_IMPORTED_MODULE_1__.toGenerator)(requests);
const link = element.children[1].querySelector("a");
const torrentTitle = link?.textContent;
const size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseSize)(element.children[5].textContent);
if (category == _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MOVIE) {
let response = await (0, common_http__WEBPACK_IMPORTED_MODULE_2__.fetchAndParseHtml)(link.href);
const imdbId = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseImdbIdFromLink)(response);
const {year, title} = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseYearAndTitle)(torrentTitle);
request = {
...request,
torrents: [ {
dom: element,
size,
resolution: (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseResolution)(torrentTitle),
tags: (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseTags)(torrentTitle)
} ],
year,
imdbId,
title
};
} else if (category == _tracker__WEBPACK_IMPORTED_MODULE_0__.Category.MUSIC) {
const splittedTitle = torrentTitle.split("-");
const artists = [ splittedTitle[0] ];
const titles = [ splittedTitle[1] ];
const year = parseYear(torrentTitle);
const {container, format} = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseContainerAndFormat)(torrentTitle);
request = {
...request,
torrents: [ {
dom: element,
size,
format,
container
} ],
artists,
titles,
year,
type: _tracker__WEBPACK_IMPORTED_MODULE_0__.MusicReleaseType.ALBUM
};
}
yield request;
}
}
name() {
return "IPT";
}
async search(request) {
return _tracker__WEBPACK_IMPORTED_MODULE_1__.SearchResult.NOT_CHECKED;
return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_CHECKED;
}
insertTrackersSelect(select) {
const element = document.createElement("p");
(0, common_dom__WEBPACK_IMPORTED_MODULE_2__.addChild)(element, select);
(0, common_dom__WEBPACK_IMPORTED_MODULE_2__.insertAfter)(element, document.querySelector('.mBox form input[name="q"]').closest("p"));
(0, common_dom__WEBPACK_IMPORTED_MODULE_3__.insertAfter)(select, document.querySelector('input[name="q"]'));
}
}
},
Expand Down Expand Up @@ -1246,24 +1297,10 @@
if ("TV-Music" == type) return _tracker__WEBPACK_IMPORTED_MODULE_0__.MusicReleaseType.TV_MUSIC;
return null;
};
const parseContainer = element => {
const text = element.textContent.trim();
const containers = [ "FLAC", "MP3" ];
const formats = [ "Lossless", "320", "V0" ];
let result = {};
for (let container of containers) if (text.includes(container)) result = {
container
};
for (let format of formats) if (text.includes(format)) result = {
...result,
format
};
return result;
};
const parseTorrents = element => {
if (element.classList.contains("torrent_redline")) {
const size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseSize)(element.children[6].textContent);
const {format, container} = parseContainer(element.children[3]);
const {format, container} = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseContainerAndFormat)(element.children[3].textContent.trim());
return [ {
size,
dom: element,
Expand All @@ -1274,7 +1311,7 @@
const groupId = element.querySelector('a[title*="View Torrent"]').href.split("id=")[1];
return Array.from(document.querySelectorAll(`tr.groupid_${groupId}`)).map((element => {
const size = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseSize)(element.children[3].textContent);
const {format, container} = parseContainer(element.children[0]);
const {format, container} = (0, _utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseContainerAndFormat)(element.children[0].textContent.trim());
return {
size,
dom: element,
Expand Down Expand Up @@ -2012,6 +2049,7 @@
if (musicRequest.type != _tracker__WEBPACK_IMPORTED_MODULE_0__.MusicReleaseType.ALBUM && musicRequest.type != _tracker__WEBPACK_IMPORTED_MODULE_0__.MusicReleaseType.SINGLE) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_ALLOWED;
if (!musicRequest.artists || !musicRequest.titles || !musicRequest.year) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.NOT_CHECKED;
for (let artist of musicRequest.artists) for (let title of musicRequest.titles) {
if ("VA" === artist) artist = "";
const queryUrl = `https://redacted.ch/torrents.php?artistname=${encodeURIComponent(artist)}&groupname=${encodeURIComponent(title)}&year=${musicRequest.year}&order_by=time&order_way=desc&group_results=1&filter_cat%5B1%5D=1&action=advanced&searchsubmit=1`;
const result = await (0, common_http__WEBPACK_IMPORTED_MODULE_1__.fetchAndParseHtml)(queryUrl);
if (!result.textContent?.includes("Your search did not match anything.")) return _tracker__WEBPACK_IMPORTED_MODULE_0__.SearchResult.EXIST;
Expand Down Expand Up @@ -2639,6 +2677,7 @@
"./src/utils/utils.ts": (__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.d(__webpack_exports__, {
parseCodec: () => parseCodec,
parseContainerAndFormat: () => parseContainerAndFormat,
parseImdbId: () => parseImdbId,
parseImdbIdFromLink: () => parseImdbIdFromLink,
parseResolution: () => parseResolution,
Expand Down Expand Up @@ -2740,6 +2779,19 @@
year: void 0
};
};
const parseContainerAndFormat = text => {
const containers = [ "FLAC", "MP3" ];
const formats = [ "Lossless", "320", "V0" ];
let result = {};
for (let container of containers) if (text.includes(container)) result = {
container
};
for (let format of formats) if (text.includes(format)) result = {
...result,
format
};
return result;
};
},
"../common/dist/dom/index.mjs": (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
__webpack_require__.d(__webpack_exports__, {
Expand Down
111 changes: 88 additions & 23 deletions Find Unique Titles/src/trackers/IPT.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import { parseImdbIdFromLink } from "../utils/utils";
import {
parseContainerAndFormat,
parseImdbIdFromLink,
parseResolution,
parseSize,
parseTags,
parseYearAndTitle,
} from "../utils/utils";
import {
Category,
MetaData,
MusicReleaseType,
Request,
SearchResult,
toGenerator,
tracker,
} from "./tracker";
import { addChild, insertAfter } from "common/dom";
import { insertAfter } from "common/dom";
import { fetchAndParseHtml } from "common/http";

const parseCategory = (element: HTMLElement): Category => {
let categoryImg = element.children[0].querySelector("img")!!;
const categoryLogo = categoryImg.src!!;
const alt = categoryImg.alt
if (categoryLogo.includes("Movies-") || alt.includes("Movie")) return Category.MOVIE;
if (categoryLogo.includes("TV-")) return Category.TV;
if (categoryLogo.includes("Music-")) return Category.MUSIC;
};
const parseYear = (title: string) => {
const regex = /-(\d{4})-/;
const match = title.match(regex);
if (match) return match[1];
};
export default class CG implements tracker {
canBeUsedAsSource(): boolean {
return true;
Expand All @@ -18,23 +40,70 @@ export default class CG implements tracker {
}

canRun(url: string): boolean {
return url.includes("iptorrents.com/movies");
return url.includes("ptorrents.com/t?");
}

async *getSearchRequest(): AsyncGenerator<MetaData | Request, void, void> {
const requests: Array<Request> = [];
document.querySelectorAll(".mBox table")?.forEach((element) => {
const imdbId = parseImdbIdFromLink(element as HTMLElement);
const request: Request = {
torrents: [],
dom: [element!!.parentElement as HTMLElement],
imdbId,
title: "",
const elements = Array.from(
document.querySelectorAll("#torrents tbody tr")
) as Array<HTMLElement>;
yield {
total: elements.length,
};
for (let element of elements) {
const category = parseCategory(element);
let request: Request = {
dom: [element as HTMLElement],
category,
};
requests.push(request);
});

yield* toGenerator(requests);
const link: HTMLAnchorElement | null =
element.children[1].querySelector("a");
const torrentTitle = link?.textContent!!;
const size = parseSize(element.children[5].textContent);
if (category == Category.MOVIE) {
let response = await fetchAndParseHtml(
(link as HTMLAnchorElement).href
);
const imdbId = parseImdbIdFromLink(response as HTMLElement);
const { year, title } = parseYearAndTitle(torrentTitle);
request = {
...request,
torrents: [
{
dom: element,
size,
resolution: parseResolution(torrentTitle),
tags: parseTags(torrentTitle),
},
],
year,
imdbId,
title,
};
} else if (category == Category.MUSIC) {
const splittedTitle = torrentTitle.split("-")!!;
const artists = [splittedTitle[0]];
const titles = [splittedTitle[1]];
const year = parseYear(torrentTitle);
const { container, format } = parseContainerAndFormat(torrentTitle);
request = {
...request,
torrents: [
{
dom: element,
size,
format,
container,
},
],
artists,
titles,
year,
type: MusicReleaseType.ALBUM,
};
}
yield request;
}
}

name(): string {
Expand All @@ -46,13 +115,9 @@ export default class CG implements tracker {
}

insertTrackersSelect(select: HTMLElement): void {
const element = document.createElement("p");
addChild(element, select);
insertAfter(
element,
document
.querySelector('.mBox form input[name="q"]')!!
.closest("p") as HTMLElement
select,
document.querySelector('input[name="q"]') as HTMLElement
);
}
}
}
35 changes: 5 additions & 30 deletions Find Unique Titles/src/trackers/JPop.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseSize } from "../utils/utils";
import { parseContainerAndFormat, parseSize } from "../utils/utils";
import { Category, MetaData, MusicReleaseType, MusicRequest, Request, SearchResult, Torrent, tracker } from "./tracker";
import { insertBefore } from "common/dom";

Expand All @@ -15,36 +15,11 @@ const parseType = (element: HTMLElement) => {

return null;
};
const parseContainer = (
element: HTMLElement
): { container?: string; format?: string } => {
const text = element.textContent!!.trim();
const containers = ["FLAC", "MP3"];
const formats = ["Lossless", "320", "V0"];
let result = {};
for (let container of containers) {
if (text.includes(container)) {
result = {
container,
};
}
}
for (let format of formats) {
if (text.includes(format)) {
result = {
...result,
format,
};
}
}

return result;
};
const parseTorrents = (element: HTMLElement): Array<Torrent> => {
if (element.classList.contains("torrent_redline")) {
const size = parseSize(element.children[6].textContent);
const { format, container } = parseContainer(
element.children[3]!! as HTMLElement
const { format, container } = parseContainerAndFormat(
element.children[3]!!.textContent!!.trim()
);
return [
{
Expand All @@ -61,8 +36,8 @@ const parseTorrents = (element: HTMLElement): Array<Torrent> => {
return Array.from(document.querySelectorAll(`tr.groupid_${groupId}`)).map(
(element) => {
const size = parseSize(element.children[3].textContent);
const { format, container } = parseContainer(
element.children[0] as HTMLElement
const { format, container } = parseContainerAndFormat(
element.children[0].textContent!!.trim()
);
return {
size,
Expand Down
Loading

0 comments on commit 89bf02e

Please sign in to comment.