Fixes missing download of sub folders on premiumize.me.

This commit is contained in:
kungfoolfighting 2023-07-19 00:16:00 +02:00
parent 0a36a3fd20
commit 8629260fe8
14 changed files with 922 additions and 847 deletions

1172
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -36,7 +36,7 @@ public class DownloadData
.FirstOrDefaultAsync(m => m.TorrentId == torrentId && m.Path == path);
}
public async Task<Download> Add(Guid torrentId, String path)
public async Task<Download> Add(Guid torrentId, String path, String folder)
{
var download = new Download
{
@ -45,7 +45,8 @@ public class DownloadData
Path = path,
Added = DateTimeOffset.UtcNow,
DownloadQueued = DateTimeOffset.UtcNow,
RetryCount = 0
RetryCount = 0,
Folder = folder
};
await _dataContext.Downloads.AddAsync(download);

View file

@ -0,0 +1,467 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using RdtClient.Data.Data;
#nullable disable
namespace RdtClient.Data.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20230718151649_Downloads_Add_Folder")]
partial class Downloads_Add_Folder
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "6.0.15");
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("AccessFailedCount")
.HasColumnType("INTEGER");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("TEXT");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<bool>("EmailConfirmed")
.HasColumnType("INTEGER");
b.Property<bool>("LockoutEnabled")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("TEXT");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.Property<string>("PasswordHash")
.HasColumnType("TEXT");
b.Property<string>("PhoneNumber")
.HasColumnType("TEXT");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("INTEGER");
b.Property<string>("SecurityStamp")
.HasColumnType("TEXT");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("INTEGER");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<string>("ClaimType")
.HasColumnType("TEXT");
b.Property<string>("ClaimValue")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("TEXT");
b.Property<string>("ProviderKey")
.HasColumnType("TEXT");
b.Property<string>("ProviderDisplayName")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("LoginProvider")
.HasColumnType("TEXT");
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("RdtClient.Data.Models.Data.Download", b =>
{
b.Property<Guid>("DownloadId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("Added")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("Completed")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("DownloadFinished")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("DownloadQueued")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("DownloadStarted")
.HasColumnType("TEXT");
b.Property<string>("Error")
.HasColumnType("TEXT");
b.Property<string>("Folder")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Link")
.HasColumnType("TEXT");
b.Property<string>("Path")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("RemoteId")
.HasColumnType("TEXT");
b.Property<int>("RetryCount")
.HasColumnType("INTEGER");
b.Property<Guid>("TorrentId")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("UnpackingFinished")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("UnpackingQueued")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("UnpackingStarted")
.HasColumnType("TEXT");
b.HasKey("DownloadId");
b.HasIndex("TorrentId");
b.ToTable("Downloads");
});
modelBuilder.Entity("RdtClient.Data.Models.Data.Setting", b =>
{
b.Property<string>("SettingId")
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("SettingId");
b.ToTable("Settings");
});
modelBuilder.Entity("RdtClient.Data.Models.Data.Torrent", b =>
{
b.Property<Guid>("TorrentId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<DateTimeOffset>("Added")
.HasColumnType("TEXT");
b.Property<string>("Category")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("Completed")
.HasColumnType("TEXT");
b.Property<int>("DeleteOnError")
.HasColumnType("INTEGER");
b.Property<int>("DownloadAction")
.HasColumnType("INTEGER");
b.Property<string>("DownloadManualFiles")
.HasColumnType("TEXT");
b.Property<int>("DownloadMinSize")
.HasColumnType("INTEGER");
b.Property<int>("DownloadRetryAttempts")
.HasColumnType("INTEGER");
b.Property<string>("Error")
.HasColumnType("TEXT");
b.Property<string>("FileOrMagnet")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("FilesSelected")
.HasColumnType("TEXT");
b.Property<int>("FinishedAction")
.HasColumnType("INTEGER");
b.Property<string>("Hash")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("HostDownloadAction")
.HasColumnType("INTEGER");
b.Property<bool>("IsFile")
.HasColumnType("INTEGER");
b.Property<int>("Lifetime")
.HasColumnType("INTEGER");
b.Property<int?>("Priority")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset?>("RdAdded")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("RdEnded")
.HasColumnType("TEXT");
b.Property<string>("RdFiles")
.HasColumnType("TEXT");
b.Property<string>("RdHost")
.HasColumnType("TEXT");
b.Property<string>("RdId")
.HasColumnType("TEXT");
b.Property<string>("RdName")
.HasColumnType("TEXT");
b.Property<long?>("RdProgress")
.HasColumnType("INTEGER");
b.Property<long?>("RdSeeders")
.HasColumnType("INTEGER");
b.Property<long?>("RdSize")
.HasColumnType("INTEGER");
b.Property<long?>("RdSpeed")
.HasColumnType("INTEGER");
b.Property<long?>("RdSplit")
.HasColumnType("INTEGER");
b.Property<int?>("RdStatus")
.HasColumnType("INTEGER");
b.Property<string>("RdStatusRaw")
.HasColumnType("TEXT");
b.Property<DateTimeOffset?>("Retry")
.HasColumnType("TEXT");
b.Property<int>("RetryCount")
.HasColumnType("INTEGER");
b.Property<int>("TorrentRetryAttempts")
.HasColumnType("INTEGER");
b.HasKey("TorrentId");
b.ToTable("Torrents");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
});
modelBuilder.Entity("RdtClient.Data.Models.Data.Download", b =>
{
b.HasOne("RdtClient.Data.Models.Data.Torrent", "Torrent")
.WithMany("Downloads")
.HasForeignKey("TorrentId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Torrent");
});
modelBuilder.Entity("RdtClient.Data.Models.Data.Torrent", b =>
{
b.Navigation("Downloads");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace RdtClient.Data.Migrations
{
public partial class Downloads_Add_Folder : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "Folder",
table: "Downloads",
type: "TEXT",
nullable: false,
defaultValue: "");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Folder",
table: "Downloads");
}
}
}

View file

@ -15,7 +15,7 @@ namespace RdtClient.Data.Migrations
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "6.0.10");
modelBuilder.HasAnnotation("ProductVersion", "6.0.15");
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
@ -233,6 +233,10 @@ namespace RdtClient.Data.Migrations
b.Property<string>("Error")
.HasColumnType("TEXT");
b.Property<string>("Folder")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Link")
.HasColumnType("TEXT");

View file

@ -14,6 +14,7 @@ public class Download
public Torrent? Torrent { get; set; }
public String Path { get; set; } = null!;
public String Folder { get; set; } = null!;
public String? Link { get; set; }
public DateTimeOffset Added { get; set; }

View file

@ -16,17 +16,18 @@ public static class DownloadHelper
var uri = new Uri(fileUrl);
var torrentPath = Path.Combine(downloadPath, torrent.RdName);
var downloadSubFolderPath = Path.Combine(torrentPath, download.Folder);
if (!Directory.Exists(torrentPath))
if (!Directory.Exists(downloadSubFolderPath))
{
Directory.CreateDirectory(torrentPath);
Directory.CreateDirectory(downloadSubFolderPath);
}
var fileName = uri.Segments.Last();
fileName = HttpUtility.UrlDecode(fileName);
var filePath = Path.Combine(torrentPath, fileName);
var filePath = Path.Combine(downloadSubFolderPath, fileName);
return filePath;
}

View file

@ -27,9 +27,9 @@ public class Downloads
return await _downloadData.Get(torrentId, path);
}
public async Task<Download> Add(Guid torrentId, String path)
public async Task<Download> Add(Guid torrentId, String path, String folder )
{
return await _downloadData.Add(torrentId, path);
return await _downloadData.Add(torrentId, path, folder);
}
public async Task UpdateUnrestrictedLink(Guid downloadId, String unrestrictedLink)

View file

@ -250,7 +250,7 @@ public class AllDebridTorrentClient : ITorrentClient
return torrent;
}
public async Task<IList<String>?> GetDownloadLinks(Torrent torrent)
public async Task<IList<Tuple<String, String>>?> GetDownloadLinks(Torrent torrent)
{
if (torrent.RdId == null)
{
@ -298,7 +298,7 @@ public class AllDebridTorrentClient : ITorrentClient
Log("", torrent);
return links.Select(m => m.LinkUrl.ToString()).ToList();
return links.Select(m => new Tuple<String, String>(m.LinkUrl.ToString(), "")).ToList();
}
private async Task<TorrentClientTorrent> GetInfo(String torrentId)

View file

@ -14,5 +14,5 @@ public interface ITorrentClient
Task Delete(String torrentId);
Task<String> Unrestrict(String link);
Task<Torrent> UpdateData(Torrent torrent, TorrentClientTorrent? torrentClientTorrent);
Task<IList<String>?> GetDownloadLinks(Torrent torrent);
Task<IList<Tuple<String, String>>?> GetDownloadLinks(Torrent torrent);
}

View file

@ -1,9 +1,11 @@
using Microsoft.Extensions.Logging;
using AllDebridNET;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using PremiumizeNET;
using RdtClient.Data.Enums;
using RdtClient.Data.Models.TorrentClient;
using RdtClient.Service.Helpers;
using System.Security.Cryptography.Xml;
using Torrent = RdtClient.Data.Models.Data.Torrent;
namespace RdtClient.Service.Services.TorrentClients;
@ -220,7 +222,49 @@ public class PremiumizeTorrentClient : ITorrentClient
return torrent;
}
public async Task<IList<String>?> GetDownloadLinks(Torrent torrent)
private async Task<List<Tuple<String,String>>> GetDownloadLinksFromFolderId(string folderId, string folderPath)
{
var files = await GetClient().Folder.ListAsync(folderId);
Log($"Found {files.Content.Count} items in folder {folderId} with name {files.Name} and breadcrumbs: {files.Breadcrumbs}");
foreach(var crumb in files.Breadcrumbs)
{
Log($"crumb name: {crumb.Name}; crumb Id; {crumb.Id}");
}
foreach (var item in files.Content)
{
Log($"Found item: {item.Name}");
Log($"Id: {item.Id}");
Log($"Size: {item.Size}");
Log($"Folder Id: {item.FolderId}");
Log($"Type: {item.Type}");
Log($"Link: {item.Link}");
}
var downloadLinks = files.Content.Where(m => !String.IsNullOrWhiteSpace(m.Link)).Select(m => m.Link).ToList();
Log($"Found {downloadLinks.Count} links in folder {folderId}");
List<Tuple<String, String>> linksAndFolders = new List<Tuple<string, string>>();
foreach(var downloadLink in downloadLinks)
{
linksAndFolders.Add(new Tuple<String, String>(downloadLink, folderPath));
}
Log($"Added {linksAndFolders.Count} links to returnList");
List<ItemContent> subFolders = files.Content.Where(m => !String.IsNullOrWhiteSpace(m.Id)).Where(m => m.Type =="folder").Select(m => m).ToList();
foreach (var subFolder in subFolders)
{
String subFolderPath = folderPath + subFolder.Name + "/";
var subFolderLinks = await GetDownloadLinksFromFolderId(subFolder.Id, subFolderPath);
linksAndFolders.AddRange(subFolderLinks);
Log($"List contains {linksAndFolders.Count} links after AddRange");
}
Log($"Returning {linksAndFolders.Count} links from sub-folder {folderPath}");
return linksAndFolders;
}
public async Task<IList<Tuple<String, String>>?> GetDownloadLinks(Torrent torrent)
{
if (torrent.RdId == null)
{
@ -238,21 +282,20 @@ public class PremiumizeTorrentClient : ITorrentClient
throw new Exception($"Transfer {torrent.RdId} not found!");
}
List<String> downloadLinks;
Log($"Searching for links in folder {transfer.FolderId}", torrent);
List<Tuple<String,String>> downloadLinks;
if (!String.IsNullOrWhiteSpace(transfer.FolderId))
{
var files = await GetClient().Folder.ListAsync(transfer.FolderId);
downloadLinks = files.Content.Where(m => !String.IsNullOrWhiteSpace(m.Link)).Select(m => m.Link).ToList();
Log($"Found {downloadLinks.Count} links in folder {transfer.FolderId}", torrent);
downloadLinks = await GetDownloadLinksFromFolderId(transfer.FolderId, "");
Log($"Found {downloadLinks.Count} total links", torrent);
}
else if (!String.IsNullOrWhiteSpace(transfer.FileId))
{
var file = await GetClient().Items.DetailsAsync(transfer.FileId);
downloadLinks = new List<String>
downloadLinks = new List<Tuple<String, String>>
{
file.Link
new Tuple<String, String>(file.Link, "")
};
Log($"Found {transfer.FileId}", torrent);
@ -264,7 +307,7 @@ public class PremiumizeTorrentClient : ITorrentClient
foreach (var link in downloadLinks)
{
Log($"{link}", torrent);
Log($"Folder: {link.Item2}; Link: {link.Item1}", torrent);
}
return downloadLinks;

View file

@ -311,7 +311,7 @@ public class RealDebridTorrentClient : ITorrentClient
return torrent;
}
public async Task<IList<String>?> GetDownloadLinks(Data.Models.Data.Torrent torrent)
public async Task<IList<Tuple<String, String>>?> GetDownloadLinks(Data.Models.Data.Torrent torrent)
{
if (torrent.RdId == null)
{
@ -325,7 +325,7 @@ public class RealDebridTorrentClient : ITorrentClient
return null;
}
var downloadLinks = rdTorrent.Links.Where(m => !String.IsNullOrWhiteSpace(m)).ToList();
var downloadLinks = rdTorrent.Links.Where(m => !String.IsNullOrWhiteSpace(m)).Select(m => new Tuple<String, String>(m, "")).ToList();
Log($"Found {downloadLinks.Count} links", torrent);

View file

@ -200,11 +200,11 @@ public class Torrents
foreach (var downloadLink in downloadLinks)
{
// Make sure downloads don't get added multiple times
var downloadExists = await _downloads.Get(torrent.TorrentId, downloadLink);
var downloadExists = await _downloads.Get(torrent.TorrentId, downloadLink.Item1);
if (downloadExists == null && !String.IsNullOrWhiteSpace(downloadLink))
if (downloadExists == null && !String.IsNullOrWhiteSpace(downloadLink.Item1))
{
await _downloads.Add(torrent.TorrentId, downloadLink);
await _downloads.Add(torrent.TorrentId, downloadLink.Item1, downloadLink.Item2);
}
}
}

View file

@ -12,7 +12,7 @@ by editing this MSBuild file. In order to learn more about this please visit htt
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<ProjectGuid>a8c7f095-89c6-4cd1-afb2-27106f470d62</ProjectGuid>
<SelfContained>false</SelfContained>
<publishUrl>..\..\publish\</publishUrl>