127 lines
3.4 KiB
C#
127 lines
3.4 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Text.Json;
|
|
using RdtClient.Data.Enums;
|
|
using RdtClient.Data.Models.DebridClient;
|
|
|
|
namespace RdtClient.Data.Models.Data;
|
|
|
|
public class Torrent
|
|
{
|
|
private String? _rdFiles;
|
|
private IList<DebridClientFile> _filesCache = [];
|
|
private Boolean _filesCacheInitialized;
|
|
|
|
[Key]
|
|
public Guid TorrentId { get; set; }
|
|
|
|
public String Hash { get; set; } = null!;
|
|
|
|
public String? Category { get; set; }
|
|
|
|
public TorrentDownloadAction DownloadAction { get; set; }
|
|
public TorrentFinishedAction FinishedAction { get; set; }
|
|
public Int32 FinishedActionDelay { get; set; }
|
|
public TorrentHostDownloadAction HostDownloadAction { get; set; }
|
|
public Int32 DownloadMinSize { get; set; }
|
|
public String? IncludeRegex { get; set; }
|
|
public String? ExcludeRegex { get; set; }
|
|
public String? DownloadManualFiles { get; set; }
|
|
public DownloadClient DownloadClient { get; set; }
|
|
|
|
public DateTimeOffset Added { get; set; }
|
|
public DateTimeOffset? FilesSelected { get; set; }
|
|
public DateTimeOffset? Completed { get; set; }
|
|
public DateTimeOffset? Retry { get; set; }
|
|
|
|
public DownloadType Type { get; set; }
|
|
public String? FileOrMagnet { get; set; }
|
|
public Boolean IsFile { get; set; }
|
|
|
|
public Int32? Priority { get; set; }
|
|
public Int32 RetryCount { get; set; }
|
|
public Int32 DownloadRetryAttempts { get; set; }
|
|
public Int32 TorrentRetryAttempts { get; set; }
|
|
public Int32 DeleteOnError { get; set; }
|
|
public Int32 Lifetime { get; set; }
|
|
|
|
public String? Error { get; set; }
|
|
|
|
[InverseProperty("Torrent")]
|
|
public IList<Download> Downloads { get; set; } = [];
|
|
|
|
public Provider? ClientKind { get; set; }
|
|
public String? RdId { get; set; }
|
|
public String? RdName { get; set; }
|
|
public Int64? RdSize { get; set; }
|
|
public String? RdHost { get; set; }
|
|
public Int64? RdSplit { get; set; }
|
|
public Int64? RdProgress { get; set; }
|
|
public TorrentStatus? RdStatus { get; set; }
|
|
public String? RdStatusRaw { get; set; }
|
|
public DateTimeOffset? RdAdded { get; set; }
|
|
public DateTimeOffset? RdEnded { get; set; }
|
|
public Int64? RdSpeed { get; set; }
|
|
public Int64? RdSeeders { get; set; }
|
|
public String? RdFiles
|
|
{
|
|
get => _rdFiles;
|
|
set
|
|
{
|
|
if (_rdFiles == value)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_rdFiles = value;
|
|
_filesCache = [];
|
|
_filesCacheInitialized = false;
|
|
}
|
|
}
|
|
|
|
[NotMapped]
|
|
public IList<DebridClientFile> Files
|
|
{
|
|
get
|
|
{
|
|
if (_filesCacheInitialized)
|
|
{
|
|
return _filesCache;
|
|
}
|
|
|
|
_filesCacheInitialized = true;
|
|
|
|
if (String.IsNullOrWhiteSpace(RdFiles))
|
|
{
|
|
_filesCache = [];
|
|
|
|
return _filesCache;
|
|
}
|
|
|
|
try
|
|
{
|
|
_filesCache = JsonSerializer.Deserialize<List<DebridClientFile>>(RdFiles) ?? [];
|
|
}
|
|
catch
|
|
{
|
|
_filesCache = [];
|
|
}
|
|
|
|
return _filesCache;
|
|
}
|
|
}
|
|
|
|
[NotMapped]
|
|
public IList<String> ManualFiles
|
|
{
|
|
get
|
|
{
|
|
if (String.IsNullOrWhiteSpace(DownloadManualFiles))
|
|
{
|
|
return [];
|
|
}
|
|
|
|
return DownloadManualFiles.Split(",");
|
|
}
|
|
}
|
|
}
|