Skip to content

Commit

Permalink
Rename DRM files if RenameExistingFilesWhenCustomFormatIsSelected is …
Browse files Browse the repository at this point in the history
…true
  • Loading branch information
sim0n00ps committed Nov 3, 2024
1 parent 997ee4c commit 03a7885
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 5 deletions.
5 changes: 0 additions & 5 deletions OF DL/Helpers/APIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
194 changes: 194 additions & 0 deletions OF DL/Helpers/DownloadHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -999,6 +1001,30 @@ public async Task<bool> 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);
Expand Down Expand Up @@ -1082,6 +1108,30 @@ public async Task<bool> 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);
Expand Down Expand Up @@ -1164,6 +1214,30 @@ public async Task<bool> 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);
Expand Down Expand Up @@ -1247,6 +1321,30 @@ public async Task<bool> 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);
Expand Down Expand Up @@ -1328,6 +1426,30 @@ public async Task<bool> 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);
Expand Down Expand Up @@ -1409,6 +1531,30 @@ public async Task<bool> 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);
Expand Down Expand Up @@ -1492,6 +1638,30 @@ public async Task<bool> 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);
Expand Down Expand Up @@ -1567,6 +1737,30 @@ public async Task<bool> 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);
Expand Down

0 comments on commit 03a7885

Please sign in to comment.