Skip to content

Commit

Permalink
Make PTP works on seeding page
Browse files Browse the repository at this point in the history
  • Loading branch information
Morea committed Oct 22, 2023
1 parent 0d597d0 commit a531fdd
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 59 deletions.
87 changes: 50 additions & 37 deletions Find Unique Titles/dist/find.unique.titles.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Find Unique Titles
// @description Find unique titles to cross seed
// @version 0.0.1
// @version 0.0.2
// @author Mea01
// @match https://cinemageddon.net/browse.php*
// @match https://karagarga.in/browse.php*
Expand Down Expand Up @@ -1714,7 +1714,7 @@ class KG {
canUpload(request) {
return _asyncToGenerator(function* () {
if (!request.imdbId) return true;
var queryUrl = "https://karagarga.in/browse.php?sort=size&search=" + request.imdbId + "&search_type=imdb&d=DESC";
var queryUrl = "https://karagarga.in/browse.php?sort=added&search=".concat(request.imdbId.replace("", ""), "&search_type=imdb&d=DESC");
var result = yield common__WEBPACK_IMPORTED_MODULE_2__["default"].http.fetchAndParseHtml(queryUrl);
return result.querySelector("tr.oddrow") === null;
})();
Expand Down Expand Up @@ -1906,6 +1906,9 @@ function isSupportedCategory(category) {
}
var parseTorrents = element => {
var torrents = [];
if (element.classList.contains("cover-movie-list__movie")) {
return [];
}
element.querySelectorAll("tr.basic-movie-list__torrent-row").forEach(element => {
if (element.querySelector(".basic-movie-list__torrent-edition")) {
return;
Expand All @@ -1928,7 +1931,11 @@ var parseTorrents = element => {
return torrents;
};
var parseCategory = element => {
var categoryTitle = element.querySelector(".basic-movie-list__torrent-edition__main").textContent;
var _element$querySelecto;
var categoryTitle = (_element$querySelecto = element.querySelector(".basic-movie-list__torrent-edition__main")) === null || _element$querySelecto === void 0 ? void 0 : _element$querySelecto.textContent;
if (!categoryTitle) {
return null;
}
if (categoryTitle.includes("Stand-up Comedy ")) {
return _tracker__WEBPACK_IMPORTED_MODULE_2__.Category.STAND_UP;
} else if (categoryTitle.includes("Live Performance ")) {
Expand All @@ -1949,10 +1956,11 @@ class PTP {
}
getSearchRequest() {
return _wrapAsyncGenerator(function* () {
var _document$querySelect;
var requests = [];
(_document$querySelect = document.querySelectorAll("#torrents-movie-view table.torrent_table > tbody")) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.forEach(element => {
var imdbId = (0,_utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseImdbIdFromLink)(element.querySelector(".basic-movie-list__movie__ratings-and-tags"));
var nodes = common__WEBPACK_IMPORTED_MODULE_3__["default"].dom.findFirst("#torrents-movie-view table.torrent_table > tbody", ".cover-movie-list__movie");
nodes === null || nodes === void 0 ? void 0 : nodes.forEach(element => {
var elements = common__WEBPACK_IMPORTED_MODULE_3__["default"].dom.findFirst(".basic-movie-list__movie__ratings-and-tags", ".cover-movie-list__movie__rating-and-tags");
var imdbId = elements ? (0,_utils_utils__WEBPACK_IMPORTED_MODULE_1__.parseImdbIdFromLink)(elements[0]) : null;
var request = {
torrents: parseTorrents(element),
dom: element,
Expand Down Expand Up @@ -2894,26 +2902,6 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _trim21_gm_fetch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @trim21/gm-fetch */ "../node_modules/@trim21/gm-fetch/dist/index.mjs");


const parser = new DOMParser();
const fetchUrl = async (url, wait = 1000) => {
await sleep(wait);
const res = await (0,_trim21_gm_fetch__WEBPACK_IMPORTED_MODULE_0__["default"])(url);
return await res.text();
};
const fetchAndParseHtml = async (query_url) => {
const response = await fetchUrl(query_url);
return parser.parseFromString(response, "text/html").body;
};
const sleep = (ms) => {
return new Promise(resolve => setTimeout(resolve, ms));
};

var http = /*#__PURE__*/Object.freeze({
__proto__: null,
fetchAndParseHtml: fetchAndParseHtml,
fetchUrl: fetchUrl
});

const insertBefore = (newNode, existingNode) => {
existingNode.parentNode.insertBefore(newNode, existingNode);
};
Expand All @@ -2924,10 +2912,11 @@ const addChild = (parent, child) => {
parent.appendChild(child);
};
const appendErrorMessage = () => {
const div = document.createElement('div');
div.innerHTML = '<span style="margin-left:15px;color:white;font-weight:bold;float:right;font-size:22px;line-height:20px;cursor:pointer;transition:0.3s;\n" onclick="this.parentElement.style.display=\'none\';">&times;</span>' +
'<span id="message"></span>';
div.style.position = 'fixed';
const div = document.createElement("div");
div.innerHTML =
'<span style="margin-left:15px;color:white;font-weight:bold;float:right;font-size:22px;line-height:20px;cursor:pointer;transition:0.3s;\n" onclick="this.parentElement.style.display=\'none\';">&times;</span>' +
'<span id="message"></span>';
div.style.position = "fixed";
div.style.bottom = "50px";
div.style.left = "50%";
div.style.display = "none";
Expand All @@ -2938,24 +2927,48 @@ const appendErrorMessage = () => {
div.style.color = "white";
addChild(document.body, div);
};
const showError = (message) => {
const element = document.querySelector('#message');
element.innerHTML = "Error occurred in Fin Unique titles script: " + message;
element.parentElement.style.display = "block";
const findFirst = (...selectors) => {
for (let selector of selectors) {
let elements = document.querySelectorAll(selector);
if (elements.length > 0) {
return elements;
}
}
return null;
};

var dom = /*#__PURE__*/Object.freeze({
__proto__: null,
addChild: addChild,
appendErrorMessage: appendErrorMessage,
findFirst: findFirst,
insertAfter: insertAfter,
insertBefore: insertBefore,
showError: showError
insertBefore: insertBefore
});

const parser = new DOMParser();
const fetchUrl = async (url, wait = 1000) => {
await sleep(wait);
const res = await (0,_trim21_gm_fetch__WEBPACK_IMPORTED_MODULE_0__["default"])(url);
return await res.text();
};
const fetchAndParseHtml = async (query_url) => {
const response = await fetchUrl(query_url);
return parser.parseFromString(response, "text/html").body;
};
const sleep = (ms) => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

var http = /*#__PURE__*/Object.freeze({
__proto__: null,
fetchAndParseHtml: fetchAndParseHtml,
fetchUrl: fetchUrl
});

const tracker_tools = {
http,
dom
dom,
};


Expand Down
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.2",
"version": "0.0.3",
"author": {
"name": "Mea01"
},
Expand Down
47 changes: 30 additions & 17 deletions Find Unique Titles/src/trackers/PTP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function isSupportedCategory(category: Category) {

const parseTorrents = (element: HTMLElement) => {
const torrents = [];
if (element.classList.contains("cover-movie-list__movie")) {
return [];
}
element
.querySelectorAll("tr.basic-movie-list__torrent-row")
.forEach((element: HTMLElement) => {
Expand Down Expand Up @@ -56,7 +59,10 @@ const parseTorrents = (element: HTMLElement) => {
const parseCategory = (element: HTMLElement): Category => {
const categoryTitle = element.querySelector(
".basic-movie-list__torrent-edition__main"
).textContent;
)?.textContent;
if (!categoryTitle) {
return null
}
if (categoryTitle.includes("Stand-up Comedy ")) {
return Category.STAND_UP;
} else if (categoryTitle.includes("Live Performance ")) {
Expand All @@ -81,22 +87,29 @@ export default class PTP implements tracker {

async *getSearchRequest(): AsyncGenerator<MetaData | Request, void, void> {
const requests: Array<Request> = [];
document
.querySelectorAll("#torrents-movie-view table.torrent_table > tbody")
?.forEach((element: HTMLElement) => {
const imdbId = parseImdbIdFromLink(
element.querySelector(".basic-movie-list__movie__ratings-and-tags")
);

const request: Request = {
torrents: parseTorrents(element),
dom: element as HTMLElement,
imdbId,
query: "",
category: parseCategory(element),
};
requests.push(request);
});
const nodes = tracker_tools.dom.findFirst(
"#torrents-movie-view table.torrent_table > tbody",
".cover-movie-list__movie"
);
nodes?.forEach((element: HTMLElement) => {
let elements = tracker_tools.dom.findFirst(
".basic-movie-list__movie__ratings-and-tags",
".cover-movie-list__movie__rating-and-tags"
);

const imdbId = elements
? parseImdbIdFromLink(elements[0] as HTMLElement)
: null;

const request: Request = {
torrents: parseTorrents(element),
dom: element as HTMLElement,
imdbId,
query: "",
category: parseCategory(element),
};
requests.push(request);
});

yield* toGenerator(requests);
}
Expand Down
12 changes: 8 additions & 4 deletions common/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ export const appendErrorMessage = () => {
addChild(document.body, div);
};

export const showError = (message: string) => {
const element = document.querySelector("#message")! as HTMLElement;
element.innerHTML = "Error occurred in Fin Unique titles script: " + message;
element.parentElement!.style.display = "block";
export const findFirst = (...selectors: string[]) => {
for (let selector of selectors) {
let elements = document.querySelectorAll(selector);
if (elements.length > 0) {
return elements;
}
}
return null;
};

0 comments on commit a531fdd

Please sign in to comment.