forked from sim0n00ps/OF-DL
Extended command line args for NonInteractive
This commit is contained in:
parent
a893653be1
commit
233de7c9e5
@ -103,6 +103,9 @@ namespace OF_DL.Entities
|
|||||||
|
|
||||||
[JsonConverter(typeof(StringEnumConverter))]
|
[JsonConverter(typeof(StringEnumConverter))]
|
||||||
public VideoResolution DownloadVideoResolution { get; set; } = VideoResolution.source;
|
public VideoResolution DownloadVideoResolution { get; set; } = VideoResolution.source;
|
||||||
|
|
||||||
|
public string[] NonInteractiveSpecificUsers { get; set; } = [];
|
||||||
|
public string[] NonInteractiveSpecificLists { get; set; } = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CreatorConfig : IFileNameFormatConfig
|
public class CreatorConfig : IFileNameFormatConfig
|
||||||
|
@ -476,15 +476,44 @@ public class Program
|
|||||||
|
|
||||||
if (args is not null && args.Length > 0)
|
if (args is not null && args.Length > 0)
|
||||||
{
|
{
|
||||||
const string NON_INTERACTIVE_ARG = "--non-interactive";
|
const string NON_INTERACTIVE_ARG = "--non-interactive";
|
||||||
|
const string SPECIFIC_LISTS_ARG = "--specific-lists";
|
||||||
|
const string SPECIFIC_USERS_ARG = "--specific-users";
|
||||||
|
|
||||||
if (args.Any(a => NON_INTERACTIVE_ARG.Equals(NON_INTERACTIVE_ARG, StringComparison.OrdinalIgnoreCase)))
|
if (args.Any(a => NON_INTERACTIVE_ARG.Equals(NON_INTERACTIVE_ARG, StringComparison.OrdinalIgnoreCase)))
|
||||||
{
|
{
|
||||||
cliNonInteractive = true;
|
AnsiConsole.Markup($"[grey]Non-Interactive Mode enabled through command-line argument![/]\n");
|
||||||
Log.Debug("NonInteractiveMode set via command line");
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.Debug("Additional arguments:");
|
config.NonInteractiveMode = true;
|
||||||
|
|
||||||
|
int indexOfSpecificListsArg = Array.FindIndex(args, a => a.Contains(SPECIFIC_LISTS_ARG, StringComparison.OrdinalIgnoreCase));
|
||||||
|
int indexOfSpecificUsersArg = Array.FindIndex(args, a => a.Contains(SPECIFIC_USERS_ARG, StringComparison.OrdinalIgnoreCase));
|
||||||
|
char[] separator = [','];
|
||||||
|
|
||||||
|
if (indexOfSpecificListsArg >= 0)
|
||||||
|
{
|
||||||
|
int indexOfListValues = indexOfSpecificListsArg + 1;
|
||||||
|
|
||||||
|
string[] strListValues = args.ElementAtOrDefault(indexOfListValues)?.Split(separator, StringSplitOptions.RemoveEmptyEntries) ?? [];
|
||||||
|
if (strListValues.Length > 0)
|
||||||
|
{
|
||||||
|
config.NonInteractiveSpecificLists = strListValues;
|
||||||
|
config.NonInteractiveModeListName = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (indexOfSpecificUsersArg >= 0)
|
||||||
|
{
|
||||||
|
int indexOfUserValues = indexOfSpecificUsersArg + 1;
|
||||||
|
string[] strUserValues = args.ElementAtOrDefault(indexOfUserValues)?.Split(separator, StringSplitOptions.RemoveEmptyEntries) ?? [];
|
||||||
|
if (strUserValues.Length > 0)
|
||||||
|
{
|
||||||
|
config.NonInteractiveSpecificUsers = strUserValues;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Debug("Additional arguments:");
|
||||||
foreach (string argument in args)
|
foreach (string argument in args)
|
||||||
{
|
{
|
||||||
Log.Debug(argument);
|
Log.Debug(argument);
|
||||||
@ -898,7 +927,28 @@ public class Program
|
|||||||
{
|
{
|
||||||
hasSelectedUsersKVP = new KeyValuePair<bool, Dictionary<string, int>>(true, new Dictionary<string, int> { { "PurchasedTab", 0 } });
|
hasSelectedUsersKVP = new KeyValuePair<bool, Dictionary<string, int>>(true, new Dictionary<string, int> { { "PurchasedTab", 0 } });
|
||||||
}
|
}
|
||||||
else if (Config.NonInteractiveMode && string.IsNullOrEmpty(Config.NonInteractiveModeListName))
|
else if (Config.NonInteractiveMode && Config.NonInteractiveSpecificLists is not null && Config.NonInteractiveSpecificLists.Length > 0)
|
||||||
|
{
|
||||||
|
HashSet<string> listUsernames = [];
|
||||||
|
foreach (string listName in Config.NonInteractiveSpecificLists)
|
||||||
|
{
|
||||||
|
if (!lists.TryGetValue(listName, out int listId))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
List<string> usernames = await m_ApiHelper.GetListUsers($"/lists/{listId}/users", Config);
|
||||||
|
foreach (string user in usernames)
|
||||||
|
listUsernames.Add(user);
|
||||||
|
}
|
||||||
|
users = users.Where(x => listUsernames.Contains(x.Key)).Distinct().ToDictionary(x => x.Key, x => x.Value);
|
||||||
|
hasSelectedUsersKVP = new KeyValuePair<bool, Dictionary<string, int>>(true, users);
|
||||||
|
}
|
||||||
|
else if (Config.NonInteractiveMode && Config.NonInteractiveSpecificUsers is not null && Config.NonInteractiveSpecificUsers.Length > 0)
|
||||||
|
{
|
||||||
|
HashSet<string> usernames = [.. Config.NonInteractiveSpecificUsers];
|
||||||
|
users = users.Where(u => usernames.Contains(u.Key)).ToDictionary(u => u.Key, u => u.Value);
|
||||||
|
hasSelectedUsersKVP = new KeyValuePair<bool, Dictionary<string, int>>(true, users);
|
||||||
|
}
|
||||||
|
else if (Config.NonInteractiveMode && string.IsNullOrEmpty(Config.NonInteractiveModeListName))
|
||||||
{
|
{
|
||||||
hasSelectedUsersKVP = new KeyValuePair<bool, Dictionary<string, int>>(true, users);
|
hasSelectedUsersKVP = new KeyValuePair<bool, Dictionary<string, int>>(true, users);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user