Add option to only download the files that are available on RD.

This commit is contained in:
Roger Far 2021-02-05 20:54:37 -07:00
parent 8bd26b7441
commit ed10c630ee
8 changed files with 56 additions and 16 deletions

View file

@ -112,6 +112,19 @@
</div> </div>
</div> </div>
<div class="field">
<div class="control">
<label class="checkbox">
<input type="checkbox" [(ngModel)]="settingOnlyDownloadAvailableFiles" />
Only download available files on RealDebrid
</label>
<div class="help">
When selected, it will only download files in the torrent that have been download by Real Debrid. You can
use this in combination with the Min File size setting above.
</div>
</div>
</div>
<div class="field"> <div class="field">
<label class="label">Test download path permissions</label> <label class="label">Test download path permissions</label>
<div class="control"> <div class="control">

View file

@ -45,6 +45,7 @@ export class SettingsComponent implements OnInit {
public settingDownloadMaxSpeed: number; public settingDownloadMaxSpeed: number;
public settingUnpackLimit: number; public settingUnpackLimit: number;
public settingMinFileSize: number; public settingMinFileSize: number;
public settingOnlyDownloadAvailableFiles: boolean;
constructor(private settingsService: SettingsService) {} constructor(private settingsService: SettingsService) {}
@ -66,6 +67,7 @@ export class SettingsComponent implements OnInit {
this.settingDownloadMaxSpeed = parseInt(this.getSetting(results, 'DownloadMaxSpeed'), 10); this.settingDownloadMaxSpeed = parseInt(this.getSetting(results, 'DownloadMaxSpeed'), 10);
this.settingUnpackLimit = parseInt(this.getSetting(results, 'UnpackLimit'), 10); this.settingUnpackLimit = parseInt(this.getSetting(results, 'UnpackLimit'), 10);
this.settingMinFileSize = parseInt(this.getSetting(results, 'MinFileSize'), 10); this.settingMinFileSize = parseInt(this.getSetting(results, 'MinFileSize'), 10);
this.settingOnlyDownloadAvailableFiles = this.getSetting(results, 'OnlyDownloadAvailableFiles') === 'true';
}, },
(err) => { (err) => {
this.error = err.error; this.error = err.error;
@ -118,6 +120,10 @@ export class SettingsComponent implements OnInit {
settingId: 'MinFileSize', settingId: 'MinFileSize',
value: (this.settingMinFileSize ?? 0).toString(), value: (this.settingMinFileSize ?? 0).toString(),
}, },
{
settingId: 'OnlyDownloadAvailableFiles',
value: (this.settingOnlyDownloadAvailableFiles ? '1' : '0').toString(),
},
]; ];
this.settingsService.update(settings).subscribe( this.settingsService.update(settings).subscribe(

View file

@ -101,6 +101,12 @@ namespace RdtClient.Data.Data
Value = "0" Value = "0"
}, },
new Setting new Setting
{
SettingId = "OnlyDownloadAvailableFiles",
Type = "Int32",
Value = "1"
},
new Setting
{ {
SettingId = "DownloadChunkCount", SettingId = "DownloadChunkCount",
Type = "Int32", Type = "Int32",

View file

@ -14,7 +14,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RD.NET" Version="1.0.0" /> <PackageReference Include="RD.NET" Version="1.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" /> <PackageReference Include="Serilog" Version="2.10.0" />
</ItemGroup> </ItemGroup>

View file

@ -6,10 +6,10 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Downloader" Version="2.0.7" /> <PackageReference Include="Downloader" Version="2.0.9" />
<PackageReference Include="MonoTorrent" Version="1.0.28" /> <PackageReference Include="MonoTorrent" Version="1.0.28" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="RD.NET" Version="1.0.0" /> <PackageReference Include="RD.NET" Version="1.0.1" />
<PackageReference Include="Serilog" Version="2.10.0" /> <PackageReference Include="Serilog" Version="2.10.0" />
<PackageReference Include="Serilog.Exceptions" Version="6.0.0" /> <PackageReference Include="Serilog.Exceptions" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" /> <PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />

View file

@ -77,7 +77,10 @@ namespace RdtClient.Service.Services
} }
settingMinFileSize = settingMinFileSize * 1024 * 1024; settingMinFileSize = settingMinFileSize * 1024 * 1024;
var settingOnlyDownloadAvailableFilesRaw = settings.GetNumber("OnlyDownloadAvailableFiles");
var settingOnlyDownloadAvailableFiles = settingOnlyDownloadAvailableFilesRaw == 1;
var settingDownloadLimit = settings.GetNumber("DownloadLimit"); var settingDownloadLimit = settings.GetNumber("DownloadLimit");
if (settingDownloadLimit < 1) if (settingDownloadLimit < 1)
{ {
@ -264,18 +267,22 @@ namespace RdtClient.Service.Services
// RealDebrid is waiting for file selection, select which files to download. // RealDebrid is waiting for file selection, select which files to download.
if (torrent.AutoDownload && torrent.RdStatus == RealDebridStatus.WaitingForFileSelection) if (torrent.AutoDownload && torrent.RdStatus == RealDebridStatus.WaitingForFileSelection)
{ {
var fileIds = torrent.Files var files = torrent.Files;
.Select(m => m.Id.ToString())
.ToArray(); if (settingOnlyDownloadAvailableFiles)
{
var availableFiles = await _torrents.GetAvailableFiles(torrent.Hash);
files = torrent.Files.Where(m => availableFiles.Any(f => m.Path.EndsWith(f))).ToList();
}
if (settingMinFileSize > 0) if (settingMinFileSize > 0)
{ {
fileIds = torrent.Files files = files.Where(m => m.Bytes > settingMinFileSize).ToList();
.Where(m => m.Bytes > settingMinFileSize)
.Select(m => m.Id.ToString())
.ToArray();
} }
var fileIds = files.Select(m => m.Id.ToString()).ToArray();
await _torrents.SelectFiles(torrent.RdId, fileIds); await _torrents.SelectFiles(torrent.RdId, fileIds);
} }

View file

@ -22,6 +22,7 @@ namespace RdtClient.Service.Services
Task UpdateCategory(String hash, String category); Task UpdateCategory(String hash, String category);
Task UploadMagnet(String magnetLink, String category, Boolean autoDownload, Boolean autoUnpack, Boolean autoDelete); Task UploadMagnet(String magnetLink, String category, Boolean autoDownload, Boolean autoUnpack, Boolean autoDelete);
Task UploadFile(Byte[] bytes, String category, Boolean autoDownload, Boolean autoUnpack, Boolean autoDelete); Task UploadFile(Byte[] bytes, String category, Boolean autoDownload, Boolean autoUnpack, Boolean autoDelete);
Task<List<String>> GetAvailableFiles(String hash);
Task SelectFiles(String torrentId, IList<String> fileIds); Task SelectFiles(String torrentId, IList<String> fileIds);
Task Delete(Guid torrentId, Boolean deleteData, Boolean deleteRdTorrent, Boolean deleteLocalFiles); Task Delete(Guid torrentId, Boolean deleteData, Boolean deleteRdTorrent, Boolean deleteLocalFiles);
Task Unrestrict(Guid torrentId); Task Unrestrict(Guid torrentId);
@ -152,6 +153,17 @@ namespace RdtClient.Service.Services
await Add(rdTorrent.Id, torrent.InfoHash.ToHex(), category, autoDownload, autoUnpack, autoDelete); await Add(rdTorrent.Id, torrent.InfoHash.ToHex(), category, autoDownload, autoUnpack, autoDelete);
} }
public async Task<List<String>> GetAvailableFiles(String hash)
{
var result = await GetRdNetClient().GetAvailableFiles(hash);
var files = result.SelectMany(m => m.Value).SelectMany(m => m.Value).SelectMany(m => m.Values);
var groups = files.GroupBy(m => m.Filename);
return groups.Select(m => m.Key).ToList();
}
public async Task SelectFiles(String torrentId, IList<String> fileIds) public async Task SelectFiles(String torrentId, IList<String> fileIds)
{ {
await GetRdNetClient().SelectTorrentFilesAsync(torrentId, fileIds.ToArray()); await GetRdNetClient().SelectTorrentFilesAsync(torrentId, fileIds.ToArray());
@ -246,11 +258,6 @@ namespace RdtClient.Service.Services
public async Task<Profile> GetProfile() public async Task<Profile> GetProfile()
{ {
if (_rdtNetClient == null)
{
return new Profile();
}
var user = await GetRdNetClient().GetUserAsync(); var user = await GetRdNetClient().GetUserAsync();
var profile = new Profile var profile = new Profile

View file

@ -72,6 +72,7 @@ namespace RdtClient.Web
.Enrich.WithExceptionDetails() .Enrich.WithExceptionDetails()
.WriteTo.File(appSettings.Logging.File.Path, logLevel, rollOnFileSizeLimit: true, fileSizeLimitBytes: appSettings.Logging.File.FileSizeLimitBytes, retainedFileCountLimit: appSettings.Logging.File.MaxRollingFiles) .WriteTo.File(appSettings.Logging.File.Path, logLevel, rollOnFileSizeLimit: true, fileSizeLimitBytes: appSettings.Logging.File.FileSizeLimitBytes, retainedFileCountLimit: appSettings.Logging.File.MaxRollingFiles)
.WriteTo.Console() .WriteTo.Console()
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
.MinimumLevel.Information() .MinimumLevel.Information()
.CreateLogger(); .CreateLogger();