Skip to content

Commit

Permalink
Add option to only download the files that are available on RD.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerfar committed Feb 6, 2021
1 parent 8bd26b7 commit ed10c63
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 16 deletions.
13 changes: 13 additions & 0 deletions client/src/app/navbar/settings/settings.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@
</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">
<label class="label">Test download path permissions</label>
<div class="control">
Expand Down
6 changes: 6 additions & 0 deletions client/src/app/navbar/settings/settings.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class SettingsComponent implements OnInit {
public settingDownloadMaxSpeed: number;
public settingUnpackLimit: number;
public settingMinFileSize: number;
public settingOnlyDownloadAvailableFiles: boolean;

constructor(private settingsService: SettingsService) {}

Expand All @@ -66,6 +67,7 @@ export class SettingsComponent implements OnInit {
this.settingDownloadMaxSpeed = parseInt(this.getSetting(results, 'DownloadMaxSpeed'), 10);
this.settingUnpackLimit = parseInt(this.getSetting(results, 'UnpackLimit'), 10);
this.settingMinFileSize = parseInt(this.getSetting(results, 'MinFileSize'), 10);
this.settingOnlyDownloadAvailableFiles = this.getSetting(results, 'OnlyDownloadAvailableFiles') === 'true';
},
(err) => {
this.error = err.error;
Expand Down Expand Up @@ -118,6 +120,10 @@ export class SettingsComponent implements OnInit {
settingId: 'MinFileSize',
value: (this.settingMinFileSize ?? 0).toString(),
},
{
settingId: 'OnlyDownloadAvailableFiles',
value: (this.settingOnlyDownloadAvailableFiles ? '1' : '0').toString(),
},
];

this.settingsService.update(settings).subscribe(
Expand Down
6 changes: 6 additions & 0 deletions server/RdtClient.Data/Data/DataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ public async Task Seed()
Value = "0"
},
new Setting
{
SettingId = "OnlyDownloadAvailableFiles",
Type = "Int32",
Value = "1"
},
new Setting
{
SettingId = "DownloadChunkCount",
Type = "Int32",
Expand Down
2 changes: 1 addition & 1 deletion server/RdtClient.Data/RdtClient.Data.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<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" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions server/RdtClient.Service/RdtClient.Service.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Downloader" Version="2.0.7" />
<PackageReference Include="Downloader" Version="2.0.9" />
<PackageReference Include="MonoTorrent" Version="1.0.28" />
<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.Exceptions" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
Expand Down
23 changes: 15 additions & 8 deletions server/RdtClient.Service/Services/TorrentRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public async Task Tick()
}

settingMinFileSize = settingMinFileSize * 1024 * 1024;


var settingOnlyDownloadAvailableFilesRaw = settings.GetNumber("OnlyDownloadAvailableFiles");
var settingOnlyDownloadAvailableFiles = settingOnlyDownloadAvailableFilesRaw == 1;

var settingDownloadLimit = settings.GetNumber("DownloadLimit");
if (settingDownloadLimit < 1)
{
Expand Down Expand Up @@ -264,18 +267,22 @@ public async Task Tick()
// RealDebrid is waiting for file selection, select which files to download.
if (torrent.AutoDownload && torrent.RdStatus == RealDebridStatus.WaitingForFileSelection)
{
var fileIds = torrent.Files
.Select(m => m.Id.ToString())
.ToArray();
var files = torrent.Files;

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)
{
fileIds = torrent.Files
.Where(m => m.Bytes > settingMinFileSize)
.Select(m => m.Id.ToString())
.ToArray();
files = files.Where(m => m.Bytes > settingMinFileSize).ToList();
}

var fileIds = files.Select(m => m.Id.ToString()).ToArray();

await _torrents.SelectFiles(torrent.RdId, fileIds);
}

Expand Down
17 changes: 12 additions & 5 deletions server/RdtClient.Service/Services/Torrents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public interface ITorrents
Task UpdateCategory(String hash, String category);
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<List<String>> GetAvailableFiles(String hash);
Task SelectFiles(String torrentId, IList<String> fileIds);
Task Delete(Guid torrentId, Boolean deleteData, Boolean deleteRdTorrent, Boolean deleteLocalFiles);
Task Unrestrict(Guid torrentId);
Expand Down Expand Up @@ -152,6 +153,17 @@ public async Task UploadFile(Byte[] bytes, String category, Boolean autoDownload
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)
{
await GetRdNetClient().SelectTorrentFilesAsync(torrentId, fileIds.ToArray());
Expand Down Expand Up @@ -246,11 +258,6 @@ public void Reset()

public async Task<Profile> GetProfile()
{
if (_rdtNetClient == null)
{
return new Profile();
}

var user = await GetRdNetClient().GetUserAsync();

var profile = new Profile
Expand Down
1 change: 1 addition & 0 deletions server/RdtClient.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public static IHostBuilder CreateHostBuilder(String[] args)
.Enrich.WithExceptionDetails()
.WriteTo.File(appSettings.Logging.File.Path, logLevel, rollOnFileSizeLimit: true, fileSizeLimitBytes: appSettings.Logging.File.FileSizeLimitBytes, retainedFileCountLimit: appSettings.Logging.File.MaxRollingFiles)
.WriteTo.Console()
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
.MinimumLevel.Information()
.CreateLogger();

Expand Down

0 comments on commit ed10c63

Please sign in to comment.