mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
fix: get date and name from torrent
This commit is contained in:
parent
fb5ed9aae3
commit
7231848bd8
2 changed files with 6 additions and 38 deletions
|
@ -29,7 +29,8 @@
|
|||
"build:win": "electron-vite build && electron-builder --win",
|
||||
"build:mac": "electron-vite build && electron-builder --mac",
|
||||
"build:linux": "electron-vite build && electron-builder --linux",
|
||||
"prepare": "husky"
|
||||
"prepare": "husky",
|
||||
"typeorm:migration-create": "yarn typeorm migration:create"
|
||||
},
|
||||
"dependencies": {
|
||||
"@electron-toolkit/preload": "^3.0.0",
|
||||
|
|
|
@ -3,15 +3,11 @@ import { decodeNonUtf8Response, savePage } from "./helpers";
|
|||
import { logger } from "../logger";
|
||||
import { JSDOM } from "jsdom";
|
||||
|
||||
import { format, parse, sub } from "date-fns";
|
||||
import { ru } from "date-fns/locale";
|
||||
|
||||
import createWorker from "@main/workers/torrent-parser.worker?nodeWorker";
|
||||
import { toMagnetURI } from "parse-torrent";
|
||||
|
||||
const worker = createWorker({});
|
||||
|
||||
import { onlinefixFormatter } from "@main/helpers";
|
||||
import makeFetchCookie from "fetch-cookie";
|
||||
import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity";
|
||||
import { formatBytes } from "@shared";
|
||||
|
@ -81,11 +77,6 @@ export const getNewRepacksFromOnlineFix = async (
|
|||
try {
|
||||
await Promise.all(
|
||||
articles.map(async (article) => {
|
||||
const gameText = article.querySelector("h2.title")?.textContent?.trim();
|
||||
if (!gameText) return;
|
||||
|
||||
const gameName = onlinefixFormatter(gameText);
|
||||
|
||||
const gameLink = article.querySelector("a")?.getAttribute("href");
|
||||
if (!gameLink) return;
|
||||
|
||||
|
@ -94,32 +85,6 @@ export const getNewRepacksFromOnlineFix = async (
|
|||
);
|
||||
const gameDocument = new JSDOM(gamePage).window.document;
|
||||
|
||||
const uploadDateText = gameDocument.querySelector("time")?.textContent;
|
||||
if (!uploadDateText) return;
|
||||
|
||||
let decodedDateText = uploadDateText;
|
||||
|
||||
// "Вчера" means yesterday.
|
||||
if (decodedDateText.includes("Вчера")) {
|
||||
const yesterday = sub(new Date(), { days: 1 });
|
||||
const formattedYesterday = format(yesterday, "d LLLL yyyy", {
|
||||
locale: ru,
|
||||
});
|
||||
decodedDateText = decodedDateText.replace(
|
||||
"Вчера", // "Change yesterday to the default expected date format"
|
||||
formattedYesterday
|
||||
);
|
||||
}
|
||||
|
||||
const uploadDate = parse(
|
||||
decodedDateText,
|
||||
"d LLLL yyyy, HH:mm",
|
||||
new Date(),
|
||||
{
|
||||
locale: ru,
|
||||
}
|
||||
);
|
||||
|
||||
const torrentButtons = Array.from(
|
||||
gameDocument.querySelectorAll("a")
|
||||
).filter((a) => a.textContent?.includes("Torrent"));
|
||||
|
@ -148,13 +113,15 @@ export const getNewRepacksFromOnlineFix = async (
|
|||
worker.once("message", (torrent) => {
|
||||
if (!torrent) return;
|
||||
|
||||
const { name, created } = torrent;
|
||||
|
||||
repacks.push({
|
||||
fileSize: formatBytes(torrent.length ?? 0),
|
||||
magnet: toMagnetURI(torrent),
|
||||
page: 1,
|
||||
repacker: "onlinefix",
|
||||
title: gameName,
|
||||
uploadDate: uploadDate,
|
||||
title: name,
|
||||
uploadDate: created,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue