Add auto import and auto delete functionality.
This commit is contained in:
parent
4dbd2cf8df
commit
4d5dfc34a4
8 changed files with 103 additions and 12 deletions
|
|
@ -33,7 +33,7 @@
|
|||
<a href="https://real-debrid.com/?id=1348683" target="_blank" rel="noopener">https://real-debrid.com</a>
|
||||
<br />
|
||||
<a href="https://alldebrid.com/?uid=2v91l&lang=en" target="_blank" rel="noopener">https://alldebrid.com</a>
|
||||
<br/>
|
||||
<br />
|
||||
At this point only 1 provider can be used at the time.
|
||||
</p>
|
||||
</div>
|
||||
|
|
@ -57,6 +57,29 @@
|
|||
<a href="https://alldebrid.com/apikeys/" target="_blank" rel="noopener">https://alldebrid.com/apikeys/</a>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" [(ngModel)]="settingProviderAutoImport" />
|
||||
Automatically import and process torrents added to provider.
|
||||
</label>
|
||||
<div class="help">
|
||||
When selected, import downloads that are not added through RealDebridClient but have been directly added to
|
||||
Real-Debrid or AllDebrid.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="field">
|
||||
<div class="control">
|
||||
<label class="checkbox">
|
||||
<input type="checkbox" [(ngModel)]="settingProviderAutoDelete" />
|
||||
Automatically delete downloads removed from provider.
|
||||
</label>
|
||||
<div class="help">
|
||||
When selected, cancel and delete downloads that have been removed from Real-Debrid or AllDebrid.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div *ngIf="activeTab === 0">
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ export class SettingsComponent implements OnInit {
|
|||
|
||||
public settingLogLevel: string;
|
||||
public settingProvider: string;
|
||||
public settingProviderAutoImport: boolean;
|
||||
public settingProviderAutoDelete: boolean;
|
||||
public settingRealDebridApiKey: string;
|
||||
public settingDownloadPath: string;
|
||||
public settingMappedPath: string;
|
||||
|
|
@ -59,6 +61,8 @@ export class SettingsComponent implements OnInit {
|
|||
this.settingsService.get().subscribe(
|
||||
(results) => {
|
||||
this.settingProvider = this.getSetting(results, 'Provider');
|
||||
this.settingProviderAutoImport = this.getSetting(results, 'ProviderAutoImport') === '1';
|
||||
this.settingProviderAutoDelete = this.getSetting(results, 'ProviderAutoDelete') === '1';
|
||||
this.settingRealDebridApiKey = this.getSetting(results, 'RealDebridApiKey');
|
||||
this.settingLogLevel = this.getSetting(results, 'LogLevel');
|
||||
this.settingDownloadPath = this.getSetting(results, 'DownloadPath');
|
||||
|
|
@ -92,6 +96,14 @@ export class SettingsComponent implements OnInit {
|
|||
settingId: 'Provider',
|
||||
value: this.settingProvider,
|
||||
},
|
||||
{
|
||||
settingId: 'ProviderAutoImport',
|
||||
value: this.settingProviderAutoImport ? '1' : '0',
|
||||
},
|
||||
{
|
||||
settingId: 'ProviderAutoDelete',
|
||||
value: this.settingProviderAutoDelete ? '1' : '0',
|
||||
},
|
||||
{
|
||||
settingId: 'RealDebridApiKey',
|
||||
value: this.settingRealDebridApiKey,
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ export class TorrentStatusPipe implements PipeTransform {
|
|||
return `Queued for unpacking`;
|
||||
}
|
||||
|
||||
const queuedForDownload = torrent.downloads.where((m) => m.downloadQueued && !m.downloadStarted);
|
||||
const queuedForDownload = torrent.downloads.where((m) => !m.downloadStarted && !m.downloadFinished);
|
||||
|
||||
if (queuedForDownload.length > 0) {
|
||||
return `Queued for downloading`;
|
||||
|
|
|
|||
|
|
@ -47,6 +47,18 @@ namespace RdtClient.Data.Data
|
|||
Value = "RealDebrid"
|
||||
},
|
||||
new Setting
|
||||
{
|
||||
SettingId = "ProviderAutoImport",
|
||||
Type = "Int32",
|
||||
Value = "0"
|
||||
},
|
||||
new Setting
|
||||
{
|
||||
SettingId = "ProviderAutoDelete",
|
||||
Type = "Int32",
|
||||
Value = "0"
|
||||
},
|
||||
new Setting
|
||||
{
|
||||
SettingId = "RealDebridApiKey",
|
||||
Type = "String",
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ namespace RdtClient.Data.Data
|
|||
Get = new DbSettings
|
||||
{
|
||||
Provider = GetString("Provider"),
|
||||
ProviderAutoImport = GetInt32("ProviderAutoImport"),
|
||||
ProviderAutoDelete= GetInt32("ProviderAutoDelete"),
|
||||
RealDebridApiKey = GetString("RealDebridApiKey"),
|
||||
DownloadPath = GetString("DownloadPath"),
|
||||
DownloadClient = GetString("DownloadClient"),
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ namespace RdtClient.Data.Models.Internal
|
|||
public class DbSettings
|
||||
{
|
||||
public String Provider { get; set; }
|
||||
public Int32 ProviderAutoImport { get; set; }
|
||||
public Int32 ProviderAutoDelete { get; set; }
|
||||
public String RealDebridApiKey { get; set; }
|
||||
public String DownloadPath { get; set; }
|
||||
public String DownloadClient { get; set; }
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ namespace RdtClient.Service.Services
|
|||
torrents = torrents.Where(m => m.Completed == null).ToList();
|
||||
|
||||
// Only poll Real-Debrid every second when a hub is connected, otherwise every 30 seconds
|
||||
if (_nextUpdate < DateTime.UtcNow && torrents.Count > 0)
|
||||
if (_nextUpdate < DateTime.UtcNow && ((torrents.Count > 0 && Settings.Get.ProviderAutoImport == 0) || Settings.Get.ProviderAutoImport == 1))
|
||||
{
|
||||
Log($"Updating torrent info from Real-Debrid");
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
|
|||
using MonoTorrent;
|
||||
using System.Text.Json.Serialization;
|
||||
using RdtClient.Data.Data;
|
||||
using RdtClient.Data.Enums;
|
||||
using RdtClient.Data.Models.Internal;
|
||||
using RdtClient.Data.Models.TorrentClient;
|
||||
using RdtClient.Service.Helpers;
|
||||
|
|
@ -212,22 +213,40 @@ namespace RdtClient.Service.Services
|
|||
|
||||
foreach (var download in torrent.Downloads)
|
||||
{
|
||||
var retry = 10;
|
||||
|
||||
while (TorrentRunner.ActiveDownloadClients.TryGetValue(download.DownloadId, out var downloadClient))
|
||||
{
|
||||
Log($"Cancelling download", download, torrent);
|
||||
|
||||
await downloadClient.Cancel();
|
||||
|
||||
await Task.Delay(100);
|
||||
await Task.Delay(500);
|
||||
|
||||
retry++;
|
||||
|
||||
if (retry > 5)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
retry = 10;
|
||||
|
||||
while (TorrentRunner.ActiveUnpackClients.TryGetValue(download.DownloadId, out var unpackClient))
|
||||
{
|
||||
Log($"Cancelling unpack", download, torrent);
|
||||
|
||||
unpackClient.Cancel();
|
||||
|
||||
await Task.Delay(100);
|
||||
await Task.Delay(500);
|
||||
|
||||
retry++;
|
||||
|
||||
if (retry > 10)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -334,22 +353,43 @@ namespace RdtClient.Service.Services
|
|||
{
|
||||
var torrent = torrents.FirstOrDefault(m => m.RdId == rdTorrent.Id);
|
||||
|
||||
if (torrent == null)
|
||||
// Auto import torrents only torrents that have their files selected
|
||||
if (torrent == null && Settings.Get.ProviderAutoImport == 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var newTorrent = new Torrent
|
||||
{
|
||||
Category = null,
|
||||
DownloadAction = TorrentDownloadAction.DownloadManual,
|
||||
FinishedAction = TorrentFinishedAction.None,
|
||||
DownloadMinSize = 0,
|
||||
TorrentRetryAttempts = 0,
|
||||
DownloadRetryAttempts = Settings.Get.DownloadRetryAttempts,
|
||||
Priority = 0,
|
||||
RdId = rdTorrent.Id
|
||||
};
|
||||
|
||||
await UpdateTorrentClientData(torrent, rdTorrent);
|
||||
await _torrentClient.UpdateData(newTorrent, rdTorrent);
|
||||
|
||||
if (newTorrent.RdStatus == TorrentStatus.WaitingForFileSelection)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
await _torrentData.Add(rdTorrent.Id, rdTorrent.Hash, null, false, newTorrent);
|
||||
}
|
||||
else
|
||||
{
|
||||
await UpdateTorrentClientData(torrent, rdTorrent);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var torrent in torrents)
|
||||
{
|
||||
var rdTorrent = rdTorrents.FirstOrDefault(m => m.Id == torrent.RdId);
|
||||
|
||||
if (rdTorrent == null)
|
||||
if (rdTorrent == null && Settings.Get.ProviderAutoDelete == 1)
|
||||
{
|
||||
await _downloads.DeleteForTorrent(torrent.TorrentId);
|
||||
await _torrentData.Delete(torrent.TorrentId);
|
||||
await Delete(torrent.TorrentId, true, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue