Exemplo n.º 1
0
        private static HttpClient CreateHttpClient(DownloadKind downloadKind, bool useHttps)
        {
            var client = new HttpClient
            {
                BaseAddress = new Uri(GetBaseAddressForDownloadKind(downloadKind, useHttps))
            };

            client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
            return(client);
        }
Exemplo n.º 2
0
        public void DownloadRankingTest()
        {
            string temp_directory_path = TestUtility.TestData[TestUtility.KEY_TEMP_DIRECTORY];

            TestUtility.EnsureLogin(network_);

            DirectoryInfo temp_directory = new DirectoryInfo(temp_directory_path);

            DownloadKind kind = new DownloadKind();

            kind.SetDuration(true, false, false, false, false);
            CategoryItem categoryItem = new CategoryItem();

            categoryItem.id         = "music";
            categoryItem.short_name = "mus";
            categoryItem.name       = "音楽";
            categoryItem.page       = new int[] { 3, 1, 1, 1, 0 };
            List <CategoryItem> categoryList = new List <CategoryItem>();

            categoryList.Add(categoryItem);
            kind.CategoryList = categoryList;
            kind.SetTarget(true, true, true);
            kind.SetFormat(DownloadKind.FormatKind.Html);

            bool completed = false;

            msgout_.OnWrite = delegate(string str)
            {
                if (str == "すべてのランキングのDLが完了しました。\r\n")
                {
                    completed = true;
                }
            };

            Assert.That(TestUtility.InitDirectory(temp_directory), Is.True, "DownloadRankingTest1");

            TestUtility.Message("Running DownloadRankingTest - Download HTML");
            network_manager_.DownloadRanking(kind, temp_directory_path);

            Assert.That(completed, Is.True, "DownloadRankingTest2-1");
            int html_count = Directory.GetFiles(temp_directory_path, "*.html", SearchOption.AllDirectories).Length;

            Assert.That(html_count, Is.EqualTo(9), "DownloadRankingTest2-2");


            Assert.That(TestUtility.InitDirectory(temp_directory), Is.True, "DownloadRankingTest3");
            kind.SetFormatRss();

            TestUtility.Message("Running DownloadRankingTest - Download RSS");
            network_manager_.DownloadRanking(kind, temp_directory_path);

            Assert.That(completed, Is.True, "DownloadRankingTest4-1");
            html_count = Directory.GetFiles(temp_directory_path, "*.xml", SearchOption.AllDirectories).Length;
            Assert.That(html_count, Is.EqualTo(9), "DownloadRankingTest4-2");
        }
Exemplo n.º 3
0
        public void ParseRankingTest1() 
        {
            string temp_directory_path = TestUtility.TestData[TestUtility.KEY_TEMP_DIRECTORY];

            TestUtility.EnsureLogin(network_);

            DirectoryInfo temp_directory = new DirectoryInfo(temp_directory_path);

            Assert.That(TestUtility.InitDirectory(temp_directory), Is.True, "ParseRankingTest1-1");

            DownloadKind kind = new DownloadKind();
            kind.SetDuration(false, false, true, false, false);
            CategoryItem categoryItem = new CategoryItem();
            categoryItem.id = "music";
            categoryItem.short_name = "mus";
            categoryItem.name = "音楽";
            categoryItem.page = new int[] { 3, 1, 1, 1, 0 };
            List<CategoryItem> categoryList = new List<CategoryItem>();
            categoryList.Add(categoryItem);
            kind.CategoryList = categoryList;
            kind.SetTarget(true, true, true);
            kind.SetFormat(DownloadKind.FormatKind.Html);

            NicoNetwork.NetworkWaitDelegate onWait = delegate(string message, int current, int total)
            {
                TestUtility.Message("({0}/{1}){2}", current, total, message);
                TestUtility.Wait();
            };

            TestUtility.Message("Running ParseRankingTest1.");
            network_.DownloadRanking(temp_directory.FullName, kind, onWait);

            NicoListManager.ParseRankingKind parse_ranking_kind;
            List<Video> video_list;

            try
            {
                parse_ranking_kind = NicoListManager.ParseRankingKind.TotalPoint;
                video_list = NicoListManager.ParseRanking(temp_directory.FullName, DateTime.Now, parse_ranking_kind);
                Assert.Fail("ParseRankingTest1-2");
            }
            catch (InvalidOperationException e)
            {
                TestUtility.Message(e.Message);
            }

            parse_ranking_kind = NicoListManager.ParseRankingKind.TermPoint;
            video_list = NicoListManager.ParseRanking(temp_directory.FullName, DateTime.Now, parse_ranking_kind);
            Assert.That(video_list.Count, Is.GreaterThan(0), "ParseRankingTest1-3");
        }
Exemplo n.º 4
0
        private static string GetBaseAddressForDownloadKind(DownloadKind downloadKind, bool useHttps)
        {
            switch (downloadKind)
            {
            case DownloadKind.Thumbnail:
                return(ClientConstants.GetThumbnailUrlPrefix(useHttps));

            case DownloadKind.NormalImage:
                return(ClientConstants.GetImageUrlPrefix(useHttps));

            case DownloadKind.LargestAvailable:
                return(ClientConstants.GetFullSizeUrlPrefix(useHttps));

            default:
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 5
0
        private static DownloadKind GetDownloadKind(CategoryManager category_manager)
        {
            DownloadKind download_kind = new DownloadKind();

            download_kind.SetDuration(bool.Parse(option_["checkBoxDlRankDurationTotal"]),
                                      bool.Parse(option_["checkBoxDlRankDurationMonthly"]),
                                      bool.Parse(option_["checkBoxDlRankDurationWeekly"]),
                                      bool.Parse(option_["checkBoxDlRankDurationDaily"]),
                                      bool.Parse(option_["checkBoxDlRankDurationHourly"]));
            download_kind.SetTarget(false, bool.Parse(option_["checkBoxDlRankView"]), // 「総合」には未対応
                                    bool.Parse(option_["checkBoxDlRankRes"]),
                                    bool.Parse(option_["checkBoxDlRankMylist"]));

            download_kind.CategoryList = category_manager.GetDownloadCategoryItemList();

            if (bool.Parse(option_["radioButtonDlRankRss"]))
            {
                download_kind.IsRss = true;
            }
            return(download_kind);
        }
Exemplo n.º 6
0
        public void ParsePointRssTest2()
        {
            int wait_milliseconds = int.Parse(TestUtility.TestData[TestUtility.KEY_ACCESS_WAIT_MILLISECONDS]);
            DirectoryInfo temp_dir = new DirectoryInfo(TestUtility.TestData[TestUtility.KEY_TEMP_DIRECTORY]);
            string video_title = "【初音ミク】みくみくにしてあげる♪【してやんよ】";

            Assert.That(TestUtility.InitDirectory(temp_dir), Is.True, "parsePointRssTest2-1");

            TestUtility.EnsureLogin(network_);

            DownloadKind download_kind = new DownloadKind();
            download_kind.SetFormatRss();
            download_kind.SetTarget(true, false, false);
            download_kind.SetDuration(true, false, false, false, false);
            download_kind.CategoryList = new List<CategoryItem>();
            CategoryItem category_item = new CategoryItem();
            category_item.id = "music";
            category_item.name = "音楽";
            category_item.page = new int[] { 3, 1, 1, 0 };
            category_item.short_name = "mus";
            download_kind.CategoryList.Add(category_item);

            network_.DownloadRanking(temp_dir.FullName, download_kind, wait_milliseconds);
            FileInfo rss_file = Array.Find(temp_dir.GetFiles(), delegate(FileInfo fi) {
                return fi.Name.StartsWith("tot_mus_vie_1_");
            });

            Assert.That(rss_file, Is.Not.Null, "ParsePointRssTest2-2");

            string rss = IJFile.ReadVer2(rss_file.FullName, IJFile.EncodingPriority.Auto);
            List<Video> video_list = new List<Video>();
            NicoListManager.ParsePointRss(rss, DateTime.Now, video_list, true, false);

            Assert.That(video_list.Count, Is.GreaterThanOrEqualTo(1), "ParsePointRssTest2-3");
            Assert.That(video_list[0].title, Is.EqualTo(video_title), "ParsePointRssTest2-4");
        }
Exemplo n.º 7
0
 public ItemDownloader(DownloadKind downloadKind, bool useHttps)
 {
     DownloadKind = downloadKind;
     UsingHttps   = useHttps;
     HttpClient   = CreateHttpClient(downloadKind, useHttps);
 }
Exemplo n.º 8
0
 public ItemDownloader(DownloadKind downloadKind)
     : this(downloadKind, true)
 {
 }
Exemplo n.º 9
0
        public void DownloadRankingTest()
        {
            string temp_directory_path = TestUtility.TestData[TestUtility.KEY_TEMP_DIRECTORY];

            TestUtility.EnsureLogin(network_);

            DirectoryInfo temp_directory = new DirectoryInfo(temp_directory_path);

            Assert.That(TestUtility.InitDirectory(temp_directory), Is.True, "DownloadRankingTest1");

            DownloadKind kind         = new DownloadKind();
            CategoryItem categoryItem = new CategoryItem();

            categoryItem.id         = "music";
            categoryItem.short_name = "mus";
            categoryItem.name       = "音楽";
            categoryItem.page       = new int[] { 3, 1, 1, 1, 0 };
            List <CategoryItem> categoryList = new List <CategoryItem>();

            categoryList.Add(categoryItem);
            kind.CategoryList = categoryList;
            kind.SetTarget(true, true, true);
            kind.SetDuration(false, false, true, false, false);
            kind.SetFormat(DownloadKind.FormatKind.Rss);

            NicoNetwork.NetworkWaitDelegate onWait = delegate(string message, int current, int total)
            {
                TestUtility.Message("({0}/{1}){2}", current, total, message);
                TestUtility.Wait();
            };

            TestUtility.Message("Running DownloadRankingTest2.");
            network_.DownloadRanking(temp_directory.FullName, kind, onWait);

            List <string> name_list     = null;
            List <string> filename_list = new List <string>();

            kind.GetRankingNameList(ref name_list, ref filename_list);
            string[] downloaded_files = Directory.GetFiles(temp_directory.FullName, "*", SearchOption.AllDirectories);
            int      i = 0;

            foreach (string filename in filename_list)
            {
                i++;
                bool result = Array.Exists <string>(downloaded_files, delegate(string downloaded_file)
                {
                    return(Path.GetFileName(downloaded_file).StartsWith(filename));
                });
                Assert.That(result, Is.True, string.Format("DownloadRankingTest2-{0}", i));
            }
            i = 0;
            foreach (string downloaded_file in downloaded_files)
            {
                i++;
                bool result = filename_list.Exists(delegate(string filename)
                {
                    return(Path.GetFileName(downloaded_file).StartsWith(filename));
                });
                Assert.That(result, Is.True, string.Format("DownloadRankingTest3-{0}", i));
            }

            i = 0;
            foreach (string downloaded_file in downloaded_files)
            {
                i++;
                TestUtility.IsValidXml(downloaded_file);
            }
        }
Exemplo n.º 10
0
 private static string GetBaseAddressForDownloadKind(DownloadKind downloadKind, bool useHttps)
 {
     switch (downloadKind)
     {
         case DownloadKind.Thumbnail:
             return ClientConstants.GetThumbnailUrlPrefix(useHttps);
         case DownloadKind.NormalImage:
             return ClientConstants.GetImageUrlPrefix(useHttps);
         case DownloadKind.LargestAvailable:
             return ClientConstants.GetFullSizeUrlPrefix(useHttps);
         default:
             throw new InvalidOperationException();
     }
 }
Exemplo n.º 11
0
 private static HttpClient CreateHttpClient(DownloadKind downloadKind, bool useHttps)
 {
     var client = new HttpClient
     {
         BaseAddress = new Uri(GetBaseAddressForDownloadKind(downloadKind, useHttps))
     };
     client.DefaultRequestHeaders.UserAgent.ParseAdd(UserAgent);
     return client;
 }
Exemplo n.º 12
0
 public ItemDownloader(DownloadKind downloadKind, bool useHttps)
 {
     DownloadKind = downloadKind;
     UsingHttps = useHttps;
     HttpClient = CreateHttpClient(downloadKind, useHttps);
 }
Exemplo n.º 13
0
 public ItemDownloader(DownloadKind downloadKind)
     : this(downloadKind, true)
 { }