Example #1
0
        private static void ParseItemsXml(ref string downloadedXml, List <Anime> animeList, WatchListManager watchList)
        {
            var tokens = downloadedXml.Split(new string[] { "<item>", "</channel>" }, StringSplitOptions.None);

            for (int i = 0; i < tokens.Length; i++)
            {
                if (!tokens[i].EndsWith("</item>")) // Unneeded token, skipping it
                {
                    continue;
                }

                var tmpTitle = ExtractString(ref tokens[i], "<title>", "</title>");
                var tmpDate  = DateTime.Parse(ExtractString(ref tokens[i], "<pubDate>", "</pubDate>"));
                var tmpLink  = ExtractString(ref tokens[i], "<link>", "</link>");
                animeList.Add(new Anime()
                {
                    Title         = tmpTitle,
                    Link          = tmpLink,
                    PubDate       = tmpDate,
                    IsInWatchList = watchList.ContainsInWatchList(new Anime {
                        Title = tmpTitle, Link = tmpLink, PubDate = tmpDate
                    }),
                    IsReleasedToday = tmpDate.Date == DateTime.Now.Date
                });
            }
            // Sort the list with possibly updated DateTime values
            watchList.SortWatchList();
        }
Example #2
0
        static void Main()
        {
            SetSettingsFromFile(out int linkIndex);
            const string torrentClientPath = @"C:\Program Files\qBittorrent\qbittorrent.exe";

            string[] horribleSubsLinks = new string[] { "http://www.horriblesubs.info/rss.php?res=1080",
                                                        "http://www.horriblesubs.info/rss.php?res=720",
                                                        "http://www.horriblesubs.info/rss.php?res=sd" };
            string choice;

            WebClient        client    = new WebClient();
            WatchListManager watchList = new WatchListManager();
            List <Anime>     animeList = new List <Anime>();

            AppDomain.CurrentDomain.ProcessExit += ExitEvent;
            void ExitEvent(object sender, EventArgs e)
            {
                watchList.WriteWatchListFile();
                SaveSettingsToFile(ref linkIndex);
            }

            var downloadedXml = client.DownloadString(horribleSubsLinks[linkIndex]);

            ParseItemsXml(ref downloadedXml, animeList, watchList);
            while (true)
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.ResetColor();
                DisplayAnimeList(animeList);
                Console.WriteLine("[Any other key - quit] [0-... - anime to be downloaded] [w - add to watch list (eg. 0 11 43 ...)] [dw - display watchlist] [sq - switch quality] [r - refresh]");
                Console.Write("Pick a choice: ");
                choice = Console.ReadLine().ToLower();

                if (int.TryParse(choice, out int result)) // Download anime
                {
                    if (result < animeList.Count)
                    {
                        Process.Start(torrentClientPath, animeList[result].Link);
                        watchList.SetAnimeAsDownloadedByAnime(animeList[result]);
                    }
                    else
                    {
                        DisplayError($"ERROR: THE NUMBER PROVIDED IS TOO LARGE");
                    }
                }
                else if (choice == "r")
                {
                    animeList.Clear();
                    var newdownloadedXml = client.DownloadString(horribleSubsLinks[linkIndex]);
                    ParseItemsXml(ref newdownloadedXml, animeList, watchList);
                }
                else if (choice == "w") // Add to watch list
                {
                    Console.Write("Add animes to be added: ");
                    choice = Console.ReadLine();
                    if (string.IsNullOrEmpty(choice))
                    {
                        continue;
                    }
                    var values = choice.Split(null);
                    watchList.AddToWatchList(values, animeList);
                }
                else if (choice == "sq")
                {
                    Console.Write("0| 1080p\n1| 720p\n2| 480p\nPick quality: ");
                    choice = Console.ReadLine();
                    if (string.IsNullOrEmpty(choice))
                    {
                        continue;
                    }
                    if (int.TryParse(choice, out int index) && index < 3 && index >= 0)
                    {
                        if (linkIndex == index)
                        {
                            continue;
                        }
                        linkIndex = index;
                        animeList.Clear();
                        var newDownloadedXml = client.DownloadString(horribleSubsLinks[index]);
                        ParseItemsXml(ref newDownloadedXml, animeList, watchList);
                    }
                    else
                    {
                        DisplayError($"ERROR: INVALID INDEX {choice} PROVIDED");
                    }
                }
                else if (choice == "dw") // Display watch list
                {
                    while (true)
                    {
                        watchList.DisplayWatchList();

                        Console.WriteLine("[q - go back to main window] [0-... - download anime] [r - multiple removal (eg. 1 5 10 30 ...)]");
                        Console.Write("Pick a choice: ");
                        choice = Console.ReadLine().ToLower();
                        if (int.TryParse(choice, out int index))
                        {
                            if (index < watchList.WatchListCount)
                            {
                                if (string.IsNullOrEmpty(watchList.GetWatchListItemLink(index)))
                                {
                                    DisplayError("ERROR: This anime has no link");
                                    continue;
                                }
                                Process.Start(torrentClientPath, watchList.GetWatchListItemLink(index));
                                watchList.SetAnimeAsDownloadedByWatchListIndex(index);
                            }
                            else
                            {
                                DisplayError($"ERROR: THE NUMBER PROVIDED IS TOO LARGE");
                            }
                        }
                        else if (choice == "r")
                        {
                            if (watchList.WatchListCount == 0)
                            {
                                DisplayError($"ERROR: THERE ARE NO ENTRIES IN THE WATCHLIST");
                                continue;
                            }
                            Console.Write("Add animes to be removed: ");
                            choice = Console.ReadLine();

                            if (string.IsNullOrEmpty(choice))
                            {
                                continue;
                            }
                            var values = choice.Split(null);
                            watchList.RemoveMultipleEntriesFromWatchList(values, animeList);
                        }
                        else if (choice == "q")
                        {
                            break;
                        }
                    }
                }
                else
                {
                    // Quit console and write the files
                    break;
                }
            }
        }