Esempio n. 1
0
        public static List <Video> ParseRanking(string dir_name, DateTime getting_dt, ParseRankingKind kind)
        {
            string[]     files      = System.IO.Directory.GetFiles(dir_name);
            List <Video> video_list = new List <Video>();
            Dictionary <string, Video> video_dic = new Dictionary <string, Video>();

            for (int i = 0; i < files.Length; ++i)
            {
                int    t    = System.Environment.TickCount;
                string html = IJFile.ReadUTF8(files[i]);
                if (html.StartsWith("<?xml"))
                {
                    ParsePointRss(html, getting_dt, video_list, kind == ParseRankingKind.TotalPoint, false);
                }
                else
                {
                    switch (kind)
                    {
                    case ParseRankingKind.TermPoint:
                        ParseRankingTermPointHtml(html, getting_dt, video_list, video_dic);
                        break;

                    case ParseRankingKind.TotalPoint:
                        throw new InvalidOperationException("ランキングHTMLは全ポイント解析できません。");
                    }
                }
                System.Diagnostics.Debug.Write((System.Environment.TickCount - t).ToString() + ", ");
            }

            return(video_list);
        }
Esempio n. 2
0
        public void ParseCategoryFile()
        {
            string filename = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "category.txt");
            string str;

            if (File.Exists(filename))
            {
                str = IJFile.ReadUTF8(filename);
            }
            else
            {
                throw new FileNotFoundException("category.txt が存在しません。nicorank.exe を起動して category.txt を作成してください。");
            }

            string[] lines = IJStringUtil.SplitWithCRLF(str);

            for (int i = 1; i < lines.Length; ++i)
            {
                string[]     ar   = lines[i].Split('\t');
                CategoryItem item = new CategoryItem();
                item.id         = ar[0];
                item.short_name = ar[1];
                item.name       = ar[2];
                int[] page = new int[5];
                for (int j = 0; j < page.Length; ++j)
                {
                    page[j] = int.Parse(ar[3 + j]);
                }
                item.page = page;
                category_item_dic_.Add(item.name, item);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 指定された検索チケットの検索条件を取得する。
        /// </summary>
        /// <param name="ticket_id">検索条件を取得する検索チケットのID。</param>
        /// <returns>指定された検索チケットの検索条件。</returns>
        public static SearchingTagOption GetOption(string ticket_id)
        {
            string ticket_option_file = GetTicketOptionFile(ticket_id);
            string option_text        = IJFile.ReadUTF8(ticket_option_file);

            return(DeserializeSearchingOption(ticket_id, option_text));
        }
Esempio n. 4
0
        public IFilterManager GetFilter()
        {
            IFilterManager filter;

            if (is_using_filter && filter_filename != "" && File.Exists(filter_filename))
            {
                try
                {
                    string first_line = IJFile.ReadFirstLineUTF8(filter_filename);

                    // フィルター書式のバージョンを調べる(ファイルの最初の行が「version=2」であるかどうか)
                    bool is_version2 = IJStringUtil.CompareString(first_line, RootFilter.version_indicator);

                    string str;

                    if (is_version2)
                    {
                        // 新フィルターはUTF-8で読み込む
                        string str_with_version = IJFile.ReadUTF8(filter_filename);

                        // 先頭の「version=2」を削除する
                        int start_index = str_with_version.IndexOfAny(new char[] { '\r', '\n' }, 0);
                        if (start_index + 1 <= str_with_version.Length - 1)
                        {
                            str = str_with_version.Substring(start_index + 1);
                        }
                        else
                        {
                            str = string.Empty;
                        }

                        filter = GetFilter2(str);
                    }
                    else
                    {
                        str    = IJFile.Read(filter_filename);
                        filter = GetFilter1(str);
                    }
                }
                catch (Exception)
                {
                    throw new FormatException("フィルターの書式が間違えています。");
                }
                return(filter);
            }
            return(new Filter(is_output_filtered_video));
        }
Esempio n. 5
0
        public void ParseCategoryFile2(Form form)
        {
            string filename = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "category.txt");
            string str;

            if (File.Exists(filename))
            {
                str = IJFile.ReadUTF8(filename);

                if (!str.StartsWith("version"))                  // 昔のバージョンの category.txt なら
                {
                    if (str != Properties.Resources.category204) // ユーザによって改変されているなら
                    {
                        File.Move(filename,
                                  Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
                                               "category_old1.txt")); // 念のためバックアップを取る
                        if (form != null)
                        {
                            MessageBox.Show(form, "category.txt を category_old1.txt にリネームしました。",
                                            "ニコニコランキングメーカー", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        }
                        else // for console
                        {
                            System.Console.WriteLine("category.txt を category_old1.txt にリネームしました。");
                        }
                    }
                    else
                    {
                        File.Delete(filename);
                    }
                    str = Properties.Resources.category;
                    IJFile.WriteUTF8(filename, str);
                }
            }
            else
            {
                str = Properties.Resources.category;
                IJFile.WriteUTF8(filename, str);
            }

            string[] lines = IJStringUtil.SplitWithCRLF(str);

            for (int i = 1; i < lines.Length; ++i)
            {
                string[]     ar   = lines[i].Split('\t');
                CategoryItem item = new CategoryItem();
                item.id         = ar[0];
                item.short_name = ar[1];
                item.name       = ar[2];
                int[] page = new int[5];
                for (int j = 0; j < page.Length; ++j)
                {
                    page[j] = int.Parse(ar[3 + j]);
                }
                item.page = page;
                category_item_dic_.Add(item.name, item);

                clistbox_.Items.Add(item.name, Array.IndexOf(category_config_, item.id) >= 0);
            }
        }