Example #1
0
 protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
 {
     await(IsAll
         ? client.AddTorrentTagsAsync(Tags)
         : client.AddTorrentTagsAsync(Hash, Tags));
     return(ExitCodes.Success);
 }
Example #2
0
            protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var tags = await client.GetTagsAsync();

                Print(tags, true);
                return(ExitCodes.Success);
            }
                protected override Task Prepare(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    _from = TryParseTime(ScheduleFrom);
                    _to   = TryParseTime(ScheduleTo);

                    return(base.Prepare(client, app, console));

                    (int?hour, int?minute) TryParseTime(string input)
                    {
                        const DateTimeStyles styles =
                            DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite | DateTimeStyles.NoCurrentDateDefault;

                        if (input == null)
                        {
                            return(null, null);
                        }

                        DateTime dt;

                        if (DateTime.TryParseExact(input, "t", CultureInfo.CurrentCulture, styles, out dt))
                        {
                            return(dt.TimeOfDay.Hours, dt.TimeOfDay.Minutes);
                        }
                        if (DateTime.TryParseExact(input, "t", CultureInfo.InvariantCulture, styles, out dt))
                        {
                            return(dt.TimeOfDay.Hours, dt.TimeOfDay.Minutes);
                        }
                        throw new InvalidOperationException($"Invalid time format: \"{input}\". Please, specify time either in your local format or as HH:mm.");
                    }
                }
Example #4
0
            protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var path = await client.GetDefaultSavePathAsync();

                console.WriteLineColored(path, ColorScheme.Current.Normal);
                return(ExitCodes.Success);
            }
            protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var(apiVersion, legacyApiVersion, legacyApiMinVersion, qVersion) = await TaskHelper.WhenAll(
                    client.GetApiVersionAsync(),
                    client.GetLegacyApiVersionAsync(),
                    client.GetLegacyMinApiVersionAsync(),
                    client.GetQBittorrentVersionAsync());

                var doc = new Document(
                    new Grid
                {
                    Stroke   = UIHelper.NoneStroke,
                    Columns  = { UIHelper.FieldsColumns },
                    Children =
                    {
                        UIHelper.Row("QBittorrent version",    qVersion),
                        UIHelper.Row("API version",            apiVersion),
                        UIHelper.Row("Legacy API version",     legacyApiVersion),
                        UIHelper.Row("Legacy API min version", legacyApiMinVersion)
                    }
                }
                    ).SetColors(ColorScheme.Current.Normal);

                ConsoleRenderer.RenderDocument(doc);

                return(ExitCodes.Success);
            }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = await client.GetPreferencesAsync();

                        var  currentTrackers = prefs.AdditinalTrackers ?? new List <string>();
                        bool modified        = false;

                        foreach (var tracker in Trackers)
                        {
                            if (!currentTrackers.Contains(tracker))
                            {
                                currentTrackers.Add(tracker);
                                modified = true;
                            }
                        }

                        if (modified)
                        {
                            prefs = new Preferences {
                                AdditinalTrackers = currentTrackers
                            };
                            await client.SetPreferencesAsync(prefs);
                        }

                        return(ExitCodes.Success);
                    }
Example #7
0
                protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    var rules = await client.GetRssAutoDownloadingRulesAsync();

                    Print(rules.Select(r => new RssRuleViewModel(r.Key, r.Value)), true);
                    return(ExitCodes.Success);
                }
            protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var props = await client.GetTorrentPropertiesAsync(Hash);

                Print(new TorrentPropertiesViewModel(props));
                return(ExitCodes.Success);
            }
Example #9
0
                protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client,
                                                                                CommandLineApplication app, IConsole console)
                {
                    var rules = await client.GetRssAutoDownloadingRulesAsync();

                    if (rules.ContainsKey(Name))
                    {
                        throw new Exception($"The rule with the name \"{Name}\" already exists.");
                    }

                    var rule = new RssAutoDownloadingRule
                    {
                        Enabled                   = !Disabled,
                        MustContain               = MustContain ?? string.Empty,
                        MustNotContain            = MustNotContain ?? string.Empty,
                        UseRegex                  = UseRegex,
                        EpisodeFilter             = EpisodeFilter ?? string.Empty,
                        SmartFilter               = SmartFilter,
                        PreviouslyMatchedEpisodes = PreviouslyMatchedEpisodes,
                        AffectedFeeds             = AffectedFeeds,
                        IgnoreDays                = IgnoreDays,
                        LastMatch                 = LastMatch,
                        AddPaused                 = ConvertPauseState(Paused),
                        AssignedCategory          = Category ?? string.Empty,
                        SavePath                  = SavePath ?? string.Empty
                    };

                    await client.SetRssAutoDownloadingRuleAsync(Name, rule);

                    return(ExitCodes.Success);
                }
Example #10
0
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = await client.GetPreferencesAsync();

                        var  banList  = prefs.BannedIpAddresses ?? new List <string>();
                        bool modified = false;

                        foreach (var address in Addresses)
                        {
                            if (!banList.Contains(address))
                            {
                                banList.Add(address);
                                modified = true;
                            }
                        }

                        if (modified)
                        {
                            prefs = new Preferences {
                                BannedIpAddresses = banList
                            };
                            await client.SetPreferencesAsync(prefs);
                        }

                        return(ExitCodes.Success);
                    }
Example #11
0
            protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var info = await client.GetGlobalTransferInfoAsync();

                Print(new GlobalTransferInfoViewModel(info));
                return(ExitCodes.Success);
            }
                protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client,
                                                                                CommandLineApplication app, IConsole console)
                {
                    var plugins = await client.GetSearchPluginsAsync();

                    Print(plugins, Verbose);
                    return(ExitCodes.Success);
                }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var preferences = await client.GetPreferencesAsync();

                        var folders = preferences.ScanDirectories ?? new Dictionary <string, SaveLocation>();

                        Print(folders);
                        return(ExitCodes.Success);
                    }
            protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var contents = await client.GetTorrentContentsAsync(Hash);

                var viewModels = contents.Select((c, i) => new TorrentContentViewModel(c, i));

                Print(viewModels, true);
                return(ExitCodes.Success);
            }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = new Preferences {
                            AdditinalTrackers = new string[0]
                        };
                        await client.SetPreferencesAsync(prefs);

                        return(ExitCodes.Success);
                    }
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = new Preferences {
                            ScanDirectories = new Dictionary <string, SaveLocation>()
                        };
                        await client.SetPreferencesAsync(prefs);

                        return(ExitCodes.Success);
                    }
Example #17
0
                protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    var trackers = await client.GetTorrentTrackersAsync(Hash);

                    var viewModels = trackers.Where(t => Sticky || t.Url.IsAbsoluteUri).Select(t => new TorrentTrackerViewModel(t));

                    Print(viewModels, true);
                    return(ExitCodes.Success);
                }
Example #18
0
                    protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                    {
                        var prefs = await client.GetPreferencesAsync();

                        foreach (var address in prefs.BannedIpAddresses ?? Enumerable.Empty <string>())
                        {
                            console.WriteLineColored(address, ColorScheme.Current.Normal);
                        }
                        return(ExitCodes.Success);
                    }
            protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var urls = await client.GetTorrentWebSeedsAsync(Hash);

                foreach (var url in urls)
                {
                    console.WriteLineColored(url.AbsoluteUri, ColorScheme.Current.Normal);
                }
                return(ExitCodes.Success);
            }
                protected override Task Prepare(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    if (AskForServerPassword)
                    {
                        WebUIPassword = console.IsInputRedirected
                            ? console.In.ReadLine()
                            : Prompt.GetPassword("Please, enter your web interface password: ");
                    }

                    return(Task.CompletedTask);
                }
Example #21
0
            protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var apiVersion = await client.GetApiVersionAsync();

                var categories = apiVersion >= new ApiVersion(2, 1, 1)
                    ? await client.GetCategoriesAsync()
                    : (await client.GetPartialDataAsync()).CategoriesChanged;

                Print(categories.Values);
                return(ExitCodes.Success);
            }
                protected override Task Prepare(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    if (AskForSmtpPassword)
                    {
                        MailNotificationPassword = console.IsInputRedirected
                            ? console.In.ReadLine()
                            : Prompt.GetPassword("Please, enter your SMTP server password: ");
                    }

                    return(Task.CompletedTask);
                }
        protected async Task AuthenticateAsync(QBittorrentClient client)
        {
            if (!string.IsNullOrEmpty(UserName))
            {
                if (Password == null && AskForPassword)
                {
                    Password = Prompt.GetPassword("Please, enter your password: ");
                }

                await client.LoginAsync(UserName, Password);
            }
        }
Example #24
0
                protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    var partialData = await client.GetPartialDataAsync();

                    if (!partialData.TorrentsChanged.TryGetValue(Hash, out var info))
                    {
                        console.WriteLineColored($"No torrent matching hash {Hash} is found.", ColorScheme.Current.Warning);
                        return(ExitCodes.NotFound);
                    }

                    Print(info.Tags, true);
                    return(ExitCodes.Success);
                }
Example #25
0
                protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    if (Enum.TryParse(Value, true, out TorrentContentPriority priority))
                    {
                        await client.SetFilePriorityAsync(Hash, File, priority);
                    }
                    else
                    {
                        var contents = (await client.GetTorrentContentsAsync(Hash))?.ToList();
                        console.WriteLineColored(contents?[File]?.Priority.ToString(), ColorScheme.Current.Normal);
                    }

                    return(ExitCodes.Success);
                }
                protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    if (Set.HasValue)
                    {
                        await client.SetTorrentUploadLimitAsync(Hash, Set.Value);
                    }
                    else
                    {
                        var limit = await client.GetTorrentUploadLimitAsync(Hash);

                        PrintLimit(console, limit);
                    }
                    return(ExitCodes.Success);
                }
Example #27
0
                protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client,
                                                                                CommandLineApplication app, IConsole console)
                {
                    var rules = await client.GetRssAutoDownloadingRulesAsync();

                    if (!rules.TryGetValue(Name, out var rule))
                    {
                        throw new Exception($"The rule with the name \"{Name}\" does not exist.");
                    }

                    Set(nameof(rule.Enabled), !Disabled);
                    Set(nameof(rule.MustContain), MustContain);
                    Set(nameof(rule.MustNotContain), MustNotContain);
                    Set(nameof(rule.UseRegex), UseRegex);
                    Set(nameof(rule.EpisodeFilter), EpisodeFilter);
                    Set(nameof(rule.IgnoreDays), IgnoreDays);
                    Set(nameof(rule.LastMatch), LastMatch);
                    Set(nameof(rule.AssignedCategory), Category);
                    Set(nameof(rule.SavePath), SavePath);

                    if (Paused != null)
                    {
                        Set(nameof(rule.AddPaused), ConvertPauseState(Paused));
                    }

                    if (PreviouslyMatchedEpisodes != null)
                    {
                        rule.PreviouslyMatchedEpisodes = PreviouslyMatchedEpisodes
                                                         .Where(e => !string.IsNullOrWhiteSpace(e))
                                                         .ToList();
                    }

                    if (AffectedFeeds != null)
                    {
                        rule.AffectedFeeds = AffectedFeeds.Where(e => e.IsAbsoluteUri).ToList();
                    }

                    await client.SetRssAutoDownloadingRuleAsync(Name, rule);

                    return(ExitCodes.Success);

                    void Set <T>(string propertyName, T value)
                    {
                        if (value != null)
                        {
                            rule.GetType().GetProperty(propertyName).SetValue(rule, value);
                        }
                    }
                }
                protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    var isAlternative = await client.GetAlternativeSpeedLimitsEnabledAsync();

                    if (Set == null)
                    {
                        console.WriteLineColored($"Alternative speed mode enabled: {isAlternative}", ColorScheme.Current.Normal);
                    }
                    else if (isAlternative != Set)
                    {
                        await client.ToggleAlternativeSpeedLimitsAsync();
                    }

                    return(ExitCodes.Success);
                }
                protected override async Task <int> OnExecuteTorrentSpecificAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
                {
                    var response = await client.GetPeerPartialDataAsync(Hash);

                    if (response == null)
                    {
                        return(ExitCodes.Failure);
                    }

                    var peers = response.PeersChanged?.Values ?? Enumerable.Empty <PeerPartialInfo>();

                    Print(peers.Select(p => new PeerPartialInfoViewModel(p)));

                    return(ExitCodes.Success);
                }
Example #30
0
            protected override async Task <int> OnExecuteAuthenticatedAsync(QBittorrentClient client, CommandLineApplication app, IConsole console)
            {
                var apiVersion = await client.GetApiVersionAsync();

                if (apiVersion < new ApiVersion(2, 1))
                {
                    console.WriteLineColored("The --save-path parameter requires qBittorrent 4.1.3 or later.",
                                             ColorScheme.Current.Warning);
                    return(ExitCodes.Failure);
                }

                await client.EditCategoryAsync(Name, SavePath);

                return(ExitCodes.Success);
            }