From a0d000138c598b482da205681349310198f70eb2 Mon Sep 17 00:00:00 2001 From: Roger Far Date: Thu, 28 Oct 2021 17:26:53 -0600 Subject: [PATCH] Fixed settings parsing when entering an invalid full Int32. Add Uploading status to the interface. --- CHANGELOG.md | 9 + .../add-new-torrent.component.html | 4 +- client/src/app/models/torrent.model.ts | 1 + client/src/app/navbar/navbar.component.html | 2 +- .../src/app/settings/settings.component.html | 10 +- client/src/app/torrent-status.pipe.ts | 2 + client/src/app/torrent/torrent.component.html | 2 +- package.json | 2 +- server/RdtClient.Data/Data/SettingData.cs | 21 ++- server/RdtClient.Data/Enums/TorrentStatus.cs | 1 + .../TorrentClients/AllDebridTorrentClient.cs | 155 ++++++++++++++++++ server/RdtClient.Service/Services/Torrents.cs | 13 +- server/RdtClient.Web/RdtClient.Web.csproj | 2 +- 13 files changed, 210 insertions(+), 14 deletions(-) create mode 100644 server/RdtClient.Service/Services/TorrentClients/AllDebridTorrentClient.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index b5dad9f..97a0ceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.9.5] - 2021-10-28 +### Changed +- Fixed issues with the simple downloader. +- Fixed issue with retrying downloads. + +### Added +- Added torrent uploading status from Real Debrid. +- Restored removing of torrents when deleted from Real Debrid. + ## [1.9.4] - 2021-10-28 ### Changed - Fixed issues retrying torrents after multiple failed downloads in large torrents. diff --git a/client/src/app/add-new-torrent/add-new-torrent.component.html b/client/src/app/add-new-torrent/add-new-torrent.component.html index 99f539a..8fa2e4d 100644 --- a/client/src/app/add-new-torrent/add-new-torrent.component.html +++ b/client/src/app/add-new-torrent/add-new-torrent.component.html @@ -52,7 +52,7 @@
- +
MB @@ -84,7 +84,7 @@
- +

Set the priority for this torrent where 1 is the highest. When empty it will be assigned the lowest priority. diff --git a/client/src/app/models/torrent.model.ts b/client/src/app/models/torrent.model.ts index eaad6a7..52e871b 100644 --- a/client/src/app/models/torrent.model.ts +++ b/client/src/app/models/torrent.model.ts @@ -56,6 +56,7 @@ export enum RealDebridStatus { WaitingForFileSelection = 1, Downloading = 2, Finished = 3, + Uploading = 4, Error = 99, } diff --git a/client/src/app/navbar/navbar.component.html b/client/src/app/navbar/navbar.component.html index a4e9317..01e6bff 100644 --- a/client/src/app/navbar/navbar.component.html +++ b/client/src/app/navbar/navbar.component.html @@ -55,7 +55,7 @@ Profile Logout

- +
diff --git a/client/src/app/settings/settings.component.html b/client/src/app/settings/settings.component.html index 52c9473..2d39bb9 100644 --- a/client/src/app/settings/settings.component.html +++ b/client/src/app/settings/settings.component.html @@ -62,7 +62,7 @@
- +

Maximum amount of downloads that get unpacked on your host at the same time.

@@ -98,7 +98,7 @@
- +

Maximum amount of torrents that get downloaded to your host at the same time.

@@ -106,7 +106,7 @@
- +

Maximum amount of parallel threads that are used to download a single torrent to your host. If set to 1 no @@ -117,7 +117,7 @@

- +

Maximum download speed in Megabytes per second. When set to 0 unlimited speed is used.

@@ -178,7 +178,7 @@
- +
MB diff --git a/client/src/app/torrent-status.pipe.ts b/client/src/app/torrent-status.pipe.ts index 246bd96..3a70a9d 100644 --- a/client/src/app/torrent-status.pipe.ts +++ b/client/src/app/torrent-status.pipe.ts @@ -99,6 +99,8 @@ export class TorrentStatusPipe implements PipeTransform { return `Torrent error: ${torrent.rdStatusRaw}`; case RealDebridStatus.Finished: return `Torrent finished, waiting to download`; + case RealDebridStatus.Uploading: + return `Torrent uploading`; default: return 'Unknown status'; } diff --git a/client/src/app/torrent/torrent.component.html b/client/src/app/torrent/torrent.component.html index ad475f6..ad54a2c 100644 --- a/client/src/app/torrent/torrent.component.html +++ b/client/src/app/torrent/torrent.component.html @@ -464,7 +464,7 @@
- +

Set the priority for this torrent where 1 is the highest. When empty it will be assigned the lowest priority. diff --git a/package.json b/package.json index d373624..83a7909 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rdt-client", - "version": "1.9.4", + "version": "1.9.5", "description": "This is a web interface to manage your torrents on Real-Debrid.", "main": "index.js", "dependencies": { diff --git a/server/RdtClient.Data/Data/SettingData.cs b/server/RdtClient.Data/Data/SettingData.cs index f710e98..9e51b6d 100644 --- a/server/RdtClient.Data/Data/SettingData.cs +++ b/server/RdtClient.Data/Data/SettingData.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using RdtClient.Data.Models.Data; using RdtClient.Data.Models.Internal; +using Serilog; namespace RdtClient.Data.Data { @@ -26,8 +27,24 @@ namespace RdtClient.Data.Data { var allSettings = await _dataContext.Settings.AsNoTracking().ToListAsync(); - String GetString(String name) => allSettings.FirstOrDefault(m => m.SettingId == name)?.Value; - Int32 GetInt32(String name) => Int32.Parse(allSettings.FirstOrDefault(m => m.SettingId == name)?.Value ?? "0"); + String GetString(String name) + { + return allSettings.FirstOrDefault(m => m.SettingId == name)?.Value; + } + + Int32 GetInt32(String name) + { + var strVal = GetString(name); + + if (!Int32.TryParse(strVal, out var intVal)) + { + Log.Error("Unable to parse setting {name} to Int32", name); + return 0; + } + + return intVal; + + } Get = new DbSettings { diff --git a/server/RdtClient.Data/Enums/TorrentStatus.cs b/server/RdtClient.Data/Enums/TorrentStatus.cs index 1471da2..3ef4341 100644 --- a/server/RdtClient.Data/Enums/TorrentStatus.cs +++ b/server/RdtClient.Data/Enums/TorrentStatus.cs @@ -6,6 +6,7 @@ WaitingForFileSelection = 1, Downloading = 2, Finished = 3, + Uploading = 4, Error = 99 } diff --git a/server/RdtClient.Service/Services/TorrentClients/AllDebridTorrentClient.cs b/server/RdtClient.Service/Services/TorrentClients/AllDebridTorrentClient.cs new file mode 100644 index 0000000..6c13a32 --- /dev/null +++ b/server/RdtClient.Service/Services/TorrentClients/AllDebridTorrentClient.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Threading.Tasks; +using RDNET; +using RdtClient.Service.Models.TorrentClient; + +namespace RdtClient.Service.Services.TorrentClients +{ + public class AllDebridTorrentClient : ITorrentClient + { + private readonly IHttpClientFactory _httpClientFactory; + + public AllDebridTorrentClient(IHttpClientFactory httpClientFactory) + { + _httpClientFactory = httpClientFactory; + } + + private RdNetClient GetRdNetClient() + { + var apiKey = Settings.Get.RealDebridApiKey; + + if (String.IsNullOrWhiteSpace(apiKey)) + { + throw new Exception("Real-Debrid API Key not set in the settings"); + } + + var httpClient = _httpClientFactory.CreateClient(); + httpClient.Timeout = TimeSpan.FromSeconds(10); + + var rdtNetClient = new RdNetClient(null, httpClient, 5); + rdtNetClient.UseApiAuthentication(apiKey); + + return rdtNetClient; + } + + private static TorrentClientTorrent Map(Torrent torrent) + { + return new TorrentClientTorrent + { + Id = torrent.Id, + Filename = torrent.Filename, + OriginalFilename = torrent.OriginalFilename, + Hash = torrent.Hash, + Bytes = torrent.Bytes, + OriginalBytes = torrent.OriginalBytes, + Host = torrent.Host, + Split = torrent.Split, + Progress = torrent.Progress, + Status = torrent.Status, + Added = torrent.Added, + Files = (torrent.Files ?? new List()).Select(m => new TorrentClientTorrentFile + { + Path = m.Path, + Bytes = m.Bytes, + Id = m.Id, + Selected = m.Selected + }).ToList(), + Links = torrent.Links, + Ended = torrent.Ended, + Speed = torrent.Speed, + Seeders = torrent.Seeders, + }; + } + + public async Task> GetTorrents() + { + var page = 0; + var results = new List(); + + while (true) + { + var pagedResults = await GetRdNetClient().Torrents.GetAsync(page, 100); + + results.AddRange(pagedResults); + + if (pagedResults.Count == 0) + { + break; + } + + page += 100; + } + + return results.Select(Map).ToList(); + } + + public async Task GetUser() + { + var user = await GetRdNetClient().User.GetAsync(); + + return new TorrentClientUser + { + Username = user.Username, + Expiration = user.Expiration + }; + } + + public async Task AddMagnet(String magnetLink) + { + var result = await GetRdNetClient().Torrents.AddMagnetAsync(magnetLink); + + return result.Id; + } + + public async Task AddFile(Byte[] bytes) + { + var result = await GetRdNetClient().Torrents.AddFileAsync(bytes); + + return result.Id; + } + + public async Task> GetAvailableFiles(String hash) + { + var result = await GetRdNetClient().Torrents.GetAvailableFiles(hash); + + var files = result.SelectMany(m => m.Value).SelectMany(m => m.Value).SelectMany(m => m.Values); + + var groups = files.GroupBy(m => $"{m.Filename}-{m.Filesize}"); + + var torrentClientAvailableFiles = groups.Select(m => new TorrentClientAvailableFile + { + Filename = m.First().Filename, + Filesize = m.First().Filesize + } ).ToList(); + + return torrentClientAvailableFiles; + } + + public async Task SelectFiles(String torrentId, IList fileIds) + { + await GetRdNetClient().Torrents.SelectFilesAsync(torrentId, fileIds.ToArray()); + } + + public async Task GetInfo(String torrentId) + { + var result = await GetRdNetClient().Torrents.GetInfoAsync(torrentId); + + return Map(result); + } + + public async Task Delete(String torrentId) + { + await GetRdNetClient().Torrents.DeleteAsync(torrentId); + } + + public async Task Unrestrict(String link) + { + var result = await GetRdNetClient().Unrestrict.LinkAsync(link); + + return result.Download; + } + } +} diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 7124414..71d0033 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -354,6 +354,17 @@ namespace RdtClient.Service.Services await UpdateRdData(torrent); } + + foreach (var torrent in torrents) + { + var rdTorrent = rdTorrents.FirstOrDefault(m => m.Id == torrent.RdId); + + if (rdTorrent == null) + { + await _downloads.DeleteForTorrent(torrent.TorrentId); + await _torrentData.Delete(torrent.TorrentId); + } + } } finally { @@ -649,7 +660,7 @@ namespace RdtClient.Service.Services "error" => RealDebridStatus.Error, "virus" => RealDebridStatus.Error, "compressing" => RealDebridStatus.Downloading, - "uploading" => RealDebridStatus.Downloading, + "uploading" => RealDebridStatus.Uploading, "dead" => RealDebridStatus.Error, _ => RealDebridStatus.Error }; diff --git a/server/RdtClient.Web/RdtClient.Web.csproj b/server/RdtClient.Web/RdtClient.Web.csproj index e0377fa..5b0ee0e 100644 --- a/server/RdtClient.Web/RdtClient.Web.csproj +++ b/server/RdtClient.Web/RdtClient.Web.csproj @@ -4,7 +4,7 @@ net5.0 Exe 94c24cba-f03f-4453-a671-3640b517c573 - 1.9.4 + 1.9.5