From 4889be18900696446f510f99ac80b09b2b330055 Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Tue, 10 Feb 2026 09:52:59 -0600 Subject: [PATCH] Update services to use coding and naming standards --- OF DL.Core/Services/ApiService.cs | 22 +- OF DL.Core/Services/AuthService.cs | 4 +- .../Services/{DBService.cs => DbService.cs} | 269 +++++++------- .../Services/DownloadOrchestrationService.cs | 10 +- OF DL.Core/Services/DownloadService.cs | 329 ++++++++---------- OF DL.Core/Services/FileNameService.cs | 6 +- .../{IAPIService.cs => IApiService.cs} | 30 +- OF DL.Core/Services/IDBService.cs | 27 -- OF DL.Core/Services/IDbService.cs | 31 ++ OF DL.Core/Services/IDownloadService.cs | 10 +- OF DL.Core/Services/ILoggingService.cs | 2 + OF DL.Core/Services/StartupService.cs | 14 +- OF DL/Program.cs | 14 +- 13 files changed, 363 insertions(+), 405 deletions(-) rename OF DL.Core/Services/{DBService.cs => DbService.cs} (65%) rename OF DL.Core/Services/{IAPIService.cs => IApiService.cs} (79%) delete mode 100644 OF DL.Core/Services/IDBService.cs create mode 100644 OF DL.Core/Services/IDbService.cs diff --git a/OF DL.Core/Services/ApiService.cs b/OF DL.Core/Services/ApiService.cs index 9e1eb22..ee08a24 100644 --- a/OF DL.Core/Services/ApiService.cs +++ b/OF DL.Core/Services/ApiService.cs @@ -37,8 +37,8 @@ using SinglePostCollection = OF_DL.Models.Entities.Posts.SinglePostCollection; namespace OF_DL.Services; -public class ApiService(IAuthService authService, IConfigService configService, IDBService dbService) - : IAPIService +public class ApiService(IAuthService authService, IConfigService configService, IDbService dbService) + : IApiService { private const int MaxAttempts = 30; private const int DelayBetweenAttempts = 3000; @@ -200,9 +200,9 @@ public class ApiService(IAuthService authService, IConfigService configService, response.EnsureSuccessStatusCode(); string body = await response.Content.ReadAsStringAsync(); - //if the content creator doesnt exist, we get a 200 response, but the content isnt usable - //so let's not throw an exception, since "content creator no longer exists" is handled elsewhere - //which means we wont get loads of exceptions + // if the content creator doesn't exist, we get a 200 response, but the content isn't usable + // so let's not throw an exception, since "content creator no longer exists" is handled elsewhere + // which means we won't get loads of exceptions if (body.Equals("[]")) { return null; @@ -2897,7 +2897,7 @@ public class ApiService(IAuthService authService, IConfigService configService, } - public async Task GetDRMMPDPSSH(string mpdUrl, string policy, string signature, string kvp) + public async Task GetDrmMpdPssh(string mpdUrl, string policy, string signature, string kvp) { try { @@ -2941,9 +2941,9 @@ public class ApiService(IAuthService authService, IConfigService configService, } - public async Task GetDRMMPDLastModified(string mpdUrl, string policy, string signature, string kvp) + public async Task GetDrmMpdLastModified(string mpdUrl, string policy, string signature, string kvp) { - Log.Debug("Calling GetDRMMPDLastModified"); + Log.Debug("Calling GetDrmMpdLastModified"); Log.Debug($"mpdUrl: {mpdUrl}"); Log.Debug($"policy: {policy}"); Log.Debug($"signature: {signature}"); @@ -2989,10 +2989,10 @@ public class ApiService(IAuthService authService, IConfigService configService, return DateTime.Now; } - public async Task GetDecryptionKeyOFDL(Dictionary drmHeaders, string licenceUrl, + public async Task GetDecryptionKeyOfdl(Dictionary drmHeaders, string licenceUrl, string pssh) { - Log.Debug("Calling GetDecryptionOFDL"); + Log.Debug("Calling GetDecryptionKeyOfdl"); try { @@ -3052,7 +3052,7 @@ public class ApiService(IAuthService authService, IConfigService configService, return string.Empty; } - public async Task GetDecryptionKeyCDM(Dictionary drmHeaders, string licenceUrl, + public async Task GetDecryptionKeyCdm(Dictionary drmHeaders, string licenceUrl, string pssh) { Log.Debug("Calling GetDecryptionKeyCDM"); diff --git a/OF DL.Core/Services/AuthService.cs b/OF DL.Core/Services/AuthService.cs index 45c7afc..bf20e50 100644 --- a/OF DL.Core/Services/AuthService.cs +++ b/OF DL.Core/Services/AuthService.cs @@ -161,8 +161,8 @@ public class AuthService(IServiceProvider serviceProvider) : IAuthService public async Task ValidateAuthAsync() { - // Resolve IAPIService lazily to avoid circular dependency - IAPIService apiService = serviceProvider.GetRequiredService(); + // Resolve IApiService lazily to avoid circular dependency + IApiService apiService = serviceProvider.GetRequiredService(); return await apiService.GetUserInfo("/users/me"); } diff --git a/OF DL.Core/Services/DBService.cs b/OF DL.Core/Services/DbService.cs similarity index 65% rename from OF DL.Core/Services/DBService.cs rename to OF DL.Core/Services/DbService.cs index c9b6df0..eb3543e 100644 --- a/OF DL.Core/Services/DBService.cs +++ b/OF DL.Core/Services/DbService.cs @@ -4,9 +4,9 @@ using Serilog; namespace OF_DL.Services; -public class DBService(IConfigService configService) : IDBService +public class DbService(IConfigService configService) : IDbService { - public async Task CreateDB(string folder) + public async Task CreateDb(string folder) { try { @@ -18,15 +18,15 @@ public class DBService(IConfigService configService) : IDBService string dbFilePath = $"{folder}/Metadata/user_data.db"; // connect to the new database file - using SqliteConnection connection = new($"Data Source={dbFilePath}"); + await using SqliteConnection connection = new($"Data Source={dbFilePath}"); // open the connection connection.Open(); // create the 'medias' table - using (SqliteCommand cmd = - new( - "CREATE TABLE IF NOT EXISTS medias (id INTEGER NOT NULL, media_id INTEGER, post_id INTEGER NOT NULL, link VARCHAR, directory VARCHAR, filename VARCHAR, size INTEGER, api_type VARCHAR, media_type VARCHAR, preview INTEGER, linked VARCHAR, downloaded INTEGER, created_at TIMESTAMP, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(media_id));", - connection)) + await using (SqliteCommand cmd = + new( + "CREATE TABLE IF NOT EXISTS medias (id INTEGER NOT NULL, media_id INTEGER, post_id INTEGER NOT NULL, link VARCHAR, directory VARCHAR, filename VARCHAR, size INTEGER, api_type VARCHAR, media_type VARCHAR, preview INTEGER, linked VARCHAR, downloaded INTEGER, created_at TIMESTAMP, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(media_id));", + connection)) { await cmd.ExecuteNonQueryAsync(); } @@ -36,7 +36,7 @@ public class DBService(IConfigService configService) : IDBService // // Alter existing databases to create unique constraint on `medias` // - using (SqliteCommand cmd = new(@" + await using (SqliteCommand cmd = new(@" PRAGMA foreign_keys=off; BEGIN TRANSACTION; @@ -74,55 +74,55 @@ public class DBService(IConfigService configService) : IDBService } // create the 'messages' table - using (SqliteCommand cmd = - new( - "CREATE TABLE IF NOT EXISTS messages (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, user_id INTEGER, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", - connection)) + await using (SqliteCommand cmd = + new( + "CREATE TABLE IF NOT EXISTS messages (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, user_id INTEGER, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", + connection)) { await cmd.ExecuteNonQueryAsync(); } // create the 'posts' table - using (SqliteCommand cmd = - new( - "CREATE TABLE IF NOT EXISTS posts (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", - connection)) + await using (SqliteCommand cmd = + new( + "CREATE TABLE IF NOT EXISTS posts (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", + connection)) { await cmd.ExecuteNonQueryAsync(); } // create the 'stories' table - using (SqliteCommand cmd = - new( - "CREATE TABLE IF NOT EXISTS stories (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", - connection)) + await using (SqliteCommand cmd = + new( + "CREATE TABLE IF NOT EXISTS stories (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", + connection)) { await cmd.ExecuteNonQueryAsync(); } // create the 'others' table - using (SqliteCommand cmd = - new( - "CREATE TABLE IF NOT EXISTS others (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", - connection)) + await using (SqliteCommand cmd = + new( + "CREATE TABLE IF NOT EXISTS others (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", + connection)) { await cmd.ExecuteNonQueryAsync(); } // create the 'products' table - using (SqliteCommand cmd = - new( - "CREATE TABLE IF NOT EXISTS products (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, title VARCHAR, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", - connection)) + await using (SqliteCommand cmd = + new( + "CREATE TABLE IF NOT EXISTS products (id INTEGER NOT NULL, post_id INTEGER NOT NULL, text VARCHAR, price INTEGER, paid INTEGER, archived BOOLEAN, created_at TIMESTAMP, title VARCHAR, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(post_id));", + connection)) { await cmd.ExecuteNonQueryAsync(); } // create the 'profiles' table - using (SqliteCommand cmd = - new( - "CREATE TABLE IF NOT EXISTS profiles (id INTEGER NOT NULL, user_id INTEGER NOT NULL, username VARCHAR NOT NULL, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(username));", - connection)) + await using (SqliteCommand cmd = + new( + "CREATE TABLE IF NOT EXISTS profiles (id INTEGER NOT NULL, user_id INTEGER NOT NULL, username VARCHAR NOT NULL, record_created_at TIMESTAMP, PRIMARY KEY(id), UNIQUE(username));", + connection)) { await cmd.ExecuteNonQueryAsync(); } @@ -144,19 +144,19 @@ public class DBService(IConfigService configService) : IDBService } } - public async Task CreateUsersDB(Dictionary users) + public async Task CreateUsersDb(Dictionary users) { try { - using SqliteConnection connection = new($"Data Source={Directory.GetCurrentDirectory()}/users.db"); + await using SqliteConnection connection = new($"Data Source={Directory.GetCurrentDirectory()}/users.db"); Log.Debug("Database data source: " + connection.DataSource); connection.Open(); - using (SqliteCommand cmd = - new( - "CREATE TABLE IF NOT EXISTS users (id INTEGER NOT NULL, user_id INTEGER NOT NULL, username VARCHAR NOT NULL, PRIMARY KEY(id), UNIQUE(username));", - connection)) + await using (SqliteCommand cmd = + new( + "CREATE TABLE IF NOT EXISTS users (id INTEGER NOT NULL, user_id INTEGER NOT NULL, username VARCHAR NOT NULL, PRIMARY KEY(id), UNIQUE(username));", + connection)) { await cmd.ExecuteNonQueryAsync(); } @@ -164,29 +164,23 @@ public class DBService(IConfigService configService) : IDBService Log.Debug("Adding missing creators"); foreach (KeyValuePair user in users) { - using (SqliteCommand checkCmd = new("SELECT user_id, username FROM users WHERE user_id = @userId;", - connection)) + await using SqliteCommand checkCmd = new("SELECT user_id, username FROM users WHERE user_id = @userId;", + connection); + checkCmd.Parameters.AddWithValue("@userId", user.Value); + await using SqliteDataReader reader = await checkCmd.ExecuteReaderAsync(); + if (!reader.Read()) { - checkCmd.Parameters.AddWithValue("@userId", user.Value); - using (SqliteDataReader reader = await checkCmd.ExecuteReaderAsync()) - { - if (!reader.Read()) - { - using (SqliteCommand insertCmd = - new("INSERT INTO users (user_id, username) VALUES (@userId, @username);", - connection)) - { - insertCmd.Parameters.AddWithValue("@userId", user.Value); - insertCmd.Parameters.AddWithValue("@username", user.Key); - await insertCmd.ExecuteNonQueryAsync(); - Log.Debug("Inserted new creator: " + user.Key); - } - } - else - { - Log.Debug("Creator " + user.Key + " already exists"); - } - } + await using SqliteCommand insertCmd = + new("INSERT INTO users (user_id, username) VALUES (@userId, @username);", + connection); + insertCmd.Parameters.AddWithValue("@userId", user.Value); + insertCmd.Parameters.AddWithValue("@username", user.Key); + await insertCmd.ExecuteNonQueryAsync(); + Log.Debug("Inserted new creator: " + user.Key); + } + else + { + Log.Debug("Creator " + user.Key + " already exists"); } } @@ -211,12 +205,12 @@ public class DBService(IConfigService configService) : IDBService { try { - using SqliteConnection connection = new($"Data Source={Directory.GetCurrentDirectory()}/users.db"); + await using SqliteConnection connection = new($"Data Source={Directory.GetCurrentDirectory()}/users.db"); connection.Open(); - using (SqliteCommand checkCmd = new("SELECT user_id, username FROM users WHERE user_id = @userId;", - connection)) + await using (SqliteCommand checkCmd = new("SELECT user_id, username FROM users WHERE user_id = @userId;", + connection)) { checkCmd.Parameters.AddWithValue("@userId", user.Value); await using (SqliteDataReader reader = await checkCmd.ExecuteReaderAsync()) @@ -264,16 +258,16 @@ public class DBService(IConfigService configService) : IDBService } } - public async Task AddMessage(string folder, long post_id, string message_text, string price, bool is_paid, - bool is_archived, DateTime created_at, long user_id) + public async Task AddMessage(string folder, long postId, string messageText, string price, bool isPaid, + bool isArchived, DateTime createdAt, long userId) { try { - using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); + await using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); connection.Open(); await EnsureCreatedAtColumnExists(connection, "messages"); - using SqliteCommand cmd = new("SELECT COUNT(*) FROM messages WHERE post_id=@post_id", connection); - cmd.Parameters.AddWithValue("@post_id", post_id); + await using SqliteCommand cmd = new("SELECT COUNT(*) FROM messages WHERE post_id=@post_id", connection); + cmd.Parameters.AddWithValue("@post_id", postId); int count = Convert.ToInt32(await cmd.ExecuteScalarAsync()); if (count == 0) { @@ -282,13 +276,13 @@ public class DBService(IConfigService configService) : IDBService new( "INSERT INTO messages(post_id, text, price, paid, archived, created_at, user_id, record_created_at) VALUES(@post_id, @message_text, @price, @is_paid, @is_archived, @created_at, @user_id, @record_created_at)", connection); - insertCmd.Parameters.AddWithValue("@post_id", post_id); - insertCmd.Parameters.AddWithValue("@message_text", message_text); + insertCmd.Parameters.AddWithValue("@post_id", postId); + insertCmd.Parameters.AddWithValue("@message_text", messageText); insertCmd.Parameters.AddWithValue("@price", price); - insertCmd.Parameters.AddWithValue("@is_paid", is_paid); - insertCmd.Parameters.AddWithValue("@is_archived", is_archived); - insertCmd.Parameters.AddWithValue("@created_at", created_at); - insertCmd.Parameters.AddWithValue("@user_id", user_id); + insertCmd.Parameters.AddWithValue("@is_paid", isPaid); + insertCmd.Parameters.AddWithValue("@is_archived", isArchived); + insertCmd.Parameters.AddWithValue("@created_at", createdAt); + insertCmd.Parameters.AddWithValue("@user_id", userId); insertCmd.Parameters.AddWithValue("@record_created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); await insertCmd.ExecuteNonQueryAsync(); } @@ -309,30 +303,30 @@ public class DBService(IConfigService configService) : IDBService } - public async Task AddPost(string folder, long post_id, string message_text, string price, bool is_paid, - bool is_archived, DateTime created_at) + public async Task AddPost(string folder, long postId, string messageText, string price, bool isPaid, + bool isArchived, DateTime createdAt) { try { - using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); + await using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); connection.Open(); await EnsureCreatedAtColumnExists(connection, "posts"); - using SqliteCommand cmd = new("SELECT COUNT(*) FROM posts WHERE post_id=@post_id", connection); - cmd.Parameters.AddWithValue("@post_id", post_id); + await using SqliteCommand cmd = new("SELECT COUNT(*) FROM posts WHERE post_id=@post_id", connection); + cmd.Parameters.AddWithValue("@post_id", postId); int count = Convert.ToInt32(await cmd.ExecuteScalarAsync()); if (count == 0) { // If the record doesn't exist, insert a new one - using SqliteCommand insertCmd = + await using SqliteCommand insertCmd = new( "INSERT INTO posts(post_id, text, price, paid, archived, created_at, record_created_at) VALUES(@post_id, @message_text, @price, @is_paid, @is_archived, @created_at, @record_created_at)", connection); - insertCmd.Parameters.AddWithValue("@post_id", post_id); - insertCmd.Parameters.AddWithValue("@message_text", message_text); + insertCmd.Parameters.AddWithValue("@post_id", postId); + insertCmd.Parameters.AddWithValue("@message_text", messageText); insertCmd.Parameters.AddWithValue("@price", price); - insertCmd.Parameters.AddWithValue("@is_paid", is_paid); - insertCmd.Parameters.AddWithValue("@is_archived", is_archived); - insertCmd.Parameters.AddWithValue("@created_at", created_at); + insertCmd.Parameters.AddWithValue("@is_paid", isPaid); + insertCmd.Parameters.AddWithValue("@is_archived", isArchived); + insertCmd.Parameters.AddWithValue("@created_at", createdAt); insertCmd.Parameters.AddWithValue("@record_created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); await insertCmd.ExecuteNonQueryAsync(); } @@ -353,30 +347,30 @@ public class DBService(IConfigService configService) : IDBService } - public async Task AddStory(string folder, long post_id, string message_text, string price, bool is_paid, - bool is_archived, DateTime created_at) + public async Task AddStory(string folder, long postId, string messageText, string price, bool isPaid, + bool isArchived, DateTime createdAt) { try { - using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); + await using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); connection.Open(); await EnsureCreatedAtColumnExists(connection, "stories"); - using SqliteCommand cmd = new("SELECT COUNT(*) FROM stories WHERE post_id=@post_id", connection); - cmd.Parameters.AddWithValue("@post_id", post_id); + await using SqliteCommand cmd = new("SELECT COUNT(*) FROM stories WHERE post_id=@post_id", connection); + cmd.Parameters.AddWithValue("@post_id", postId); int count = Convert.ToInt32(await cmd.ExecuteScalarAsync()); if (count == 0) { // If the record doesn't exist, insert a new one - using SqliteCommand insertCmd = + await using SqliteCommand insertCmd = new( "INSERT INTO stories(post_id, text, price, paid, archived, created_at, record_created_at) VALUES(@post_id, @message_text, @price, @is_paid, @is_archived, @created_at, @record_created_at)", connection); - insertCmd.Parameters.AddWithValue("@post_id", post_id); - insertCmd.Parameters.AddWithValue("@message_text", message_text); + insertCmd.Parameters.AddWithValue("@post_id", postId); + insertCmd.Parameters.AddWithValue("@message_text", messageText); insertCmd.Parameters.AddWithValue("@price", price); - insertCmd.Parameters.AddWithValue("@is_paid", is_paid); - insertCmd.Parameters.AddWithValue("@is_archived", is_archived); - insertCmd.Parameters.AddWithValue("@created_at", created_at); + insertCmd.Parameters.AddWithValue("@is_paid", isPaid); + insertCmd.Parameters.AddWithValue("@is_archived", isArchived); + insertCmd.Parameters.AddWithValue("@created_at", createdAt); insertCmd.Parameters.AddWithValue("@record_created_at", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); await insertCmd.ExecuteNonQueryAsync(); } @@ -397,13 +391,13 @@ public class DBService(IConfigService configService) : IDBService } - public async Task AddMedia(string folder, long media_id, long post_id, string link, string? directory, - string? filename, long? size, string api_type, string media_type, bool preview, bool downloaded, - DateTime? created_at) + public async Task AddMedia(string folder, long mediaId, long postId, string link, string? directory, + string? filename, long? size, string apiType, string mediaType, bool preview, bool downloaded, + DateTime? createdAt) { try { - using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); + await using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); connection.Open(); await EnsureCreatedAtColumnExists(connection, "medias"); StringBuilder sql = new("SELECT COUNT(*) FROM medias WHERE media_id=@media_id"); @@ -412,15 +406,15 @@ public class DBService(IConfigService configService) : IDBService sql.Append(" and api_type=@api_type"); } - using SqliteCommand cmd = new(sql.ToString(), connection); - cmd.Parameters.AddWithValue("@media_id", media_id); - cmd.Parameters.AddWithValue("@api_type", api_type); + await using SqliteCommand cmd = new(sql.ToString(), connection); + cmd.Parameters.AddWithValue("@media_id", mediaId); + cmd.Parameters.AddWithValue("@api_type", apiType); int count = Convert.ToInt32(cmd.ExecuteScalar()); if (count == 0) { // If the record doesn't exist, insert a new one - using SqliteCommand insertCmd = new( - $"INSERT INTO medias(media_id, post_id, link, directory, filename, size, api_type, media_type, preview, downloaded, created_at, record_created_at) VALUES({media_id}, {post_id}, '{link}', '{directory ?? "NULL"}', '{filename ?? "NULL"}', {size?.ToString() ?? "NULL"}, '{api_type}', '{media_type}', {Convert.ToInt32(preview)}, {Convert.ToInt32(downloaded)}, '{created_at?.ToString("yyyy-MM-dd HH:mm:ss")}', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')", + await using SqliteCommand insertCmd = new( + $"INSERT INTO medias(media_id, post_id, link, directory, filename, size, api_type, media_type, preview, downloaded, created_at, record_created_at) VALUES({mediaId}, {postId}, '{link}', '{directory ?? "NULL"}', '{filename ?? "NULL"}', {size?.ToString() ?? "NULL"}, '{apiType}', '{mediaType}', {Convert.ToInt32(preview)}, {Convert.ToInt32(downloaded)}, '{createdAt?.ToString("yyyy-MM-dd HH:mm:ss")}', '{DateTime.Now:yyyy-MM-dd HH:mm:ss}')", connection); await insertCmd.ExecuteNonQueryAsync(); } @@ -441,12 +435,10 @@ public class DBService(IConfigService configService) : IDBService } - public async Task CheckDownloaded(string folder, long media_id, string api_type) + public async Task CheckDownloaded(string folder, long mediaId, string apiType) { try { - bool downloaded; - await using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); StringBuilder sql = new("SELECT downloaded FROM medias WHERE media_id=@media_id"); if (configService.CurrentConfig.DownloadDuplicatedMedia) @@ -456,9 +448,9 @@ public class DBService(IConfigService configService) : IDBService connection.Open(); await using SqliteCommand cmd = new(sql.ToString(), connection); - cmd.Parameters.AddWithValue("@media_id", media_id); - cmd.Parameters.AddWithValue("@api_type", api_type); - downloaded = Convert.ToBoolean(await cmd.ExecuteScalarAsync()); + cmd.Parameters.AddWithValue("@media_id", mediaId); + cmd.Parameters.AddWithValue("@api_type", apiType); + bool downloaded = Convert.ToBoolean(await cmd.ExecuteScalarAsync()); return downloaded; } @@ -480,10 +472,10 @@ public class DBService(IConfigService configService) : IDBService } - public async Task UpdateMedia(string folder, long media_id, string api_type, string directory, string filename, - long size, bool downloaded, DateTime created_at) + public async Task UpdateMedia(string folder, long mediaId, string apiType, string directory, string filename, + long size, bool downloaded, DateTime createdAt) { - using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); + await using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); connection.Open(); // Construct the update command @@ -496,33 +488,30 @@ public class DBService(IConfigService configService) : IDBService } // Create a new command object - using SqliteCommand command = new(sql.ToString(), connection); + await using SqliteCommand command = new(sql.ToString(), connection); // Add parameters to the command object command.Parameters.AddWithValue("@directory", directory); command.Parameters.AddWithValue("@filename", filename); command.Parameters.AddWithValue("@size", size); command.Parameters.AddWithValue("@downloaded", downloaded ? 1 : 0); - command.Parameters.AddWithValue("@created_at", created_at); - command.Parameters.AddWithValue("@media_id", media_id); - command.Parameters.AddWithValue("@api_type", api_type); + command.Parameters.AddWithValue("@created_at", createdAt); + command.Parameters.AddWithValue("@media_id", mediaId); + command.Parameters.AddWithValue("@api_type", apiType); // Execute the command await command.ExecuteNonQueryAsync(); } - public async Task GetStoredFileSize(string folder, long media_id, string api_type) + public async Task GetStoredFileSize(string folder, long mediaId, string apiType) { - long size; - using (SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db")) - { - connection.Open(); - using SqliteCommand cmd = new("SELECT size FROM medias WHERE media_id=@media_id and api_type=@api_type", - connection); - cmd.Parameters.AddWithValue("@media_id", media_id); - cmd.Parameters.AddWithValue("@api_type", api_type); - size = Convert.ToInt64(await cmd.ExecuteScalarAsync()); - } + await using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); + connection.Open(); + await using SqliteCommand cmd = new("SELECT size FROM medias WHERE media_id=@media_id and api_type=@api_type", + connection); + cmd.Parameters.AddWithValue("@media_id", mediaId); + cmd.Parameters.AddWithValue("@api_type", apiType); + long size = Convert.ToInt64(await cmd.ExecuteScalarAsync()); return size; } @@ -530,10 +519,9 @@ public class DBService(IConfigService configService) : IDBService public async Task GetMostRecentPostDate(string folder) { DateTime? mostRecentDate = null; - using (SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db")) - { - connection.Open(); - using SqliteCommand cmd = new(@" + await using SqliteConnection connection = new($"Data Source={folder}/Metadata/user_data.db"); + connection.Open(); + await using SqliteCommand cmd = new(@" SELECT MIN(created_at) AS created_at FROM ( @@ -549,11 +537,10 @@ public class DBService(IConfigService configService) : IDBService ON P.post_id = m.post_id WHERE m.downloaded = 0 )", connection); - object? scalarValue = await cmd.ExecuteScalarAsync(); - if (scalarValue != null && scalarValue != DBNull.Value) - { - mostRecentDate = Convert.ToDateTime(scalarValue); - } + object? scalarValue = await cmd.ExecuteScalarAsync(); + if (scalarValue != null && scalarValue != DBNull.Value) + { + mostRecentDate = Convert.ToDateTime(scalarValue); } return mostRecentDate; @@ -561,8 +548,8 @@ public class DBService(IConfigService configService) : IDBService private async Task EnsureCreatedAtColumnExists(SqliteConnection connection, string tableName) { - using SqliteCommand cmd = new($"PRAGMA table_info({tableName});", connection); - using SqliteDataReader reader = await cmd.ExecuteReaderAsync(); + await using SqliteCommand cmd = new($"PRAGMA table_info({tableName});", connection); + await using SqliteDataReader reader = await cmd.ExecuteReaderAsync(); bool columnExists = false; while (await reader.ReadAsync()) @@ -576,7 +563,7 @@ public class DBService(IConfigService configService) : IDBService if (!columnExists) { - using SqliteCommand alterCmd = new($"ALTER TABLE {tableName} ADD COLUMN record_created_at TIMESTAMP;", + await using SqliteCommand alterCmd = new($"ALTER TABLE {tableName} ADD COLUMN record_created_at TIMESTAMP;", connection); await alterCmd.ExecuteNonQueryAsync(); } diff --git a/OF DL.Core/Services/DownloadOrchestrationService.cs b/OF DL.Core/Services/DownloadOrchestrationService.cs index f71177c..f48fa3a 100644 --- a/OF DL.Core/Services/DownloadOrchestrationService.cs +++ b/OF DL.Core/Services/DownloadOrchestrationService.cs @@ -10,10 +10,10 @@ using UserEntities = OF_DL.Models.Entities.Users; namespace OF_DL.Services; public class DownloadOrchestrationService( - IAPIService apiService, + IApiService apiService, IConfigService configService, IDownloadService downloadService, - IDBService dbService) : IDownloadOrchestrationService + IDbService dbService) : IDownloadOrchestrationService { public List PaidPostIds { get; } = new(); @@ -85,7 +85,7 @@ public class DownloadOrchestrationService( } } - await dbService.CreateUsersDB(result.Users); + await dbService.CreateUsersDb(result.Users); return result; } @@ -113,7 +113,7 @@ public class DownloadOrchestrationService( Log.Debug($"Created folder for {username}"); } - await dbService.CreateDB(path); + await dbService.CreateDb(path); } public async Task DownloadCreatorContentAsync( @@ -346,7 +346,7 @@ public class DownloadOrchestrationService( } await apiService.GetUserInfo($"/users/{user.Key}"); - await dbService.CreateDB(path); + await dbService.CreateDb(path); } string basePath = !string.IsNullOrEmpty(config.DownloadPath) diff --git a/OF DL.Core/Services/DownloadService.cs b/OF DL.Core/Services/DownloadService.cs index 5eb046c..e071d24 100644 --- a/OF DL.Core/Services/DownloadService.cs +++ b/OF DL.Core/Services/DownloadService.cs @@ -19,9 +19,9 @@ namespace OF_DL.Services; public class DownloadService( IAuthService authService, IConfigService configService, - IDBService dbService, + IDbService dbService, IFileNameService fileNameService, - IAPIService apiService) + IApiService apiService) : IDownloadService { private TaskCompletionSource _completionSource = new(); @@ -67,7 +67,7 @@ public class DownloadService( Directory.CreateDirectory(folder + subFolder); } - List md5Hashes = CalculateFolderMD5(folder + subFolder); + List md5Hashes = CalculateFolderMd5(folder + subFolder); Uri uri = new(url); string destinationPath = $"{folder}{subFolder}/"; @@ -205,7 +205,7 @@ public class DownloadService( } private async Task OnFFMPEGDownloadComplete(string tempFilename, DateTime lastModified, string folder, string path, - string customFileName, string filename, long media_id, string api_type, IProgressReporter progressReporter) + string customFileName, string filename, long mediaId, string apiType, IProgressReporter progressReporter) { try { @@ -223,16 +223,9 @@ public class DownloadService( long fileSizeInBytes = new FileInfo(!string.IsNullOrEmpty(customFileName) ? folder + path + "/" + customFileName + ".mp4" : tempFilename).Length; - if (configService.CurrentConfig.ShowScrapeSize) - { - progressReporter.ReportProgress(fileSizeInBytes); - } - else - { - progressReporter.ReportProgress(1); - } + progressReporter.ReportProgress(configService.CurrentConfig.ShowScrapeSize ? fileSizeInBytes : 1); - await dbService.UpdateMedia(folder, media_id, api_type, folder + path, + await dbService.UpdateMedia(folder, mediaId, apiType, folder + path, !string.IsNullOrEmpty(customFileName) ? customFileName + ".mp4" : filename + "_source.mp4", fileSizeInBytes, true, lastModified); } @@ -266,32 +259,27 @@ public class DownloadService( _completionSource.TrySetResult(false); } - private static List CalculateFolderMD5(string folder) + private static List CalculateFolderMd5(string folder) { - List md5Hashes = new(); - if (Directory.Exists(folder)) + List md5Hashes = []; + if (!Directory.Exists(folder)) { - string[] files = Directory.GetFiles(folder); - - foreach (string file in files) - { - md5Hashes.Add(CalculateMD5(file)); - } + return md5Hashes; } + string[] files = Directory.GetFiles(folder); + + md5Hashes.AddRange(files.Select(CalculateMd5)); + return md5Hashes; } - private static string CalculateMD5(string filePath) + private static string CalculateMd5(string filePath) { - using (MD5 md5 = MD5.Create()) - { - using (FileStream stream = File.OpenRead(filePath)) - { - byte[] hash = md5.ComputeHash(stream); - return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); - } - } + using MD5 md5 = MD5.Create(); + using FileStream stream = File.OpenRead(filePath); + byte[] hash = md5.ComputeHash(stream); + return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } /// @@ -299,17 +287,17 @@ public class DownloadService( /// /// /// - /// - /// + /// + /// /// /// /// /// - protected async Task CreateDirectoriesAndDownloadMedia(string path, + private async Task CreateDirectoriesAndDownloadMedia(string path, string url, string folder, - long media_id, - string api_type, + long mediaId, + string apiType, IProgressReporter progressReporter, string serverFileName, string resolvedFileName) @@ -325,7 +313,7 @@ public class DownloadService( path = UpdatePathBasedOnExtension(folder, path, extension); - return await ProcessMediaDownload(folder, media_id, api_type, url, path, serverFileName, resolvedFileName, + return await ProcessMediaDownload(folder, mediaId, apiType, url, path, serverFileName, resolvedFileName, extension, progressReporter); } catch (Exception ex) @@ -461,12 +449,12 @@ public class DownloadService( if (uri.Host == "cdn3.onlyfans.com" && uri.LocalPath.Contains("/dash/files")) { string[] messageUrlParsed = url.Split(','); - string mpdURL = messageUrlParsed[0]; + string mpdUrl = messageUrlParsed[0]; string policy = messageUrlParsed[1]; string signature = messageUrlParsed[2]; string kvp = messageUrlParsed[3]; - mpdURL = mpdURL.Replace(".mpd", "_source.mp4"); + mpdUrl = mpdUrl.Replace(".mpd", "_source.mp4"); using HttpClient client = new(); client.DefaultRequestHeaders.Add("Cookie", @@ -474,7 +462,7 @@ public class DownloadService( client.DefaultRequestHeaders.Add("User-Agent", authService.CurrentAuth.UserAgent); using HttpResponseMessage response = - await client.GetAsync(mpdURL, HttpCompletionOption.ResponseHeadersRead); + await client.GetAsync(mpdUrl, HttpCompletionOption.ResponseHeadersRead); if (response.IsSuccessStatusCode) { fileSize = response.Content.Headers.ContentLength ?? 0; @@ -500,7 +488,7 @@ public class DownloadService( return fileSize; } - public static async Task GetDRMVideoLastModified(string url, Auth auth) + public static async Task GetDrmVideoLastModified(string url, Auth auth) { string[] messageUrlParsed = url.Split(','); string mpdUrl = messageUrlParsed[0]; @@ -532,15 +520,12 @@ public class DownloadService( using HttpClient client = new(); using HttpResponseMessage response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); - if (response.IsSuccessStatusCode) + if (!response.IsSuccessStatusCode) { - if (response.Content.Headers.LastModified != null) - { - return response.Content.Headers.LastModified.Value.DateTime; - } + return DateTime.Now; } - return DateTime.Now; + return response.Content.Headers.LastModified?.DateTime ?? DateTime.Now; } /// @@ -636,8 +621,8 @@ public class DownloadService( /// Handles new media by downloading and updating the database. /// /// - /// - /// + /// + /// /// /// /// @@ -646,8 +631,8 @@ public class DownloadService( /// /// A Task resulting in a boolean indicating whether the media is newly downloaded or not. private async Task HandleNewMedia(string folder, - long media_id, - string api_type, + long mediaId, + string apiType, string url, string path, string serverFilename, @@ -696,32 +681,18 @@ public class DownloadService( fileSizeInBytes = GetLocalFileSize(finalPath); lastModified = File.GetLastWriteTime(finalPath); - if (configService.CurrentConfig.ShowScrapeSize) - { - progressReporter.ReportProgress(fileSizeInBytes); - } - else - { - progressReporter.ReportProgress(1); - } + progressReporter.ReportProgress(configService.CurrentConfig.ShowScrapeSize ? fileSizeInBytes : 1); status = false; } // Handle the case where the file has been downloaded in the past with a custom filename. - //but it has downloaded outsite of this application so it doesn't exist in the database + // but it has downloaded outside of this application so it doesn't exist in the database // this is a bit improbable but we should check for that. else if (File.Exists(fullPathWithTheNewFileName)) { fileSizeInBytes = GetLocalFileSize(fullPathWithTheNewFileName); lastModified = File.GetLastWriteTime(fullPathWithTheNewFileName); - if (configService.CurrentConfig.ShowScrapeSize) - { - progressReporter.ReportProgress(fileSizeInBytes); - } - else - { - progressReporter.ReportProgress(1); - } + progressReporter.ReportProgress(configService.CurrentConfig.ShowScrapeSize ? fileSizeInBytes : 1); status = false; } @@ -733,9 +704,9 @@ public class DownloadService( } //finaly check which filename we should use. Custom or the server one. - //if a custom is used, then the servefilename will be different from the resolved filename. + //if a custom is used, then the serverFilename will be different from the resolved filename. string finalName = serverFilename == resolvedFilename ? serverFilename : resolvedFilename; - await dbService.UpdateMedia(folder, media_id, api_type, folder + path, finalName + extension, fileSizeInBytes, + await dbService.UpdateMedia(folder, mediaId, apiType, folder + path, finalName + extension, fileSizeInBytes, true, lastModified); return status; } @@ -745,16 +716,16 @@ public class DownloadService( /// Handles media that has been previously downloaded and updates the task accordingly. /// /// - /// - /// + /// + /// /// /// A boolean indicating whether the media is newly downloaded or not. - private async Task HandlePreviouslyDownloadedMediaAsync(string folder, long media_id, string api_type, + private async Task HandlePreviouslyDownloadedMediaAsync(string folder, long mediaId, string apiType, IProgressReporter progressReporter) { if (configService.CurrentConfig.ShowScrapeSize) { - long size = await dbService.GetStoredFileSize(folder, media_id, api_type); + long size = await dbService.GetStoredFileSize(folder, mediaId, apiType); progressReporter.ReportProgress(size); } else @@ -791,11 +762,12 @@ public class DownloadService( Stream body = await response.Content.ReadAsStreamAsync(); // Wrap the body stream with the ThrottledStream to limit read rate. - using (ThrottledStream throttledStream = new(body, - configService.CurrentConfig.DownloadLimitInMbPerSec * 1_000_000, - configService.CurrentConfig.LimitDownloadRate)) + await using (ThrottledStream throttledStream = new(body, + configService.CurrentConfig.DownloadLimitInMbPerSec * 1_000_000, + configService.CurrentConfig.LimitDownloadRate)) { - using FileStream fileStream = new(destinationPath, FileMode.Create, FileAccess.Write, FileShare.None, 16384, + await using FileStream fileStream = new(destinationPath, FileMode.Create, FileAccess.Write, FileShare.None, + 16384, true); byte[] buffer = new byte[16384]; int read; @@ -854,7 +826,7 @@ public class DownloadService( return totalFileSize; } - public async Task DownloadMedia(string url, string folder, long media_id, string api_type, + public async Task DownloadMedia(string url, string folder, long mediaId, string apiType, IProgressReporter progressReporter, string path, string? filenameFormat, object? postInfo, object? postMedia, object? author, Dictionary users) @@ -864,12 +836,12 @@ public class DownloadService( string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, folder.Split("/")[^1], users, fileNameService, CustomFileNameOption.ReturnOriginal); - return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, api_type, progressReporter, + return await CreateDirectoriesAndDownloadMedia(path, url, folder, mediaId, apiType, progressReporter, filename, resolvedFilename); } - public async Task DownloadDRMVideo(string policy, string signature, string kvp, string url, - string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, + public async Task DownloadDrmVideo(string policy, string signature, string kvp, string url, + string decryptionKey, string folder, DateTime lastModified, long mediaId, string apiType, IProgressReporter progressReporter, string path, string? filenameFormat, object? postInfo, object? postMedia, object? author, Dictionary users) @@ -902,14 +874,14 @@ public class DownloadService( string customFileName = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, folder.Split("/")[^1], users, fileNameService, CustomFileNameOption.ReturnEmpty); - if (!await dbService.CheckDownloaded(folder, media_id, api_type)) + if (!await dbService.CheckDownloaded(folder, mediaId, apiType)) { if (!string.IsNullOrEmpty(customFileName) ? !File.Exists(folder + path + "/" + customFileName + ".mp4") : !File.Exists(folder + path + "/" + filename + "_source.mp4")) { return await DownloadDrmMedia(authService.CurrentAuth.UserAgent, policy, signature, kvp, - authService.CurrentAuth.Cookie, url, decryptionKey, folder, lastModified, media_id, api_type, + authService.CurrentAuth.Cookie, url, decryptionKey, folder, lastModified, mediaId, apiType, progressReporter, customFileName, filename, path); } @@ -918,7 +890,7 @@ public class DownloadService( : folder + path + "/" + filename + "_source.mp4").Length; ReportProgress(progressReporter, fileSizeInBytes); - await dbService.UpdateMedia(folder, media_id, api_type, folder + path, + await dbService.UpdateMedia(folder, mediaId, apiType, folder + path, !string.IsNullOrEmpty(customFileName) ? customFileName + ".mp4" : filename + "_source.mp4", fileSizeInBytes, true, lastModified); } @@ -946,15 +918,15 @@ public class DownloadService( return false; } - long size = await dbService.GetStoredFileSize(folder, media_id, api_type); - await dbService.UpdateMedia(folder, media_id, api_type, folder + path, customFileName + ".mp4", + long size = await dbService.GetStoredFileSize(folder, mediaId, apiType); + await dbService.UpdateMedia(folder, mediaId, apiType, folder + path, customFileName + ".mp4", size, true, lastModified); } } if (configService.CurrentConfig.ShowScrapeSize) { - long size = await dbService.GetStoredFileSize(folder, media_id, api_type); + long size = await dbService.GetStoredFileSize(folder, mediaId, apiType); progressReporter.ReportProgress(size); } else @@ -982,26 +954,17 @@ public class DownloadService( return false; } - private void ReportProgress(IProgressReporter reporter, long sizeOrCount) - { - if (configService.CurrentConfig.ShowScrapeSize) - { - reporter.ReportProgress(sizeOrCount); - } - else - { - reporter.ReportProgress(1); - } - } + private void ReportProgress(IProgressReporter reporter, long sizeOrCount) => + reporter.ReportProgress(configService.CurrentConfig.ShowScrapeSize ? sizeOrCount : 1); public async Task<(string decryptionKey, DateTime lastModified)?> GetDecryptionInfo( string mpdUrl, string policy, string signature, string kvp, string mediaId, string contentId, string drmType, bool clientIdBlobMissing, bool devicePrivateKeyMissing) { - string pssh = await apiService.GetDRMMPDPSSH(mpdUrl, policy, signature, kvp); + string pssh = await apiService.GetDrmMpdPssh(mpdUrl, policy, signature, kvp); - DateTime lastModified = await apiService.GetDRMMPDLastModified(mpdUrl, policy, signature, kvp); + DateTime lastModified = await apiService.GetDrmMpdLastModified(mpdUrl, policy, signature, kvp); Dictionary drmHeaders = apiService.GetDynamicHeaders($"/api2/v2/users/media/{mediaId}/drm/{drmType}/{contentId}", "?type=widevine"); @@ -1009,8 +972,8 @@ public class DownloadService( $"https://onlyfans.com/api2/v2/users/media/{mediaId}/drm/{drmType}/{contentId}?type=widevine"; string decryptionKey = clientIdBlobMissing || devicePrivateKeyMissing - ? await apiService.GetDecryptionKeyOFDL(drmHeaders, licenseUrl, pssh) - : await apiService.GetDecryptionKeyCDM(drmHeaders, licenseUrl, pssh); + ? await apiService.GetDecryptionKeyOfdl(drmHeaders, licenseUrl, pssh) + : await apiService.GetDecryptionKeyCdm(drmHeaders, licenseUrl, pssh); return (decryptionKey, lastModified); } @@ -1041,10 +1004,10 @@ public class DownloadService( int oldHighlightsCount = 0; int newHighlightsCount = 0; - foreach (KeyValuePair highlightKVP in highlights) + foreach (KeyValuePair highlightKvp in highlights) { bool isNew = - await DownloadMedia(highlightKVP.Value, path, highlightKVP.Key, "Stories", progressReporter, + await DownloadMedia(highlightKvp.Value, path, highlightKvp.Key, "Stories", progressReporter, "/Stories/Free", null, null, null, null, new Dictionary()); if (isNew) { @@ -1095,9 +1058,9 @@ public class DownloadService( int oldStoriesCount = 0; int newStoriesCount = 0; - foreach (KeyValuePair storyKVP in stories) + foreach (KeyValuePair storyKvp in stories) { - bool isNew = await DownloadMedia(storyKVP.Value, path, storyKVP.Key, "Stories", progressReporter, + bool isNew = await DownloadMedia(storyKvp.Value, path, storyKvp.Key, "Stories", progressReporter, "/Stories/Free", null, null, null, null, new Dictionary()); if (isNew) { @@ -1146,20 +1109,20 @@ public class DownloadService( int oldArchivedCount = 0; int newArchivedCount = 0; - foreach (KeyValuePair archivedKVP in archived.ArchivedPosts) + foreach (KeyValuePair archivedKvp in archived.ArchivedPosts) { bool isNew; ArchivedEntities.Medium? mediaInfo = - archived.ArchivedPostMedia.FirstOrDefault(m => m.Id == archivedKVP.Key); + archived.ArchivedPostMedia.FirstOrDefault(m => m.Id == archivedKvp.Key); ArchivedEntities.ListItem? postInfo = mediaInfo == null ? null : archived.ArchivedPostObjects.FirstOrDefault(p => p.Media?.Contains(mediaInfo) == true); string filenameFormat = configService.CurrentConfig.GetCreatorFileNameFormatConfig(username).PostFileNameFormat ?? ""; - if (archivedKVP.Value.Contains("cdn3.onlyfans.com/dash/files")) + if (archivedKvp.Value.Contains("cdn3.onlyfans.com/dash/files")) { - string[] parsed = archivedKVP.Value.Split(','); + string[] parsed = archivedKvp.Value.Split(','); (string decryptionKey, DateTime lastModified)? drmInfo = await GetDecryptionInfo(parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], "post", clientIdBlobMissing, devicePrivateKeyMissing); @@ -1168,14 +1131,14 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], - drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, archivedKVP.Key, "Posts", + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], + drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, archivedKvp.Key, "Posts", progressReporter, "/Archived/Posts/Free/Videos", filenameFormat, postInfo, mediaInfo, postInfo?.Author, users); } else { - isNew = await DownloadMedia(archivedKVP.Value, path, archivedKVP.Key, "Posts", progressReporter, + isNew = await DownloadMedia(archivedKvp.Value, path, archivedKvp.Key, "Posts", progressReporter, "/Archived/Posts/Free", filenameFormat, postInfo, mediaInfo, postInfo?.Author, users); } @@ -1226,12 +1189,12 @@ public class DownloadService( int oldMessagesCount = 0; int newMessagesCount = 0; - foreach (KeyValuePair messageKVP in messages.Messages) + foreach (KeyValuePair messageKvp in messages.Messages) { bool isNew; - MessageEntities.Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.Id == messageKVP.Key); + MessageEntities.Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.Id == messageKvp.Key); MessageEntities.ListItem? messageInfo = messages.MessageObjects.FirstOrDefault(p => - p.Media?.Any(m => m.Id == messageKVP.Key) == true); + p.Media?.Any(m => m.Id == messageKvp.Key) == true); string filenameFormat = configService.CurrentConfig.GetCreatorFileNameFormatConfig(username).MessageFileNameFormat ?? ""; string messagePath = configService.CurrentConfig.FolderPerMessage && messageInfo != null && @@ -1239,9 +1202,9 @@ public class DownloadService( ? $"/Messages/Free/{messageInfo.Id} {messageInfo.CreatedAt.Value:yyyy-MM-dd HH-mm-ss}" : "/Messages/Free"; - if (messageKVP.Value.Contains("cdn3.onlyfans.com/dash/files")) + if (messageKvp.Value.Contains("cdn3.onlyfans.com/dash/files")) { - string[] parsed = messageKVP.Value.Split(','); + string[] parsed = messageKvp.Value.Split(','); (string decryptionKey, DateTime lastModified)? drmInfo = await GetDecryptionInfo(parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], "message", clientIdBlobMissing, devicePrivateKeyMissing); @@ -1250,14 +1213,14 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], - drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, messageKVP.Key, "Messages", + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], + drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, messageKvp.Key, "Messages", progressReporter, messagePath + "/Videos", filenameFormat, messageInfo, mediaInfo, messageInfo?.FromUser, users); } else { - isNew = await DownloadMedia(messageKVP.Value, path, messageKVP.Key, "Messages", progressReporter, + isNew = await DownloadMedia(messageKvp.Value, path, messageKvp.Key, "Messages", progressReporter, messagePath, filenameFormat, messageInfo, mediaInfo, messageInfo?.FromUser, users); } @@ -1335,7 +1298,7 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, kvpEntry.Key, "Messages", progressReporter, paidMsgPath + "/Videos", filenameFormat, messageInfo, mediaInfo, messageInfo?.FromUser, users); @@ -1415,7 +1378,7 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, kvpEntry.Key, "Streams", progressReporter, streamPath + "/Videos", filenameFormat, streamInfo, mediaInfo, streamInfo?.Author, users); @@ -1471,10 +1434,10 @@ public class DownloadService( int oldCount = 0, newCount = 0; - foreach (KeyValuePair postKVP in posts.Posts) + foreach (KeyValuePair postKvp in posts.Posts) { bool isNew; - PostEntities.Medium? mediaInfo = posts.PostMedia.FirstOrDefault(m => m.Id == postKVP.Key); + PostEntities.Medium? mediaInfo = posts.PostMedia.FirstOrDefault(m => m.Id == postKvp.Key); PostEntities.ListItem? postInfo = mediaInfo == null ? null : posts.PostObjects.FirstOrDefault(p => p.Media?.Contains(mediaInfo) == true); @@ -1484,9 +1447,9 @@ public class DownloadService( ? $"/Posts/Free/{postInfo.Id} {postInfo.PostedAt:yyyy-MM-dd HH-mm-ss}" : "/Posts/Free"; - if (postKVP.Value.Contains("cdn3.onlyfans.com/dash/files")) + if (postKvp.Value.Contains("cdn3.onlyfans.com/dash/files")) { - string[] parsed = postKVP.Value.Split(','); + string[] parsed = postKvp.Value.Split(','); (string decryptionKey, DateTime lastModified)? drmInfo = await GetDecryptionInfo(parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], "post", clientIdBlobMissing, devicePrivateKeyMissing); @@ -1495,14 +1458,14 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], - drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, postKVP.Key, "Posts", + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], + drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, postKvp.Key, "Posts", progressReporter, postPath + "/Videos", filenameFormat, postInfo, mediaInfo, postInfo?.Author, users); } else { - isNew = await DownloadMedia(postKVP.Value, path, postKVP.Key, "Posts", progressReporter, + isNew = await DownloadMedia(postKvp.Value, path, postKvp.Key, "Posts", progressReporter, postPath, filenameFormat, postInfo, mediaInfo, postInfo?.Author, users); } @@ -1551,13 +1514,13 @@ public class DownloadService( int oldCount = 0, newCount = 0; - foreach (KeyValuePair postKVP in purchasedPosts.PaidPosts) + foreach (KeyValuePair postKvp in purchasedPosts.PaidPosts) { bool isNew; MessageEntities.Medium? mediaInfo = - purchasedPosts.PaidPostMedia.FirstOrDefault(m => m.Id == postKVP.Key); + purchasedPosts.PaidPostMedia.FirstOrDefault(m => m.Id == postKvp.Key); PurchasedEntities.ListItem? postInfo = - purchasedPosts.PaidPostObjects.FirstOrDefault(p => p.Media?.Any(m => m.Id == postKVP.Key) == true); + purchasedPosts.PaidPostObjects.FirstOrDefault(p => p.Media?.Any(m => m.Id == postKvp.Key) == true); string filenameFormat = configService.CurrentConfig.GetCreatorFileNameFormatConfig(username).PostFileNameFormat ?? ""; string paidPostPath = configService.CurrentConfig.FolderPerPaidPost && postInfo != null && @@ -1565,9 +1528,9 @@ public class DownloadService( ? $"/Posts/Paid/{postInfo.Id} {postInfo.PostedAt.Value:yyyy-MM-dd HH-mm-ss}" : "/Posts/Paid"; - if (postKVP.Value.Contains("cdn3.onlyfans.com/dash/files")) + if (postKvp.Value.Contains("cdn3.onlyfans.com/dash/files")) { - string[] parsed = postKVP.Value.Split(','); + string[] parsed = postKvp.Value.Split(','); (string decryptionKey, DateTime lastModified)? drmInfo = await GetDecryptionInfo(parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], "post", clientIdBlobMissing, devicePrivateKeyMissing); @@ -1576,14 +1539,14 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], - drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, postKVP.Key, "Posts", + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], + drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, postKvp.Key, "Posts", progressReporter, paidPostPath + "/Videos", filenameFormat, postInfo, mediaInfo, postInfo?.FromUser, users); } else { - isNew = await DownloadMedia(postKVP.Value, path, postKVP.Key, "Posts", progressReporter, + isNew = await DownloadMedia(postKvp.Value, path, postKvp.Key, "Posts", progressReporter, paidPostPath, filenameFormat, postInfo, mediaInfo, postInfo?.FromUser, users); } @@ -1622,14 +1585,14 @@ public class DownloadService( int oldCount = 0, newCount = 0; - foreach (KeyValuePair purchasedPostKVP in purchasedPosts.PaidPosts) + foreach (KeyValuePair purchasedPostKvp in purchasedPosts.PaidPosts) { bool isNew; MessageEntities.Medium? mediaInfo = - purchasedPosts?.PaidPostMedia?.FirstOrDefault(m => m.Id == purchasedPostKVP.Key); + purchasedPosts?.PaidPostMedia?.FirstOrDefault(m => m.Id == purchasedPostKvp.Key); PurchasedEntities.ListItem? postInfo = mediaInfo != null ? purchasedPosts?.PaidPostObjects?.FirstOrDefault(p => - p.Media?.Any(m => m.Id == purchasedPostKVP.Key) == true) + p.Media?.Any(m => m.Id == purchasedPostKvp.Key) == true) : null; string filenameFormat = configService.CurrentConfig.GetCreatorFileNameFormatConfig(username) .PaidPostFileNameFormat ?? ""; @@ -1638,9 +1601,9 @@ public class DownloadService( ? $"/Posts/Paid/{postInfo.Id} {postInfo.PostedAt.Value:yyyy-MM-dd HH-mm-ss}" : "/Posts/Paid"; - if (purchasedPostKVP.Value.Contains("cdn3.onlyfans.com/dash/files")) + if (purchasedPostKvp.Value.Contains("cdn3.onlyfans.com/dash/files")) { - string[] parsed = purchasedPostKVP.Value.Split(','); + string[] parsed = purchasedPostKvp.Value.Split(','); (string decryptionKey, DateTime lastModified)? drmInfo = await GetDecryptionInfo(parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], "post", clientIdBlobMissing, devicePrivateKeyMissing); @@ -1649,15 +1612,15 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], - drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, purchasedPostKVP.Key, + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], + drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, purchasedPostKvp.Key, "Posts", progressReporter, paidPostPath + "/Videos", filenameFormat, postInfo, mediaInfo, postInfo?.FromUser, users); } else { - isNew = await DownloadMedia(purchasedPostKVP.Value, path, - purchasedPostKVP.Key, "Posts", progressReporter, + isNew = await DownloadMedia(purchasedPostKvp.Value, path, + purchasedPostKvp.Key, "Posts", progressReporter, paidPostPath, filenameFormat, postInfo, mediaInfo, postInfo?.FromUser, users); } @@ -1696,14 +1659,14 @@ public class DownloadService( int oldCount = 0, newCount = 0; - foreach (KeyValuePair paidMessageKVP in paidMessageCollection.PaidMessages) + foreach (KeyValuePair paidMessageKvp in paidMessageCollection.PaidMessages) { bool isNew; MessageEntities.Medium? mediaInfo = - paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.Id == paidMessageKVP.Key); + paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.Id == paidMessageKvp.Key); PurchasedEntities.ListItem? messageInfo = paidMessageCollection.PaidMessageObjects.FirstOrDefault(p => - p.Media?.Any(m => m.Id == paidMessageKVP.Key) == true); + p.Media?.Any(m => m.Id == paidMessageKvp.Key) == true); string filenameFormat = configService.CurrentConfig.GetCreatorFileNameFormatConfig(username) .PaidMessageFileNameFormat ?? ""; string paidMsgPath = configService.CurrentConfig.FolderPerPaidMessage && messageInfo != null && @@ -1711,9 +1674,9 @@ public class DownloadService( ? $"/Messages/Paid/{messageInfo.Id} {messageInfo.CreatedAt.Value:yyyy-MM-dd HH-mm-ss}" : "/Messages/Paid"; - if (paidMessageKVP.Value.Contains("cdn3.onlyfans.com/dash/files")) + if (paidMessageKvp.Value.Contains("cdn3.onlyfans.com/dash/files")) { - string[] parsed = paidMessageKVP.Value.Split(','); + string[] parsed = paidMessageKvp.Value.Split(','); (string decryptionKey, DateTime lastModified)? drmInfo = await GetDecryptionInfo(parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], "message", clientIdBlobMissing, devicePrivateKeyMissing); @@ -1722,15 +1685,15 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], - drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, paidMessageKVP.Key, + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], + drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, paidMessageKvp.Key, "Messages", progressReporter, paidMsgPath + "/Videos", filenameFormat, messageInfo, mediaInfo, messageInfo?.FromUser, users); } else { - isNew = await DownloadMedia(paidMessageKVP.Value, path, - paidMessageKVP.Key, "Messages", progressReporter, + isNew = await DownloadMedia(paidMessageKvp.Value, path, + paidMessageKvp.Key, "Messages", progressReporter, paidMsgPath, filenameFormat, messageInfo, mediaInfo, messageInfo?.FromUser, users); } @@ -1769,9 +1732,9 @@ public class DownloadService( int oldCount = 0, newCount = 0; - foreach (KeyValuePair postKVP in post.SinglePosts) + foreach (KeyValuePair postKvp in post.SinglePosts) { - PostEntities.Medium? mediaInfo = post.SinglePostMedia.FirstOrDefault(m => m.Id == postKVP.Key); + PostEntities.Medium? mediaInfo = post.SinglePostMedia.FirstOrDefault(m => m.Id == postKvp.Key); PostEntities.SinglePost? postInfo = mediaInfo == null ? null : post.SinglePostObjects.FirstOrDefault(p => p.Media?.Contains(mediaInfo) == true); @@ -1782,9 +1745,9 @@ public class DownloadService( : "/Posts/Free"; bool isNew; - if (postKVP.Value.Contains("cdn3.onlyfans.com/dash/files")) + if (postKvp.Value.Contains("cdn3.onlyfans.com/dash/files")) { - string[] parsed = postKVP.Value.Split(','); + string[] parsed = postKvp.Value.Split(','); (string decryptionKey, DateTime lastModified)? drmInfo = await GetDecryptionInfo(parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], "post", clientIdBlobMissing, devicePrivateKeyMissing); @@ -1793,8 +1756,8 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], - drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, postKVP.Key, "Posts", + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], + drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, postKvp.Key, "Posts", progressReporter, postPath + "/Videos", filenameFormat, postInfo, mediaInfo, postInfo?.Author, users); } @@ -1802,8 +1765,8 @@ public class DownloadService( { try { - isNew = await DownloadMedia(postKVP.Value, path, - postKVP.Key, "Posts", progressReporter, + isNew = await DownloadMedia(postKvp.Value, path, + postKvp.Key, "Posts", progressReporter, postPath, filenameFormat, postInfo, mediaInfo, postInfo?.Author, users); } catch @@ -1845,14 +1808,14 @@ public class DownloadService( // Download preview messages if (singlePaidMessageCollection.PreviewSingleMessages.Count > 0) { - foreach (KeyValuePair paidMessageKVP in singlePaidMessageCollection.PreviewSingleMessages) + foreach (KeyValuePair paidMessageKvp in singlePaidMessageCollection.PreviewSingleMessages) { MessageEntities.Medium? mediaInfo = singlePaidMessageCollection.PreviewSingleMessageMedia.FirstOrDefault(m => - m.Id == paidMessageKVP.Key); + m.Id == paidMessageKvp.Key); MessageEntities.SingleMessage? messageInfo = singlePaidMessageCollection.SingleMessageObjects.FirstOrDefault(p => - p.Media?.Any(m => m.Id == paidMessageKVP.Key) == true); + p.Media?.Any(m => m.Id == paidMessageKvp.Key) == true); string filenameFormat = configService.CurrentConfig.GetCreatorFileNameFormatConfig(username) .PaidMessageFileNameFormat ?? ""; string previewMsgPath = configService.CurrentConfig.FolderPerMessage && messageInfo != null && @@ -1861,9 +1824,9 @@ public class DownloadService( : "/Messages/Free"; bool isNew; - if (paidMessageKVP.Value.Contains("cdn3.onlyfans.com/dash/files")) + if (paidMessageKvp.Value.Contains("cdn3.onlyfans.com/dash/files")) { - string[] parsed = paidMessageKVP.Value.Split(','); + string[] parsed = paidMessageKvp.Value.Split(','); (string decryptionKey, DateTime lastModified)? drmInfo = await GetDecryptionInfo(parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], "message", clientIdBlobMissing, devicePrivateKeyMissing); @@ -1872,15 +1835,15 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], - drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, paidMessageKVP.Key, + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], + drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, paidMessageKvp.Key, "Messages", progressReporter, previewMsgPath + "/Videos", filenameFormat, messageInfo, mediaInfo, messageInfo?.FromUser, users); } else { - isNew = await DownloadMedia(paidMessageKVP.Value, path, - paidMessageKVP.Key, "Messages", progressReporter, + isNew = await DownloadMedia(paidMessageKvp.Value, path, + paidMessageKvp.Key, "Messages", progressReporter, previewMsgPath, filenameFormat, messageInfo, mediaInfo, messageInfo?.FromUser, users); } @@ -1898,14 +1861,14 @@ public class DownloadService( // Download actual paid messages if (singlePaidMessageCollection.SingleMessages.Count > 0) { - foreach (KeyValuePair paidMessageKVP in singlePaidMessageCollection.SingleMessages) + foreach (KeyValuePair paidMessageKvp in singlePaidMessageCollection.SingleMessages) { MessageEntities.Medium? mediaInfo = singlePaidMessageCollection.SingleMessageMedia.FirstOrDefault(m => - m.Id == paidMessageKVP.Key); + m.Id == paidMessageKvp.Key); MessageEntities.SingleMessage? messageInfo = singlePaidMessageCollection.SingleMessageObjects.FirstOrDefault(p => - p.Media?.Any(m => m.Id == paidMessageKVP.Key) == true); + p.Media?.Any(m => m.Id == paidMessageKvp.Key) == true); string filenameFormat = configService.CurrentConfig.GetCreatorFileNameFormatConfig(username) .PaidMessageFileNameFormat ?? ""; string singlePaidMsgPath = configService.CurrentConfig.FolderPerPaidMessage && @@ -1915,9 +1878,9 @@ public class DownloadService( : "/Messages/Paid"; bool isNew; - if (paidMessageKVP.Value.Contains("cdn3.onlyfans.com/dash/files")) + if (paidMessageKvp.Value.Contains("cdn3.onlyfans.com/dash/files")) { - string[] parsed = paidMessageKVP.Value.Split(','); + string[] parsed = paidMessageKvp.Value.Split(','); (string decryptionKey, DateTime lastModified)? drmInfo = await GetDecryptionInfo(parsed[0], parsed[1], parsed[2], parsed[3], parsed[4], parsed[5], "message", clientIdBlobMissing, devicePrivateKeyMissing); @@ -1926,15 +1889,15 @@ public class DownloadService( continue; } - isNew = await DownloadDRMVideo(parsed[1], parsed[2], parsed[3], parsed[0], - drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, paidMessageKVP.Key, + isNew = await DownloadDrmVideo(parsed[1], parsed[2], parsed[3], parsed[0], + drmInfo.Value.decryptionKey, path, drmInfo.Value.lastModified, paidMessageKvp.Key, "Messages", progressReporter, singlePaidMsgPath + "/Videos", filenameFormat, messageInfo, mediaInfo, messageInfo?.FromUser, users); } else { - isNew = await DownloadMedia(paidMessageKVP.Value, path, - paidMessageKVP.Key, "Messages", progressReporter, + isNew = await DownloadMedia(paidMessageKvp.Value, path, + paidMessageKvp.Key, "Messages", progressReporter, singlePaidMsgPath, filenameFormat, messageInfo, mediaInfo, messageInfo?.FromUser, users); } diff --git a/OF DL.Core/Services/FileNameService.cs b/OF DL.Core/Services/FileNameService.cs index cd8732e..0f533bd 100644 --- a/OF DL.Core/Services/FileNameService.cs +++ b/OF DL.Core/Services/FileNameService.cs @@ -27,7 +27,7 @@ public class FileNameService(IAuthService authService) : IFileNameService if (fileProperty != null && drmProperty != null && propertyName == "mediaCreatedAt") { - string? mpdurl = GetNestedPropertyValue(media, "Files.Drm.Manifest.Dash") as string; + string? mpdUrl = GetNestedPropertyValue(media, "Files.Drm.Manifest.Dash") as string; string? policy = GetNestedPropertyValue(media, "Files.Drm.Signature.Dash.CloudFrontPolicy") as string; string? signature = @@ -35,7 +35,7 @@ public class FileNameService(IAuthService authService) : IFileNameService string? kvp = GetNestedPropertyValue(media, "Files.Drm.Signature.Dash.CloudFrontKeyPairId") as string; - if (string.IsNullOrEmpty(mpdurl) || string.IsNullOrEmpty(policy) || + if (string.IsNullOrEmpty(mpdUrl) || string.IsNullOrEmpty(policy) || string.IsNullOrEmpty(signature) || string.IsNullOrEmpty(kvp) || authService.CurrentAuth == null) { @@ -43,7 +43,7 @@ public class FileNameService(IAuthService authService) : IFileNameService } DateTime lastModified = - await DownloadService.GetDRMVideoLastModified(string.Join(",", mpdurl, policy, signature, kvp), + await DownloadService.GetDrmVideoLastModified(string.Join(",", mpdUrl, policy, signature, kvp), authService.CurrentAuth); values.Add(propertyName, lastModified.ToString("yyyy-MM-dd")); continue; diff --git a/OF DL.Core/Services/IAPIService.cs b/OF DL.Core/Services/IApiService.cs similarity index 79% rename from OF DL.Core/Services/IAPIService.cs rename to OF DL.Core/Services/IApiService.cs index 9fa9349..0ff8a39 100644 --- a/OF DL.Core/Services/IAPIService.cs +++ b/OF DL.Core/Services/IApiService.cs @@ -9,27 +9,31 @@ using UserEntities = OF_DL.Models.Entities.Users; namespace OF_DL.Services; -public interface IAPIService +public interface IApiService { - Task GetDecryptionKeyCDM(Dictionary drmHeaders, string licenceURL, string pssh); - Task GetDRMMPDLastModified(string mpdUrl, string policy, string signature, string kvp); - Task GetDRMMPDPSSH(string mpdUrl, string policy, string signature, string kvp); + Task GetDecryptionKeyCdm(Dictionary drmHeaders, string licenceUrl, string pssh); + + Task GetDrmMpdLastModified(string mpdUrl, string policy, string signature, string kvp); + + Task GetDrmMpdPssh(string mpdUrl, string policy, string signature, string kvp); + Task?> GetLists(string endpoint); + Task?> GetListUsers(string endpoint); - Task?> GetMedia(MediaType mediatype, string endpoint, string? username, string folder, - List paid_post_ids); + Task?> GetMedia(MediaType mediaType, string endpoint, string? username, string folder, + List paidPostIds); Task GetPaidPosts(string endpoint, string folder, string username, - List paid_post_ids, + List paidPostIds, IStatusReporter statusReporter); - Task GetPosts(string endpoint, string folder, List paid_post_ids, + Task GetPosts(string endpoint, string folder, List paidPostIds, IStatusReporter statusReporter); Task GetPost(string endpoint, string folder); - Task GetStreams(string endpoint, string folder, List paid_post_ids, + Task GetStreams(string endpoint, string folder, List paidPostIds, IStatusReporter statusReporter); Task GetArchived(string endpoint, string folder, @@ -41,15 +45,21 @@ public interface IAPIService IStatusReporter statusReporter); Task GetPaidMessage(string endpoint, string folder); + Task> GetPurchasedTabUsers(string endpoint, Dictionary users); Task> GetPurchasedTab(string endpoint, string folder, Dictionary users); Task GetUserInfo(string endpoint); + Task GetUserInfoById(string endpoint); + Dictionary GetDynamicHeaders(string path, string queryParam); + Task?> GetActiveSubscriptions(string endpoint, bool includeRestrictedSubscriptions); + Task?> GetExpiredSubscriptions(string endpoint, bool includeRestrictedSubscriptions); - Task GetDecryptionKeyOFDL(Dictionary drmHeaders, string licenceURL, string pssh); + + Task GetDecryptionKeyOfdl(Dictionary drmHeaders, string licenceUrl, string pssh); } diff --git a/OF DL.Core/Services/IDBService.cs b/OF DL.Core/Services/IDBService.cs deleted file mode 100644 index 9a14484..0000000 --- a/OF DL.Core/Services/IDBService.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace OF_DL.Services; - -public interface IDBService -{ - Task AddMessage(string folder, long post_id, string message_text, string price, bool is_paid, bool is_archived, - DateTime created_at, long user_id); - - Task AddPost(string folder, long post_id, string message_text, string price, bool is_paid, bool is_archived, - DateTime created_at); - - Task AddStory(string folder, long post_id, string message_text, string price, bool is_paid, bool is_archived, - DateTime created_at); - - Task CreateDB(string folder); - Task CreateUsersDB(Dictionary users); - Task CheckUsername(KeyValuePair user, string path); - - Task AddMedia(string folder, long media_id, long post_id, string link, string? directory, string? filename, - long? size, string api_type, string media_type, bool preview, bool downloaded, DateTime? created_at); - - Task UpdateMedia(string folder, long media_id, string api_type, string directory, string filename, long size, - bool downloaded, DateTime created_at); - - Task GetStoredFileSize(string folder, long media_id, string api_type); - Task CheckDownloaded(string folder, long media_id, string api_type); - Task GetMostRecentPostDate(string folder); -} diff --git a/OF DL.Core/Services/IDbService.cs b/OF DL.Core/Services/IDbService.cs new file mode 100644 index 0000000..c7b05f4 --- /dev/null +++ b/OF DL.Core/Services/IDbService.cs @@ -0,0 +1,31 @@ +namespace OF_DL.Services; + +public interface IDbService +{ + Task AddMessage(string folder, long postId, string messageText, string price, bool isPaid, bool isArchived, + DateTime createdAt, long userId); + + Task AddPost(string folder, long postId, string messageText, string price, bool isPaid, bool isArchived, + DateTime createdAt); + + Task AddStory(string folder, long postId, string messageText, string price, bool isPaid, bool isArchived, + DateTime createdAt); + + Task CreateDb(string folder); + + Task CreateUsersDb(Dictionary users); + + Task CheckUsername(KeyValuePair user, string path); + + Task AddMedia(string folder, long mediaId, long postId, string link, string? directory, string? filename, + long? size, string apiType, string mediaType, bool preview, bool downloaded, DateTime? createdAt); + + Task UpdateMedia(string folder, long mediaId, string apiType, string directory, string filename, long size, + bool downloaded, DateTime createdAt); + + Task GetStoredFileSize(string folder, long mediaId, string apiType); + + Task CheckDownloaded(string folder, long mediaId, string apiType); + + Task GetMostRecentPostDate(string folder); +} diff --git a/OF DL.Core/Services/IDownloadService.cs b/OF DL.Core/Services/IDownloadService.cs index b474f60..b2a6e26 100644 --- a/OF DL.Core/Services/IDownloadService.cs +++ b/OF DL.Core/Services/IDownloadService.cs @@ -11,22 +11,22 @@ public interface IDownloadService { Task CalculateTotalFileSize(List urls); - Task ProcessMediaDownload(string folder, long media_id, string api_type, string url, string path, + Task ProcessMediaDownload(string folder, long mediaId, string apiType, string url, string path, string serverFileName, string resolvedFileName, string extension, IProgressReporter progressReporter); - Task DownloadMedia(string url, string folder, long media_id, string api_type, + Task DownloadMedia(string url, string folder, long mediaId, string apiType, IProgressReporter progressReporter, string path, string? filenameFormat, object? postInfo, object? postMedia, object? author, Dictionary users); - Task DownloadDRMVideo(string policy, string signature, string kvp, string url, - string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, + Task DownloadDrmVideo(string policy, string signature, string kvp, string url, + string decryptionKey, string folder, DateTime lastModified, long mediaId, string apiType, IProgressReporter progressReporter, string path, string? filenameFormat, object? postInfo, object? postMedia, object? author, Dictionary users); Task<(string decryptionKey, DateTime lastModified)?> GetDecryptionInfo( - string mpdURL, string policy, string signature, string kvp, + string mpdUrl, string policy, string signature, string kvp, string mediaId, string contentId, string drmType, bool clientIdBlobMissing, bool devicePrivateKeyMissing); diff --git a/OF DL.Core/Services/ILoggingService.cs b/OF DL.Core/Services/ILoggingService.cs index 7c6a8a3..787ca92 100644 --- a/OF DL.Core/Services/ILoggingService.cs +++ b/OF DL.Core/Services/ILoggingService.cs @@ -6,6 +6,8 @@ namespace OF_DL.Services; public interface ILoggingService { LoggingLevelSwitch LevelSwitch { get; } + void UpdateLoggingLevel(LoggingLevel newLevel); + LoggingLevel GetCurrentLoggingLevel(); } diff --git a/OF DL.Core/Services/StartupService.cs b/OF DL.Core/Services/StartupService.cs index 08d80d2..ff96321 100644 --- a/OF DL.Core/Services/StartupService.cs +++ b/OF DL.Core/Services/StartupService.cs @@ -221,7 +221,7 @@ public class StartupService(IConfigService configService, IAuthService authServi return File.Exists(path); } - public static string? GetFullPath(string filename) + private static string? GetFullPath(string filename) { if (File.Exists(filename)) { @@ -229,15 +229,7 @@ public class StartupService(IConfigService configService, IAuthService authServi } string pathEnv = Environment.GetEnvironmentVariable("PATH") ?? ""; - foreach (string path in pathEnv.Split(Path.PathSeparator)) - { - string fullPath = Path.Combine(path, filename); - if (File.Exists(fullPath)) - { - return fullPath; - } - } - - return null; + return pathEnv.Split(Path.PathSeparator).Select(path => Path.Combine(path, filename)) + .FirstOrDefault(File.Exists); } } diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 23647e2..f43d269 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -110,8 +110,8 @@ public class Program(IServiceProvider serviceProvider) services.AddSingleton(loggingService); services.AddSingleton(configService); services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); @@ -403,8 +403,8 @@ public class Program(IServiceProvider serviceProvider) AnsiConsole.Markup($"[red]Folder for {Markup.Escape(username)} already created\n[/]"); } - IDBService dbService = serviceProvider.GetRequiredService(); - await dbService.CreateDB(path); + IDbService dbService = serviceProvider.GetRequiredService(); + await dbService.CreateDb(path); await orchestrationService.DownloadSinglePostAsync(username, postId, path, users, startupResult.ClientIdBlobMissing, startupResult.DevicePrivateKeyMissing, eventHandler); @@ -475,8 +475,8 @@ public class Program(IServiceProvider serviceProvider) Log.Debug($"Folder for {username} already created"); } - IDBService dbService = serviceProvider.GetRequiredService(); - await dbService.CreateDB(path); + IDbService dbService = serviceProvider.GetRequiredService(); + await dbService.CreateDb(path); await orchestrationService.DownloadSinglePaidMessageAsync(username, messageId, path, users, startupResult.ClientIdBlobMissing, startupResult.DevicePrivateKeyMissing, eventHandler); @@ -488,7 +488,7 @@ public class Program(IServiceProvider serviceProvider) { IConfigService configService = serviceProvider.GetRequiredService(); IAuthService authService = serviceProvider.GetRequiredService(); - IAPIService apiService = serviceProvider.GetRequiredService(); + IApiService apiService = serviceProvider.GetRequiredService(); ILoggingService loggingService = serviceProvider.GetRequiredService(); bool hasSelectedUsers = false;