forked from sim0n00ps/OF-DL
Fix custom filename format configs
This commit is contained in:
parent
a57af4042f
commit
a8b2acaad6
@ -105,28 +105,35 @@ public class Config : IFileNameFormatConfig
|
||||
|
||||
public IFileNameFormatConfig GetCreatorFileNameFormatConfig(string username)
|
||||
{
|
||||
FileNameFormatConfig combinedFilenameFormatConfig = new();
|
||||
FileNameFormatConfig combinedFilenameFormatConfig = new()
|
||||
{
|
||||
PaidPostFileNameFormat = PaidPostFileNameFormat,
|
||||
PostFileNameFormat = PostFileNameFormat,
|
||||
PaidMessageFileNameFormat = PaidMessageFileNameFormat,
|
||||
MessageFileNameFormat = MessageFileNameFormat
|
||||
};
|
||||
|
||||
if (CreatorConfigs.TryGetValue(username, out CreatorConfig? creatorConfig))
|
||||
{
|
||||
combinedFilenameFormatConfig.PaidMessageFileNameFormat =
|
||||
!string.IsNullOrEmpty(creatorConfig.PaidMessageFileNameFormat)
|
||||
? creatorConfig.PaidMessageFileNameFormat
|
||||
: PaidMessageFileNameFormat;
|
||||
if (creatorConfig?.PaidPostFileNameFormat != null)
|
||||
{
|
||||
combinedFilenameFormatConfig.PaidPostFileNameFormat = creatorConfig.PaidPostFileNameFormat;
|
||||
}
|
||||
|
||||
combinedFilenameFormatConfig.PostFileNameFormat = !string.IsNullOrEmpty(creatorConfig.PostFileNameFormat)
|
||||
? creatorConfig.PostFileNameFormat
|
||||
: PostFileNameFormat;
|
||||
if (creatorConfig?.PostFileNameFormat != null)
|
||||
{
|
||||
combinedFilenameFormatConfig.PostFileNameFormat = creatorConfig.PostFileNameFormat;
|
||||
}
|
||||
|
||||
combinedFilenameFormatConfig.MessageFileNameFormat =
|
||||
!string.IsNullOrEmpty(creatorConfig.MessageFileNameFormat)
|
||||
? creatorConfig.MessageFileNameFormat
|
||||
: MessageFileNameFormat;
|
||||
if (creatorConfig?.PaidMessageFileNameFormat != null)
|
||||
{
|
||||
combinedFilenameFormatConfig.PaidMessageFileNameFormat = creatorConfig.PaidMessageFileNameFormat;
|
||||
}
|
||||
|
||||
combinedFilenameFormatConfig.PaidPostFileNameFormat =
|
||||
!string.IsNullOrEmpty(creatorConfig.PaidPostFileNameFormat)
|
||||
? creatorConfig.PaidPostFileNameFormat
|
||||
: PaidPostFileNameFormat;
|
||||
if (creatorConfig?.MessageFileNameFormat != null)
|
||||
{
|
||||
combinedFilenameFormatConfig.MessageFileNameFormat = creatorConfig.MessageFileNameFormat;
|
||||
}
|
||||
}
|
||||
|
||||
Log.Debug("PaidMessageFilenameFormat: {CombinedConfigPaidMessageFileNameFormat}",
|
||||
|
||||
@ -13,5 +13,5 @@ public class FilesDto
|
||||
|
||||
[JsonProperty("squarePreview")] public SquarePreviewDto SquarePreview { get; set; } = new();
|
||||
|
||||
[JsonProperty("drm")] public DrmDto Drm { get; set; } = new();
|
||||
[JsonProperty("drm")] public DrmDto? Drm { get; set; }
|
||||
}
|
||||
|
||||
@ -5,12 +5,12 @@ namespace OF_DL.Services;
|
||||
|
||||
public class FileNameService(IAuthService authService) : IFileNameService
|
||||
{
|
||||
public async Task<Dictionary<string, string>> GetFilename(object obj1, object obj2, object obj3,
|
||||
List<string> selectedProperties, string username, Dictionary<string, long> users = null)
|
||||
public async Task<Dictionary<string, string>> GetFilename(object info, object media, object author,
|
||||
List<string> selectedProperties, string username, Dictionary<string, long>? users = null)
|
||||
{
|
||||
Dictionary<string, string> values = new();
|
||||
Type type1 = obj1.GetType();
|
||||
Type type2 = obj2.GetType();
|
||||
Type type1 = info.GetType();
|
||||
Type type2 = media.GetType();
|
||||
PropertyInfo[] properties1 = type1.GetProperties();
|
||||
PropertyInfo[] properties2 = type2.GetProperties();
|
||||
|
||||
@ -18,19 +18,30 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
{
|
||||
if (propertyName.Contains("media"))
|
||||
{
|
||||
object drmProperty = null;
|
||||
object fileProperty = GetNestedPropertyValue(obj2, "files");
|
||||
object? drmProperty = null;
|
||||
object? fileProperty = GetNestedPropertyValue(media, "Files");
|
||||
if (fileProperty != null)
|
||||
{
|
||||
drmProperty = GetNestedPropertyValue(obj2, "files.drm");
|
||||
drmProperty = GetNestedPropertyValue(media, "Files.Drm");
|
||||
}
|
||||
|
||||
if (fileProperty != null && drmProperty != null && propertyName == "mediaCreatedAt")
|
||||
{
|
||||
object mpdurl = GetNestedPropertyValue(obj2, "files.drm.manifest.dash");
|
||||
object policy = GetNestedPropertyValue(obj2, "files.drm.signature.dash.CloudFrontPolicy");
|
||||
object signature = GetNestedPropertyValue(obj2, "files.drm.signature.dash.CloudFrontSignature");
|
||||
object kvp = GetNestedPropertyValue(obj2, "files.drm.signature.dash.CloudFrontKeyPairId");
|
||||
string? mpdurl = GetNestedPropertyValue(media, "Files.Drm.Manifest.Dash") as string;
|
||||
string? policy =
|
||||
GetNestedPropertyValue(media, "Files.Drm.Signature.Dash.CloudFrontPolicy") as string;
|
||||
string? signature =
|
||||
GetNestedPropertyValue(media, "Files.Drm.Signature.Dash.CloudFrontSignature") as string;
|
||||
string? kvp =
|
||||
GetNestedPropertyValue(media, "Files.Drm.Signature.Dash.CloudFrontKeyPairId") as string;
|
||||
|
||||
if (string.IsNullOrEmpty(mpdurl) || string.IsNullOrEmpty(policy) ||
|
||||
string.IsNullOrEmpty(signature) || string.IsNullOrEmpty(kvp) ||
|
||||
authService.CurrentAuth == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DateTime lastModified =
|
||||
await DownloadService.GetDRMVideoLastModified(string.Join(",", mpdurl, policy, signature, kvp),
|
||||
authService.CurrentAuth);
|
||||
@ -40,18 +51,18 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
|
||||
if ((fileProperty == null || drmProperty == null) && propertyName == "mediaCreatedAt")
|
||||
{
|
||||
object source = GetNestedPropertyValue(obj2, "files.full.url");
|
||||
object? source = GetNestedPropertyValue(media, "Files.Full.Url");
|
||||
if (source != null)
|
||||
{
|
||||
DateTime lastModified = await DownloadService.GetMediaLastModified(source.ToString());
|
||||
DateTime lastModified = await DownloadService.GetMediaLastModified(source.ToString() ?? "");
|
||||
values.Add(propertyName, lastModified.ToString("yyyy-MM-dd"));
|
||||
continue;
|
||||
}
|
||||
|
||||
object preview = GetNestedPropertyValue(obj2, "preview");
|
||||
object? preview = GetNestedPropertyValue(media, "Preview");
|
||||
if (preview != null)
|
||||
{
|
||||
DateTime lastModified = await DownloadService.GetMediaLastModified(preview.ToString());
|
||||
DateTime lastModified = await DownloadService.GetMediaLastModified(preview.ToString() ?? "");
|
||||
values.Add(propertyName, lastModified.ToString("yyyy-MM-dd"));
|
||||
continue;
|
||||
}
|
||||
@ -61,7 +72,7 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
p => p.Name.Equals(propertyName.Replace("media", ""), StringComparison.OrdinalIgnoreCase));
|
||||
if (property != null)
|
||||
{
|
||||
object? propertyValue = property.GetValue(obj2);
|
||||
object? propertyValue = property.GetValue(media);
|
||||
if (propertyValue != null)
|
||||
{
|
||||
if (propertyValue is DateTime dateTimeValue)
|
||||
@ -70,28 +81,26 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
}
|
||||
else
|
||||
{
|
||||
values.Add(propertyName, propertyValue.ToString());
|
||||
values.Add(propertyName, propertyValue.ToString() ?? "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (propertyName.Contains("filename"))
|
||||
{
|
||||
string sourcePropertyPath = "files.full.url";
|
||||
object sourcePropertyValue = GetNestedPropertyValue(obj2, sourcePropertyPath);
|
||||
object? sourcePropertyValue = GetNestedPropertyValue(media, "Files.Full.Url");
|
||||
if (sourcePropertyValue != null)
|
||||
{
|
||||
Uri uri = new(sourcePropertyValue.ToString());
|
||||
Uri uri = new(sourcePropertyValue.ToString() ?? "");
|
||||
string filename = Path.GetFileName(uri.LocalPath);
|
||||
values.Add(propertyName, filename.Split(".")[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
string propertyPath = "files.drm.manifest.dash";
|
||||
object nestedPropertyValue = GetNestedPropertyValue(obj2, propertyPath);
|
||||
object? nestedPropertyValue = GetNestedPropertyValue(media, "Files.Drm.Manifest.Dash");
|
||||
if (nestedPropertyValue != null)
|
||||
{
|
||||
Uri uri = new(nestedPropertyValue.ToString());
|
||||
Uri uri = new(nestedPropertyValue.ToString() ?? "");
|
||||
string filename = Path.GetFileName(uri.LocalPath);
|
||||
values.Add(propertyName, filename.Split(".")[0] + "_source");
|
||||
}
|
||||
@ -105,8 +114,7 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
}
|
||||
else
|
||||
{
|
||||
string propertyPath = "id";
|
||||
object nestedPropertyValue = GetNestedPropertyValue(obj3, propertyPath);
|
||||
object? nestedPropertyValue = GetNestedPropertyValue(author, "Id");
|
||||
if (nestedPropertyValue != null)
|
||||
{
|
||||
values.Add(propertyName,
|
||||
@ -116,11 +124,11 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
}
|
||||
else if (propertyName.Contains("text", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
PropertyInfo property = Array.Find(properties1,
|
||||
PropertyInfo? property = Array.Find(properties1,
|
||||
p => p.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase));
|
||||
if (property != null)
|
||||
{
|
||||
object propertyValue = property.GetValue(obj1);
|
||||
object? propertyValue = property.GetValue(info);
|
||||
if (propertyValue != null)
|
||||
{
|
||||
HtmlDocument pageDoc = new();
|
||||
@ -137,11 +145,11 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
}
|
||||
else
|
||||
{
|
||||
PropertyInfo property = Array.Find(properties1,
|
||||
PropertyInfo? property = Array.Find(properties1,
|
||||
p => p.Name.Equals(propertyName, StringComparison.OrdinalIgnoreCase));
|
||||
if (property != null)
|
||||
{
|
||||
object propertyValue = property.GetValue(obj1);
|
||||
object? propertyValue = property.GetValue(info);
|
||||
if (propertyValue != null)
|
||||
{
|
||||
if (propertyValue is DateTime dateTimeValue)
|
||||
@ -150,7 +158,7 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
}
|
||||
else
|
||||
{
|
||||
values.Add(propertyName, propertyValue.ToString());
|
||||
values.Add(propertyName, propertyValue.ToString() ?? "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -160,7 +168,7 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
return values;
|
||||
}
|
||||
|
||||
public async Task<string> BuildFilename(string fileFormat, Dictionary<string, string> values)
|
||||
public Task<string> BuildFilename(string fileFormat, Dictionary<string, string> values)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> kvp in values)
|
||||
{
|
||||
@ -168,15 +176,15 @@ public class FileNameService(IAuthService authService) : IFileNameService
|
||||
fileFormat = fileFormat.Replace(placeholder, kvp.Value);
|
||||
}
|
||||
|
||||
return RemoveInvalidFileNameChars($"{fileFormat}");
|
||||
return Task.FromResult(RemoveInvalidFileNameChars($"{fileFormat}"));
|
||||
}
|
||||
|
||||
private static object GetNestedPropertyValue(object source, string propertyPath)
|
||||
private static object? GetNestedPropertyValue(object source, string propertyPath)
|
||||
{
|
||||
object value = source;
|
||||
object? value = source;
|
||||
foreach (string propertyName in propertyPath.Split('.'))
|
||||
{
|
||||
PropertyInfo property = value.GetType().GetProperty(propertyName) ??
|
||||
PropertyInfo property = value?.GetType().GetProperty(propertyName) ??
|
||||
throw new ArgumentException($"Property '{propertyName}' not found.");
|
||||
value = property.GetValue(value);
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ public interface IFileNameService
|
||||
{
|
||||
Task<string> BuildFilename(string fileFormat, Dictionary<string, string> values);
|
||||
|
||||
Task<Dictionary<string, string>> GetFilename(object obj1, object obj2, object obj3, List<string> selectedProperties,
|
||||
string username, Dictionary<string, long> users = null);
|
||||
Task<Dictionary<string, string>> GetFilename(object info, object media, object author,
|
||||
List<string> selectedProperties,
|
||||
string username, Dictionary<string, long>? users = null);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user