mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-24 22:14:55 +03:00
fix: do not add the same magnet twice to real debrid
This commit is contained in:
parent
d3f891da16
commit
27bf3c92ec
@ -69,10 +69,22 @@ export class Downloader {
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
const torrent = await RealDebridClient.addMagnet(repack.magnet);
|
||||
if (torrent && torrent.id) {
|
||||
await RealDebridClient.selectAllFiles(torrent.id);
|
||||
const { links } = await RealDebridClient.getInfo(torrent.id);
|
||||
// Lets try first to find the torrent on RealDebrid
|
||||
const torrents = await RealDebridClient.getAllTorrents();
|
||||
const hash = RealDebridClient.extractSHA1FromMagnet(repack.magnet);
|
||||
let torrent = torrents.find((t) => t.hash === hash);
|
||||
|
||||
if (!torrent) {
|
||||
// Torrent is missing, lets add it
|
||||
const magnet = await RealDebridClient.addMagnet(repack.magnet);
|
||||
if (magnet && magnet.id) {
|
||||
await RealDebridClient.selectAllFiles(magnet.id);
|
||||
torrent = await RealDebridClient.getInfo(magnet.id);
|
||||
}
|
||||
}
|
||||
|
||||
if (torrent) {
|
||||
const { links } = torrent;
|
||||
const { download } = await RealDebridClient.unrestrictLink(links[0]);
|
||||
this.lastHttpDownloader = new HTTPDownloader();
|
||||
this.lastHttpDownloader.download(
|
||||
|
@ -52,9 +52,23 @@ export class RealDebridClient {
|
||||
return response.json() as Promise<RealDebridUnrestrictLink>;
|
||||
}
|
||||
|
||||
static async getAllTorrents() {
|
||||
const response = await fetch(`${base}/torrents`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${await this.getApiToken()}`,
|
||||
},
|
||||
});
|
||||
|
||||
return response.json() as Promise<RealDebridTorrentInfo[]>;
|
||||
}
|
||||
|
||||
static getApiToken() {
|
||||
return userPreferencesRepository
|
||||
.findOne({ where: { id: 1 } })
|
||||
.then((userPreferences) => userPreferences!.realDebridApiToken);
|
||||
}
|
||||
|
||||
static extractSHA1FromMagnet(magnet: string) {
|
||||
return magnet.match(/btih:([0-9a-fA-F]*)/)?.[1].toLowerCase();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user