Beispiel #1
0
        public static Video GetVideo(NicoNetwork network, string video_id, CancelObject cancel_object, MessageOut msgout)
        {
            Video video = null;

            for (int error_times = 0; ; ++error_times)
            {
                try
                {
                    video = new Video(network.GetThumbInfo(video_id));
                }
                catch (Exception)
                {
                    if (error_times >= checking_error_num_ - 1)
                    {
                        return(Video.GetOtherStateVideo());
                    }
                    else
                    {
                        if (msgout != null)
                        {
                            msgout.Write("ニコニコ動画へのアクセスエラーが起きました。3秒後に再試行します。\r\n");
                        }
                        cancel_object.Wait(3000);
                        continue;
                    }
                }
                break;
            }
            return(video);
        }
Beispiel #2
0
        private string RemoveMylistGroup(NicoNetwork network, string mylist_id, string token)
        {
            HttpWebRequest request = WebRequest.Create("http://www.nicovideo.jp/api/mylistgroup/delete") as HttpWebRequest;

            request.Method = "POST";
            string          cookie_value     = network.GetUserSession();
            Cookie          cookie           = new Cookie("user_session", cookie_value, "/", ".nicovideo.jp");
            CookieContainer cookie_container = new CookieContainer();

            cookie_container.Add(cookie);
            request.CookieContainer = cookie_container;
            request.ContentType     = "application/x-www-form-urlencoded; charset=UTF-8";
            request.Headers.Add("x-requested-with", "XMLHttpRequest");

            string post_data = IJNetwork.ConstructPostData(
                "group_id", mylist_id,
                "token", token);

            using (Stream request_stream = request.GetRequestStream())
                using (TextWriter request_writer = new StreamWriter(request_stream, new UTF8Encoding()))
                {
                    request_writer.Write(post_data);
                }

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                using (Stream response_stream = response.GetResponseStream())
                    using (TextReader response_reader = new StreamReader(response_stream, new UTF8Encoding()))
                    {
                        return(response_reader.ReadToEnd());
                    }
        }
Beispiel #3
0
        internal static void EnsureLogin(NicoNetwork network)
        {
            string ok_mail      = TestUtility.TestData[TestUtility.KEY_OK_MAIL];
            string ok_pass      = TestUtility.TestData[TestUtility.KEY_OK_PASS];
            bool   login_result = false;

            if (!network.IsLoginNiconico())
            {
                login_result = network.LoginNiconico(ok_mail, ok_pass);
            }
            Assert.That(login_result, Is.True, "EnsureLogin");
        }
Beispiel #4
0
 public void Setup()
 {
     network_         = new NicoNetwork();
     msgout_          = new TestMessageOut();
     cancel_object_   = new CancelObject();
     network_manager_ = new NicoNetworkManager(network_, msgout_, cancel_object_);
     NicoTools.NicoNetworkManager.StringDelegate string_delegate = delegate(string str)
     {
         Console.WriteLine(str);
     };
     network_manager_.SetDelegateSetDonwloadInfo(string_delegate);
 }
Beispiel #5
0
 static void LoadCookie(NicoNetwork network)
 {
     if (bool.Parse(option_["radioButtonBrowserIE"]))
     {
         network.SetCookieKind(NicoNetwork.CookieKind.IE);
     }
     else if (bool.Parse(option_["radioButtonBrowserFirefox3"]))
     {
         network.SetCookieKind(NicoNetwork.CookieKind.Firefox3);
     }
     else if (bool.Parse(option_["radioButtonBrowserOpera"]))
     {
         network.SetCookieKind(NicoNetwork.CookieKind.Opera);
     }
     else if (bool.Parse(option_["radioButtonBrowserChrome"]))
     {
         network.SetCookieKind(NicoNetwork.CookieKind.Chrome);
     }
 }
Beispiel #6
0
 public void Setup()
 {
     network_ = new NicoNetwork();
 }
Beispiel #7
0
 public NicoCommentManager(NicoNetwork network, MessageOut msgout, CancelObject cancel_object)
 {
     niconico_network_ = network;
     msgout_           = msgout;
     cancel_object_    = cancel_object;
 }
Beispiel #8
0
 public NicoMylist(NicoNetwork network, MessageOut msgout, CancelObject cancel_object)
 {
     niconico_network_ = network;
     msgout_           = msgout;
     cancel_object_    = cancel_object;
 }
Beispiel #9
0
        static void Main(string[] args)
        {
            try
            {
                if (args.Length <= 1)
                {
                    ShowUsage();
                    System.Environment.Exit(1);
                }

                Receiver           receiver      = new Receiver();
                CancelObject       cancel_object = new CancelObject();
                NicoNetwork        network       = new NicoNetwork();
                NicoNetworkManager network_mgr   = new NicoNetworkManager(network, receiver, cancel_object);
                NicoMylist         nico_mylist   = new NicoMylist(network, receiver, cancel_object);

                for (int i = 2; i < args.Length; ++i)
                {
                    switch (args[i])
                    {
                    case "-i":
                        if (i < args.Length - 1)
                        {
                            input_rank_file_ = Dequote(args[i + 1]);
                            if (!File.Exists(input_rank_file_))
                            {
                                System.Console.WriteLine("入力ランクファイルが存在しません。");
                                System.Environment.Exit(1);
                            }
                            ++i;
                        }
                        else
                        {
                            System.Console.WriteLine("入力ランクファイルを指定してください。");
                            System.Environment.Exit(1);
                        }
                        break;

                    case "-o":
                        if (i < args.Length - 1)
                        {
                            output_rank_file_ = Dequote(args[i + 1]);
                            ++i;
                        }
                        break;

                    case "-c":
                        if (i < args.Length - 1)
                        {
                            config_file_ = Dequote(args[i + 1]);
                            ++i;
                        }
                        break;
                    }
                }

                if (string.IsNullOrEmpty(config_file_)) // config ファイル指定なしの場合
                {
                    config_file_ = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "config.txt");
                    if (!File.Exists(config_file_))
                    {
                        System.Console.WriteLine("最初に nicorank.exe を起動してオプションを指定してください。");
                        System.Environment.Exit(1);
                    }
                }
                else
                {
                    if (!File.Exists(config_file_))
                    {
                        System.Console.WriteLine("config ファイルが見つかりません。");
                        System.Environment.Exit(1);
                    }
                }
                ParseConfig(IJFile.Read(config_file_));

                InputOutputOption iooption = new InputOutputOption(!string.IsNullOrEmpty(input_rank_file_), !string.IsNullOrEmpty(output_rank_file_));
                if (string.IsNullOrEmpty(input_rank_file_)) // 標準入力から
                {
                    iooption.SetInputFromStdin();
                }
                else
                {
                    iooption.SetInputPath(input_rank_file_);
                }
                if (string.IsNullOrEmpty(output_rank_file_)) // 標準出力へ
                {
                    iooption.SetOutputRankFileDelegate(delegate(string s)
                    {
                        System.Console.Write(s);
                    });
                }
                else
                {
                    iooption.SetOutputPath(output_rank_file_);
                }

                switch (args[0])
                {
                case "download":
                    switch (args[1])
                    {
                    case "ranking":
                        CategoryManager category_manager = new CategoryManager();
                        category_manager.SetString(option_["dlrank_category"]);
                        category_manager.ParseCategoryFile();
                        network_mgr.DownloadRanking(GetDownloadKind(category_manager), option_["textBoxRankDlDir"]);
                        break;

                    case "video":
                        LoadCookie(network);
                        network_mgr.DownloadFlv(iooption, option_["textBoxDlInterval"], MakeDirectoryPath(option_["textBoxFlvDlDir"]),
                                                bool.Parse(option_["checkBoxIsFixFlvDlExtension"]));
                        break;

                    default:
                        ShowInvalidAndUsage(args[1]);
                        System.Environment.Exit(1);
                        break;
                    }
                    break;

                case "list":
                    switch (args[1])
                    {
                    case "searchtag":
                        network_mgr.MakeListAndWriteBySearchTag(iooption, MakeSearchingTagOption(), MakeRankingMethod());
                        break;

                    default:
                        ShowInvalidAndUsage(args[1]);
                        System.Environment.Exit(1);
                        break;
                    }
                    break;

                case "mylist":
                    switch (args[1])
                    {
                    case "add":
                        LoadCookie(network);
                        nico_mylist.AddMylist(iooption, option_["textBoxMylistId"]);
                        break;

                    default:
                        ShowInvalidAndUsage(args[1]);
                        System.Environment.Exit(1);
                        break;
                    }
                    break;

                default:
                    ShowInvalidAndUsage(args[0]);
                    System.Environment.Exit(1);
                    break;
                }
            }
            catch (KeyNotFoundException e)
            {
                System.Console.WriteLine("エラーが発生しました。");
                System.Console.WriteLine("キーが存在しません: " + e.Data.ToString());
            }
            catch (Exception e)
            {
                System.Console.WriteLine("エラーが発生しました。");
                System.Console.WriteLine("エラー\r\n---メッセージ\r\n" +
                                         e.Message + "\r\n---ソース\r\n" + e.Source + "\r\n---スタックトレース\r\n" +
                                         e.StackTrace + "\r\n---ターゲット\r\n" + e.TargetSite + "\r\n---文字列\r\n" +
                                         e.ToString());
            }
        }