mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-24 05:54:55 +03:00
feat: added support to add magnets and download from real debrid
This commit is contained in:
parent
76a64fca4a
commit
6bb22655e8
65
src/main/services/donwloaders/real-debrid.d.ts
vendored
Normal file
65
src/main/services/donwloaders/real-debrid.d.ts
vendored
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
interface RealDebridUnrestrictLink {
|
||||||
|
id: string;
|
||||||
|
filename: string;
|
||||||
|
mimeType: string;
|
||||||
|
filesize: number;
|
||||||
|
link: string;
|
||||||
|
host: string;
|
||||||
|
host_icon: string;
|
||||||
|
chunks: number;
|
||||||
|
crc: number;
|
||||||
|
download: string;
|
||||||
|
streamable: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RealDebridAddMagnet {
|
||||||
|
"id": string,
|
||||||
|
// URL of the created ressource
|
||||||
|
"uri": string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RealDebridTorrentInfo {
|
||||||
|
"id": string,
|
||||||
|
"filename": string,
|
||||||
|
"original_filename": string, // Original name of the torrent
|
||||||
|
"hash": string, // SHA1 Hash of the torrent
|
||||||
|
"bytes": number, // Size of selected files only
|
||||||
|
"original_bytes": number, // Total size of the torrent
|
||||||
|
"host": string, // Host main domain
|
||||||
|
"split": number, // Split size of links
|
||||||
|
"progress": number, // Possible values: 0 to 100
|
||||||
|
"status": "downloaded", // Current status of the torrent: magnet_error, magnet_conversion, waiting_files_selection, queued, downloading, downloaded, error, virus, compressing, uploading, dead
|
||||||
|
"added": string, // jsonDate
|
||||||
|
"files": [
|
||||||
|
{
|
||||||
|
"id": number,
|
||||||
|
"path": string, // Path to the file inside the torrent, starting with "/"
|
||||||
|
"bytes": number,
|
||||||
|
"selected": number // 0 or 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": number,
|
||||||
|
"path": string, // Path to the file inside the torrent, starting with "/"
|
||||||
|
"bytes": number,
|
||||||
|
"selected": number // 0 or 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"links": [
|
||||||
|
"string" // Host URL
|
||||||
|
],
|
||||||
|
"ended": string, // !! Only present when finished, jsonDate
|
||||||
|
"speed": number, // !! Only present in "downloading", "compressing", "uploading" status
|
||||||
|
"seeders": number // !! Only present in "downloading", "magnet_conversion" status
|
||||||
|
}
|
||||||
|
|
||||||
|
declare module 'real-debrid-api' {
|
||||||
|
interface Torrent {
|
||||||
|
addMagnet(magnet: string): Promise<RealDebridAddMagnet>;
|
||||||
|
info(id: string): Promise<RealDebridTorrentInfo[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class {
|
||||||
|
constructor(token: string);
|
||||||
|
torrents: Torrent;
|
||||||
|
}
|
||||||
|
}
|
55
src/main/services/donwloaders/real-debrid.ts
Normal file
55
src/main/services/donwloaders/real-debrid.ts
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/// <reference path="./real-debrid.d.ts" />
|
||||||
|
import { userPreferencesRepository } from "@main/repository";
|
||||||
|
import fetch from "node-fetch";
|
||||||
|
|
||||||
|
const base = "https://api.real-debrid.com/rest/1.0";
|
||||||
|
|
||||||
|
export class RealDebridClient {
|
||||||
|
static async addMagnet(magnet: string) {
|
||||||
|
const response = await fetch(`${base}/torrents/addMagnet`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${await this.getApiToken()}`,
|
||||||
|
},
|
||||||
|
body: `magnet=${encodeURIComponent(magnet)}`
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.json() as Promise<RealDebridAddMagnet>;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async getInfo(id: string) {
|
||||||
|
const response = await fetch(`${base}/torrents/info/${id}`, {
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${await this.getApiToken()}`
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.json() as Promise<RealDebridTorrentInfo>;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async selectAllFiles(id: string) {
|
||||||
|
const response = await fetch(`${base}/torrents/selectFiles/${id}`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${await this.getApiToken()}`,
|
||||||
|
},
|
||||||
|
body: "files=all"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static async unrestrictLink(link: string) {
|
||||||
|
const response = await fetch(`${base}/unrestrict/link`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${await this.getApiToken()}`,
|
||||||
|
},
|
||||||
|
body: `link=${link}`
|
||||||
|
});
|
||||||
|
|
||||||
|
return response.json() as Promise<RealDebridUnrestrictLink>;
|
||||||
|
}
|
||||||
|
|
||||||
|
static getApiToken() {
|
||||||
|
return userPreferencesRepository.findOne({ where: { id: 1 } }).then(userPreferences => userPreferences.realDebridApiToken);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user