예제 #1
0
        private static void ReadRSSFeed(qbtService service, RSSSettings rssFeed)
        {
            Utils.Log("Reading RSS feed for {0}", rssFeed.url);

            try
            {
                XmlReader       reader = XmlReader.Create(rssFeed.url);
                SyndicationFeed feed   = SyndicationFeed.Load(reader);
                reader.Close();

                if (feed.Items.Any())
                {
                    // Cache list and save dates. Filter by list entry and oldest date > 1 month
                    DownloadItems(service, feed.Items);
                }
                else
                {
                    Utils.Log("No RSS items found.");
                }
            }
            catch (Exception ex)
            {
                Utils.Log("Error reading feed: {0}", ex.Message);
            }
        }
예제 #2
0
        private static void ReadRSSFeeds(qbtService service, List <RSSSettings> settings)
        {
            if (settings != null && settings.Any())
            {
                Utils.Log("Processing RSS feed list...");

                foreach (var rssFeed in settings)
                {
                    ReadRSSFeed(service, rssFeed);
                }
            }
            else
            {
                Utils.Log("No RSS feeds to process...");
            }
        }
예제 #3
0
        private static void DownloadItems(qbtService service, IEnumerable <SyndicationItem> items)
        {
            Utils.Log("Processing {0} RSS feed items.", items.Count());

            DownloadHistory history = new DownloadHistory();

            history.ReadHistory();

            foreach (SyndicationItem item in items)
            {
                string subject = item.Title.Text;

                var link = item.Links.FirstOrDefault();

                if (link != null)
                {
                    string torrentUrl = link.Uri.ToString();

                    if (history.Contains(torrentUrl))
                    {
                        Utils.Log("Skipping item for {0} (downloaded already).", subject, torrentUrl);
                        continue;
                    }

                    Utils.Log("Sending link for {0} ({1}) to QBT...", subject, torrentUrl);

                    if (service.DownloadTorrent(torrentUrl, "freeleech"))
                    {
                        history.AddHistory(item);
                    }
                    else
                    {
                        Utils.Log("Error: torrent add failed.");
                    }
                }
            }

            history.WriteHistory();
        }
예제 #4
0
        public static void Main(string[] args)
        {
            var settingPath = args.Where(p => p.EndsWith(".json", StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            LogHandler.InitLogs();

            if (string.IsNullOrEmpty(settingPath))
            {
                settingPath = "Settings.json";
            }

            try
            {
                if (!File.Exists(settingPath))
                {
                    Utils.Log("Settings not found: {0}", settingPath);
                    return;
                }

                string json = File.ReadAllText(settingPath);

                var settings = Utils.deserializeJSON <Settings>(json);

                qbtService service = new qbtService(settings.qbt);

                if (settings.deleteTasks)
                {
                    if (settings.deleteFiles)
                    {
                        Utils.Log("Filtered torrents will be deleted with their content.");
                    }
                    else
                    {
                        Utils.Log("Filtered torrents will be deleted (files will not be deleted).");
                    }
                }
                else
                {
                    Utils.Log("Filtered torrents will be paused.");
                }

                Utils.Log("Signing in to QBittorrent.");

                if (service.SignIn())
                {
                    Utils.Log("Getting Seeding Task list and mapping trackers...");
                    var tasks = service.GetTasks()
                                .OrderBy(x => x.name)
                                .ToList();

                    ProcessTorrents(service, tasks, settings);

                    if (settings.rssfeeds != null)
                    {
                        ReadRSSFeeds(service, settings.rssfeeds);
                    }
                }
                else
                {
                    Utils.Log("Login failed.");
                }
            }
            catch (Exception ex)
            {
                Utils.Log("Error initialising. {0}", ex);
            }
        }
예제 #5
0
        private static void ProcessTorrents(qbtService service, IList <Torrent> tasks, Settings settings)
        {
            Utils.Log("Processing torrent list...");

            var toKeep   = new List <Torrent>();
            var toDelete = new List <Torrent>();
            var limits   = new Dictionary <Torrent, int>();

            foreach (var task in tasks)
            {
                bool keepTask = true;
                var  tracker  = FindTaskTracker(task, settings);

                if (tracker != null)
                {
                    if (IsDeletable(task, tracker))
                    {
                        keepTask = false;
                    }

                    if (TrackerMsgIsDeletable(task, tracker))
                    {
                        keepTask = false;
                    }
                }

                if (keepTask)
                {
                    toKeep.Add(task);
                    Utils.Log($" - Keep: {task}");

                    if (tracker != null && tracker.up_limit.HasValue && task.up_limit != tracker.up_limit)
                    {
                        // Store the tracker limits.
                        limits[task] = tracker.up_limit.Value;
                    }
                }
                else
                {
                    toDelete.Add(task);
                    Utils.Log($" - Delete: {task}");
                }
            }

            if (limits.Any())
            {
                var limitGroups = limits.GroupBy(x => x.Value, y => y.Key);

                foreach (var x in limitGroups)
                {
                    int limit  = x.Key;
                    var hashes = x.Select(t => t.hash).ToArray();

                    if (!service.SetUploadLimit(hashes, limit))
                    {
                        Utils.Log($"Failed to set upload limits.");
                    }
                }
            }

            if (toDelete.Any())
            {
                var deleteHashes = toDelete.Select(x => x.hash).Distinct().ToArray();

                if (settings.deleteTasks)
                {
                    Utils.Log($"Deleting {deleteHashes.Count()} tasks...");
                    service.DeleteTask(deleteHashes, settings.deleteFiles);
                }
                else
                {
                    Utils.Log($"Pausing {deleteHashes.Count()} tasks...");
                    service.PauseTask(deleteHashes);
                }

                if (settings.email != null)
                {
                    Utils.Log("Sending alert email.");
                    Utils.SendAlertEmail(settings.email, toDelete);
                }
            }
            else
            {
                Utils.Log("No tasks to delete/pause.");
            }
        }