Skip to content

Commit

Permalink
fix: Only apply AllDebrid-specific path fixes to AllDebrid
Browse files Browse the repository at this point in the history
  • Loading branch information
Sculas committed Jan 6, 2025
1 parent d5ee5d2 commit ee9e80f
Show file tree
Hide file tree
Showing 9 changed files with 538 additions and 14 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace RdtClient.Data.Migrations
{
/// <inheritdoc />
public partial class Torrent_Add_ClientKind : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "ClientKind",
table: "Torrents",
type: "INTEGER",
nullable: true);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ClientKind",
table: "Torrents");
}
}
}
3 changes: 3 additions & 0 deletions server/RdtClient.Data/Migrations/DataContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("Category")
.HasColumnType("TEXT");

b.Property<int?>("ClientKind")
.HasColumnType("INTEGER");

b.Property<DateTimeOffset?>("Completed")
.HasColumnType("TEXT");

Expand Down
9 changes: 9 additions & 0 deletions server/RdtClient.Data/Models/Data/Torrent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class Torrent
[InverseProperty("Torrent")]
public IList<Download> Downloads { get; set; } = [];

public TorrentClientKind? ClientKind { get; set; }
public String? RdId { get; set; }
public String? RdName { get; set; }
public Int64? RdSize { get; set; }
Expand Down Expand Up @@ -92,4 +93,12 @@ public IList<String> ManualFiles
return DownloadManualFiles.Split(",");
}
}

public enum TorrentClientKind
{
AllDebrid,
Premiumize,
RealDebrid,
TorBox
}
}
22 changes: 11 additions & 11 deletions server/RdtClient.Service/Helpers/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public static class DownloadHelper
if (matchingTorrentFiles.Count > 0)
{
var matchingTorrentFile = matchingTorrentFiles[0];

var subPath = Path.GetDirectoryName(matchingTorrentFile.Path);

if (!String.IsNullOrWhiteSpace(subPath))
Expand All @@ -49,22 +48,23 @@ public static class DownloadHelper

torrentPath = Path.Combine(torrentPath, subPath);
}
else if (torrent.Files.Count == 1)
{
if (directory != fileName)
{
throw new($"Torrent path {torrentPath} does not match file name {fileName}. This is a requirement for single file torrents.");
}

return torrentPath;
}
}
}
else if (torrent.Files.Count == 1)
{
// Debrid servers such as RealDebrid store single file torrents in a subfolder, but AllDebrid doesn't.
// We should replicate this behavior so that both folder structures are equal.
// See issue: https://github.com/rogerfar/rdt-client/issues/648
if (torrent.ClientKind != Torrent.TorrentClientKind.AllDebrid)
{
torrentPath = Path.Combine(downloadPath, directory);
}

var torrentFile = torrent.Files[0];
var subPath = Path.GetDirectoryName(torrentFile.Path);


// What we think is a single file torrent may also be a folder with a single file in it.
// So make sure we handle that here. If this is not the case, torrentPath will be empty below.
if (!String.IsNullOrWhiteSpace(subPath))
{
subPath = subPath.Trim('/').Trim('\\');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ public async Task<Torrent> UpdateData(Torrent torrent, TorrentClientTorrent? tor
torrent.RdFiles = JsonConvert.SerializeObject(torrentClientTorrent.Files);
}

torrent.ClientKind = Torrent.TorrentClientKind.AllDebrid;
torrent.RdHost = torrentClientTorrent.Host;
torrent.RdSplit = torrentClientTorrent.Split;
torrent.RdProgress = torrentClientTorrent.Progress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public async Task<Torrent> UpdateData(Torrent torrent, TorrentClientTorrent? tor
torrent.RdFiles = JsonConvert.SerializeObject(torrentClientTorrent.Files);
}

torrent.ClientKind = Torrent.TorrentClientKind.Premiumize;
torrent.RdHost = torrentClientTorrent.Host;
torrent.RdSplit = torrentClientTorrent.Split;
torrent.RdProgress = torrentClientTorrent.Progress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public async Task<String> Unrestrict(String link)
torrent.RdFiles = JsonConvert.SerializeObject(torrentClientTorrent.Files);
}

torrent.ClientKind = Data.Models.Data.Torrent.TorrentClientKind.RealDebrid;
torrent.RdHost = torrentClientTorrent.Host;
torrent.RdSplit = torrentClientTorrent.Split;
torrent.RdProgress = torrentClientTorrent.Progress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using RdtClient.Data.Enums;
using RdtClient.Data.Models.TorrentClient;
using System.Web;
using RdtClient.Data.Models.Data;

namespace RdtClient.Service.Services.TorrentClients;

Expand Down Expand Up @@ -167,7 +168,7 @@ public async Task<IList<TorrentClientAvailableFile>> GetAvailableFiles(String ha
return [];
}

public Task SelectFiles(Data.Models.Data.Torrent torrent)
public Task SelectFiles(Torrent torrent)
{
return Task.CompletedTask;
}
Expand All @@ -194,7 +195,7 @@ public async Task<String> Unrestrict(String link)
return result.Data!;
}

public async Task<Data.Models.Data.Torrent> UpdateData(Data.Models.Data.Torrent torrent, TorrentClientTorrent? torrentClientTorrent)
public async Task<Torrent> UpdateData(Torrent torrent, TorrentClientTorrent? torrentClientTorrent)
{
try
{
Expand Down Expand Up @@ -229,6 +230,7 @@ public async Task<String> Unrestrict(String link)
torrent.RdFiles = JsonConvert.SerializeObject(rdTorrent.Files);
}

torrent.ClientKind = Torrent.TorrentClientKind.TorBox;
torrent.RdHost = rdTorrent.Host;
torrent.RdSplit = rdTorrent.Split;
torrent.RdProgress = rdTorrent.Progress;
Expand Down Expand Up @@ -280,7 +282,7 @@ public async Task<String> Unrestrict(String link)
return torrent;
}

public async Task<IList<String>?> GetDownloadLinks(Data.Models.Data.Torrent torrent)
public async Task<IList<String>?> GetDownloadLinks(Torrent torrent)
{
var files = new List<String>();

Expand Down

0 comments on commit ee9e80f

Please sign in to comment.