Skip to content

Commit

Permalink
Download Purchased Tab changes and support for Non Interactive Mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sim0n00ps committed Apr 24, 2024
1 parent e2deab3 commit 7212249
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
1 change: 1 addition & 0 deletions OF DL/Entities/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class Config
public bool NonInteractiveMode { get; set; } = false;

public string NonInteractiveModeListName { get; set; } = string.Empty;
public bool NonInteractiveModePurchasedTab { get; set; } = false;
public string? FFmpegPath { get; set; } = string.Empty;
}

Expand Down
31 changes: 16 additions & 15 deletions OF DL/Helpers/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ private static async Task<string> GenerateCustomFileName(string filename,
object? postInfo,
object? postMedia,
object? author,
string username,
Dictionary<string, int> users,
IFileNameHelper fileNameHelper,
CustomFileNameOption option)
Expand All @@ -169,7 +170,7 @@ private static async Task<string> GenerateCustomFileName(string filename,
MatchCollection matches = Regex.Matches(filenameFormat, pattern);
properties.AddRange(matches.Select(match => match.Groups[1].Value));

Dictionary<string, string> values = await fileNameHelper.GetFilename(postInfo, postMedia, author, properties, users);
Dictionary<string, string> values = await fileNameHelper.GetFilename(postInfo, postMedia, author, properties, username, users);
return await fileNameHelper.BuildFilename(filenameFormat, values);
}

Expand Down Expand Up @@ -653,7 +654,7 @@ public async Task<bool> DownloadPostMedia(string url, string folder, long media_

Uri uri = new(url);
string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);

return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize);
}
Expand All @@ -671,7 +672,7 @@ public async Task<bool> DownloadPostMedia(string url, string folder, long media_

Uri uri = new(url);
string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, postInfo, postMedia, author, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);

return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize);
}
Expand All @@ -689,7 +690,7 @@ public async Task<bool> DownloadStreamMedia(string url, string folder, long medi

Uri uri = new(url);
string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, streamInfo, streamMedia, author, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, streamInfo, streamMedia, author, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);

return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize);
}
Expand All @@ -708,7 +709,7 @@ public async Task<bool> DownloadMessageMedia(string url, string folder, long med
}
Uri uri = new(url);
string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize);
}

Expand All @@ -718,7 +719,7 @@ public async Task<bool> DownloadArchivedMedia(string url, string folder, long me
string path = "/Archived/Posts/Free";
Uri uri = new(url);
string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, author, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, author, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize);
}

Expand All @@ -745,7 +746,7 @@ public async Task<bool> DownloadPurchasedMedia(string url, string folder, long m
}
Uri uri = new(url);
string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize);
}

Expand All @@ -772,7 +773,7 @@ public async Task<bool> DownloadPurchasedPostMedia(string url,
}
Uri uri = new(url);
string filename = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
string resolvedFilename = await GenerateCustomFileName(filename, filenameFormat, messageInfo, messageMedia, fromUser, folder.Split("/")[^1], users, _FileNameHelper, CustomFileNameOption.ReturnOriginal);
return await CreateDirectoriesAndDownloadMedia(path, url, folder, media_id, task, filename, resolvedFilename, config, showScrapeSize);
}

Expand Down Expand Up @@ -920,7 +921,7 @@ public async Task<bool> DownloadMessageDRMVideo(string user_agent, string policy
{
properties.Add(match.Groups[1].Value);
}
Dictionary<string, string> values = await _FileNameHelper.GetFilename(messageInfo, messageMedia, fromUser, properties, users);
Dictionary<string, string> values = await _FileNameHelper.GetFilename(messageInfo, messageMedia, fromUser, properties, folder.Split("/")[^1],users);
customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values);
}

Expand Down Expand Up @@ -1003,7 +1004,7 @@ public async Task<bool> DownloadPurchasedMessageDRMVideo(string user_agent, stri
{
properties.Add(match.Groups[1].Value);
}
Dictionary<string, string> values = await _FileNameHelper.GetFilename(messageInfo, messageMedia, fromUser, properties, users);
Dictionary<string, string> values = await _FileNameHelper.GetFilename(messageInfo, messageMedia, fromUser, properties, folder.Split("/")[^1], users);
customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values);
}

Expand Down Expand Up @@ -1086,7 +1087,7 @@ public async Task<bool> DownloadPostDRMVideo(string user_agent, string policy, s
{
properties.Add(match.Groups[1].Value);
}
Dictionary<string, string> values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, users);
Dictionary<string, string> values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, folder.Split("/")[^1], users);
customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values);
}

Expand Down Expand Up @@ -1167,7 +1168,7 @@ public async Task<bool> DownloadPostDRMVideo(string user_agent, string policy, s
{
properties.Add(match.Groups[1].Value);
}
Dictionary<string, string> values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, users);
Dictionary<string, string> values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, folder.Split("/")[^1], users);
customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values);
}

Expand Down Expand Up @@ -1248,7 +1249,7 @@ public async Task<bool> DownloadStreamsDRMVideo(string user_agent, string policy
{
properties.Add(match.Groups[1].Value);
}
Dictionary<string, string> values = await _FileNameHelper.GetFilename(streamInfo, streamMedia, author, properties, users);
Dictionary<string, string> values = await _FileNameHelper.GetFilename(streamInfo, streamMedia, author, properties, folder.Split("/")[^1], users);
customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values);
}

Expand Down Expand Up @@ -1331,7 +1332,7 @@ public async Task<bool> DownloadPurchasedPostDRMVideo(string user_agent, string
{
properties.Add(match.Groups[1].Value);
}
Dictionary<string, string> values = await _FileNameHelper.GetFilename(postInfo, postMedia, fromUser, properties, users);
Dictionary<string, string> values = await _FileNameHelper.GetFilename(postInfo, postMedia, fromUser, properties, folder.Split("/")[^1], users);
customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values);
}

Expand Down Expand Up @@ -1406,7 +1407,7 @@ public async Task<bool> DownloadArchivedPostDRMVideo(string user_agent, string p
{
properties.Add(match.Groups[1].Value);
}
Dictionary<string, string> values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, users);
Dictionary<string, string> values = await _FileNameHelper.GetFilename(postInfo, postMedia, author, properties, folder.Split("/")[^1], users);
customFileName = await _FileNameHelper.BuildFilename(filenameFormat, values);
}

Expand Down
17 changes: 12 additions & 5 deletions OF DL/Helpers/FileNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OF_DL.Helpers
{
public class FileNameHelper : IFileNameHelper
{
public async Task<Dictionary<string, string>> GetFilename(object obj1, object obj2, object obj3, List<string> selectedProperties, Dictionary<string, int> users = null)
public async Task<Dictionary<string, string>> GetFilename(object obj1, object obj2, object obj3, List<string> selectedProperties, string username, Dictionary<string, int> users = null)
{
Dictionary<string, string> values = new();
Type type1 = obj1.GetType();
Expand Down Expand Up @@ -113,11 +113,18 @@ public async Task<Dictionary<string, string>> GetFilename(object obj1, object ob
}
else if (propertyName.Contains("username"))
{
string propertyPath = "id";
object nestedPropertyValue = GetNestedPropertyValue(obj3, propertyPath);
if (nestedPropertyValue != null)
if(!string.IsNullOrEmpty(username))
{
values.Add(propertyName, users.FirstOrDefault(u => u.Value == Convert.ToInt32(nestedPropertyValue.ToString())).Key);
values.Add(propertyName, username);
}
else
{
string propertyPath = "id";
object nestedPropertyValue = GetNestedPropertyValue(obj3, propertyPath);
if (nestedPropertyValue != null)
{
values.Add(propertyName, users.FirstOrDefault(u => u.Value == Convert.ToInt32(nestedPropertyValue.ToString())).Key);
}
}
}
else if (propertyName.Contains("text", StringComparison.OrdinalIgnoreCase))
Expand Down
2 changes: 1 addition & 1 deletion OF DL/Helpers/Interfaces/IFileNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ namespace OF_DL.Helpers
public interface IFileNameHelper
{
Task<string> BuildFilename(string fileFormat, Dictionary<string, string> values);
Task<Dictionary<string, string>> GetFilename(object obj1, object obj2, object obj3, List<string> selectedProperties, Dictionary<string, int>? users = null);
Task<Dictionary<string, string>> GetFilename(object obj1, object obj2, object obj3, List<string> selectedProperties, string username, Dictionary<string, int> users = null);
}
}
14 changes: 10 additions & 4 deletions OF DL/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ private static async Task DownloadAllData()
Dictionary<string, int> lists = await m_ApiHelper.GetLists("/lists", Auth);
Dictionary<string, int> selectedUsers = new();
KeyValuePair<bool, Dictionary<string, int>> hasSelectedUsersKVP;
if (Config.NonInteractiveMode && string.IsNullOrEmpty(Config.NonInteractiveModeListName))
if(Config.NonInteractiveMode && Config.NonInteractiveModePurchasedTab)
{
hasSelectedUsersKVP = new KeyValuePair<bool, Dictionary<string, int>>(true, new Dictionary<string, int> { { "PurchasedTab", 0 } });
}
else if (Config.NonInteractiveMode && string.IsNullOrEmpty(Config.NonInteractiveModeListName))
{
hasSelectedUsersKVP = new KeyValuePair<bool, Dictionary<string, int>>(true, users);
}
Expand Down Expand Up @@ -1837,12 +1841,13 @@ public static async Task<KeyValuePair<bool, Dictionary<string, int>>> HandleUser
( "[red]DownloadPostsBeforeOrAfterSpecificDate[/]", Config.DownloadOnlySpecificDates ),
( "[red]ShowScrapeSize[/]", Config.ShowScrapeSize),
( "[red]DownloadPostsIncrementally[/]", Config.DownloadPostsIncrementally),
( "[red]NonInteractiveMode[/]", Config.NonInteractiveMode)
( "[red]NonInteractiveMode[/]", Config.NonInteractiveMode),
( "[red]NonInteractiveModePurchasedTab[/]", Config.NonInteractiveModePurchasedTab)
});

MultiSelectionPrompt<string> multiSelectionPrompt = new MultiSelectionPrompt<string>()
.Title("[red]Edit config.json[/]")
.PageSize(24);
.PageSize(25);

foreach (var choice in choices)
{
Expand Down Expand Up @@ -1893,7 +1898,8 @@ public static async Task<KeyValuePair<bool, Dictionary<string, int>>> HandleUser
DownloadOnlySpecificDates = configOptions.Contains("[red]DownloadPostsBeforeOrAfterSpecificDate[/]"),
ShowScrapeSize = configOptions.Contains("[red]ShowScrapeSize[/]"),
DownloadPostsIncrementally = configOptions.Contains("[red]DownloadPostsIncrementally[/]"),
NonInteractiveMode = configOptions.Contains("[red]NonInteractiveMode[/]")
NonInteractiveMode = configOptions.Contains("[red]NonInteractiveMode[/]"),
NonInteractiveModePurchasedTab = configOptions.Contains("[red]NonInteractiveModePurchasedTab[/]")
};


Expand Down

0 comments on commit 7212249

Please sign in to comment.