From 03a7885443837c578f88484b631891305a08a736 Mon Sep 17 00:00:00 2001 From: sim0n00ps Date: Sun, 3 Nov 2024 21:33:46 +0000 Subject: [PATCH] Rename DRM files if RenameExistingFilesWhenCustomFormatIsSelected is true --- OF DL/Helpers/APIHelper.cs | 5 - OF DL/Helpers/DownloadHelper.cs | 194 ++++++++++++++++++++++++++++++++ 2 files changed, 194 insertions(+), 5 deletions(-) diff --git a/OF DL/Helpers/APIHelper.cs b/OF DL/Helpers/APIHelper.cs index 69c5891..46eb8d7 100644 --- a/OF DL/Helpers/APIHelper.cs +++ b/OF DL/Helpers/APIHelper.cs @@ -10,18 +10,13 @@ using OF_DL.Entities.Stories; using OF_DL.Entities.Streams; using OF_DL.Enumurations; -using Org.BouncyCastle.Asn1.Crmf; using Serilog; using System.Globalization; -using System.IO; -using System.Net; -using System.Reflection.PortableExecutable; using System.Security.Cryptography; using System.Text; using System.Text.Json; using System.Xml.Linq; using WidevineClient.Widevine; -using static OF_DL.Entities.Highlights.HighlightMedia; using static WidevineClient.HttpUtil; namespace OF_DL.Helpers; diff --git a/OF DL/Helpers/DownloadHelper.cs b/OF DL/Helpers/DownloadHelper.cs index d63b815..1c2589e 100644 --- a/OF DL/Helpers/DownloadHelper.cs +++ b/OF DL/Helpers/DownloadHelper.cs @@ -1,5 +1,6 @@ using FFmpeg.NET; using FFmpeg.NET.Events; +using FFmpeg.NET.Services; using OF_DL.Entities; using OF_DL.Entities.Archived; using OF_DL.Entities.Messages; @@ -16,6 +17,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Drawing; using System.IO; using System.Linq; using System.Net; @@ -999,6 +1001,30 @@ public async Task DownloadMessageDRMVideo(string policy, string signature, } else { + if (!string.IsNullOrEmpty(customFileName)) + { + if (downloadConfig.RenameExistingFilesWhenCustomFormatIsSelected && (filename + "_source" != customFileName)) + { + string fullPathWithTheServerFileName = $"{folder}{path}/{filename}_source.mp4"; + string fullPathWithTheNewFileName = $"{folder}{path}/{customFileName}.mp4"; + if (!File.Exists(fullPathWithTheServerFileName)) + { + return false; + } + try + { + File.Move(fullPathWithTheServerFileName, fullPathWithTheNewFileName); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + return false; + } + long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); + await m_DBHelper.UpdateMedia(folder, media_id, api_type, folder + path, customFileName + ".mp4", size, true, lastModified); + } + } + if (downloadConfig.ShowScrapeSize) { long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); @@ -1082,6 +1108,30 @@ public async Task DownloadPurchasedMessageDRMVideo(string policy, string s } else { + if (!string.IsNullOrEmpty(customFileName)) + { + if (downloadConfig.RenameExistingFilesWhenCustomFormatIsSelected && (filename + "_source" != customFileName)) + { + string fullPathWithTheServerFileName = $"{folder}{path}/{filename}_source.mp4"; + string fullPathWithTheNewFileName = $"{folder}{path}/{customFileName}.mp4"; + if (!File.Exists(fullPathWithTheServerFileName)) + { + return false; + } + try + { + File.Move(fullPathWithTheServerFileName, fullPathWithTheNewFileName); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + return false; + } + long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); + await m_DBHelper.UpdateMedia(folder, media_id, api_type, folder + path, customFileName + ".mp4", size, true, lastModified); + } + } + if (downloadConfig.ShowScrapeSize) { long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); @@ -1164,6 +1214,30 @@ public async Task DownloadSinglePurchasedMessageDRMVideo(string policy, st } else { + if (!string.IsNullOrEmpty(customFileName)) + { + if (downloadConfig.RenameExistingFilesWhenCustomFormatIsSelected && (filename + "_source" != customFileName)) + { + string fullPathWithTheServerFileName = $"{folder}{path}/{filename}_source.mp4"; + string fullPathWithTheNewFileName = $"{folder}{path}/{customFileName}.mp4"; + if (!File.Exists(fullPathWithTheServerFileName)) + { + return false; + } + try + { + File.Move(fullPathWithTheServerFileName, fullPathWithTheNewFileName); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + return false; + } + long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); + await m_DBHelper.UpdateMedia(folder, media_id, api_type, folder + path, customFileName + ".mp4", size, true, lastModified); + } + } + if (downloadConfig.ShowScrapeSize) { long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); @@ -1247,6 +1321,30 @@ public async Task DownloadPostDRMVideo(string policy, string signature, st } else { + if (!string.IsNullOrEmpty(customFileName)) + { + if (downloadConfig.RenameExistingFilesWhenCustomFormatIsSelected && (filename + "_source" != customFileName)) + { + string fullPathWithTheServerFileName = $"{folder}{path}/{filename}_source.mp4"; + string fullPathWithTheNewFileName = $"{folder}{path}/{customFileName}.mp4"; + if (!File.Exists(fullPathWithTheServerFileName)) + { + return false; + } + try + { + File.Move(fullPathWithTheServerFileName, fullPathWithTheNewFileName); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + return false; + } + long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); + await m_DBHelper.UpdateMedia(folder, media_id, api_type, folder + path, customFileName + ".mp4", size, true, lastModified); + } + } + if (downloadConfig.ShowScrapeSize) { long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); @@ -1328,6 +1426,30 @@ public async Task DownloadPostDRMVideo(string policy, string signature, st } else { + if (!string.IsNullOrEmpty(customFileName)) + { + if (downloadConfig.RenameExistingFilesWhenCustomFormatIsSelected && (filename + "_source" != customFileName)) + { + string fullPathWithTheServerFileName = $"{folder}{path}/{filename}_source.mp4"; + string fullPathWithTheNewFileName = $"{folder}{path}/{customFileName}.mp4"; + if (!File.Exists(fullPathWithTheServerFileName)) + { + return false; + } + try + { + File.Move(fullPathWithTheServerFileName, fullPathWithTheNewFileName); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + return false; + } + long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); + await m_DBHelper.UpdateMedia(folder, media_id, api_type, folder + path, customFileName + ".mp4", size, true, lastModified); + } + } + if (downloadConfig.ShowScrapeSize) { long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); @@ -1409,6 +1531,30 @@ public async Task DownloadStreamsDRMVideo(string policy, string signature, } else { + if (!string.IsNullOrEmpty(customFileName)) + { + if (downloadConfig.RenameExistingFilesWhenCustomFormatIsSelected && (filename + "_source" != customFileName)) + { + string fullPathWithTheServerFileName = $"{folder}{path}/{filename}_source.mp4"; + string fullPathWithTheNewFileName = $"{folder}{path}/{customFileName}.mp4"; + if (!File.Exists(fullPathWithTheServerFileName)) + { + return false; + } + try + { + File.Move(fullPathWithTheServerFileName, fullPathWithTheNewFileName); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + return false; + } + long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); + await m_DBHelper.UpdateMedia(folder, media_id, api_type, folder + path, customFileName + ".mp4", size, true, lastModified); + } + } + if (downloadConfig.ShowScrapeSize) { long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); @@ -1492,6 +1638,30 @@ public async Task DownloadPurchasedPostDRMVideo(string policy, string sign } else { + if (!string.IsNullOrEmpty(customFileName)) + { + if (downloadConfig.RenameExistingFilesWhenCustomFormatIsSelected && (filename + "_source" != customFileName)) + { + string fullPathWithTheServerFileName = $"{folder}{path}/{filename}_source.mp4"; + string fullPathWithTheNewFileName = $"{folder}{path}/{customFileName}.mp4"; + if (!File.Exists(fullPathWithTheServerFileName)) + { + return false; + } + try + { + File.Move(fullPathWithTheServerFileName, fullPathWithTheNewFileName); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + return false; + } + long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); + await m_DBHelper.UpdateMedia(folder, media_id, api_type, folder + path, customFileName + ".mp4", size, true, lastModified); + } + } + if (downloadConfig.ShowScrapeSize) { long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); @@ -1567,6 +1737,30 @@ public async Task DownloadArchivedPostDRMVideo(string policy, string signa } else { + if (!string.IsNullOrEmpty(customFileName)) + { + if (downloadConfig.RenameExistingFilesWhenCustomFormatIsSelected && (filename + "_source" != customFileName)) + { + string fullPathWithTheServerFileName = $"{folder}{path}/{filename}_source.mp4"; + string fullPathWithTheNewFileName = $"{folder}{path}/{customFileName}.mp4"; + if (!File.Exists(fullPathWithTheServerFileName)) + { + return false; + } + try + { + File.Move(fullPathWithTheServerFileName, fullPathWithTheNewFileName); + } + catch (Exception ex) + { + Console.WriteLine($"An error occurred: {ex.Message}"); + return false; + } + long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type); + await m_DBHelper.UpdateMedia(folder, media_id, api_type, folder + path, customFileName + ".mp4", size, true, lastModified); + } + } + if (downloadConfig.ShowScrapeSize) { long size = await m_DBHelper.GetStoredFileSize(folder, media_id, api_type);