示例#1
0
文件: Comment.cs 项目: Hayao-H/Nicome
        /// <summary>
        /// waybackkeyを取得
        /// </summary>
        private async Task <string> GetWayBackKey(int thread, NicoContext context)
        {
            var client = context.NicoClient.Client;
            var res    = await client.GetAsync($"https://flapi.nicovideo.jp/api/getwaybackkey?thread={thread}");

            if (!res.IsSuccessStatusCode)
            {
                throw new HttpRequestException("waybackkeyの取得に失敗しました。");
            }

            var responseData = await res.Content.ReadAsStringAsync();

            var query = System.Web.HttpUtility.ParseQueryString(responseData);

            return(query["waybackkey"]);
        }
示例#2
0
文件: Comment.cs 项目: Hayao-H/Nicome
        /// <summary>
        /// threadkeyを取得
        /// </summary>
        private async Task <(string, string)> GetThreadKey(string thread, NicoContext context)
        {
            var logger = NicoLogger.GetLogger();
            var client = context.NicoClient.Client;

            logger.Debug($"threadkeyの取得を開始(thread_id: {thread})", moduleName);
            var res = await client.GetAsync(new Uri($"http://flapi.nicovideo.jp/api/getthreadkey?thread={thread}"));

            if (res.IsSuccessStatusCode)
            {
                var resContent = await res.Content.ReadAsStringAsync();

                logger.Debug($"threadkeyの取得が完了(response: {resContent})", moduleName);
                var query = System.Web.HttpUtility.ParseQueryString(resContent);
                return(query["threadkey"], query["force_184"]);
            }
            else
            {
                throw new Exception("threadkeyの取得に失敗しました。");
            }
        }
示例#3
0
文件: Comment.cs 项目: Hayao-H/Nicome
        /// <summary>
        /// コメントを取得する(エントリー・ポイント)
        /// </summary>
        /// <returns></returns>
        public async Task <List <ComApi.CommentBody.Json.JsonComment> > GetComment(WatchPage::BaseJson data, NicoContext context, bool kako = false)
        {
            var logger = NicoLogger.GetLogger();

            logger.Debug($"過去ログ: {kako}", moduleName);


            //threadkeyを取得
            (crInfo.Threadkey, crInfo.Force184) = await GetThreadKey(data.video.dmcInfo.thread.thread_id.ToString(), context);


            //最古コメントを取得
            logger.Log("現行コメントをダウンロード中...");
            var comments = new CommentList();

            comments.Add(await GetCommentData(data));
            ComApi::CommentBody.Json.Chat firstComment = comments.GetFirstComment();



            if (kako)
            {
                crInfo.WayBackKey = await GetWayBackKey(data.video.dmcInfo.thread.thread_id, context);

                //初期whenデータを作成
                int _when = comments.GetFirstComment().date;
                int i     = 1;
                do
                {
                    var kacomments = new CommentList();
                    logger.Log($"過去ログをダウンロード中...({i}件目、no.{firstComment.no}まで取得完了)");
                    kacomments.Add(await GetCommentData(data, _when));
                    try
                    {
                        firstComment = kacomments.GetFirstComment();
                    }
                    catch
                    {
                        break;
                    }
                    _when = firstComment.GetPrevDate();
                    comments.Merge(kacomments);
                    ++i;
                    if (comments.IsMax(i))
                    {
                        break;
                    }
                }while (firstComment.no > 1);
            }
            logger.Log("ダウンロードしたコメントの整合性をチェックしています。");
            comments.FormatComments();

            return(comments.Comments);
        }
示例#4
0
文件: Comment.cs 项目: Hayao-H/Nicome
        public async Task <NicoEnums::GenelicErrorCode> DownloadComment(string id)
        {
            var  logger     = NicoLogger.GetLogger();
            var  storeData  = new Store.Store().GetData();
            bool fileExists = Utils.IO.Exists(id);

            if (fileExists)
            {
                if (storeData.DoSkipOverWrite())
                {
                    logger.Warn($"id:{id}は既に保存のため、スキップします");
                    return(NicoEnums.GenelicErrorCode.SKIP);
                }
                else if (!storeData.DoOverWrite())
                {
                    while (true)
                    {
                        logger.Warn($"id:{id}は既に保存済です。上書きしますか?(Y/N)");
                        string continueOrNot = Console.ReadLine();
                        if (Regex.IsMatch(continueOrNot, "[yY]"))
                        {
                            break;
                        }
                        else if (Regex.IsMatch(continueOrNot, "[nN]"))
                        {
                            logger.Log("処理をスキップします。");
                            return(NicoEnums::GenelicErrorCode.OK);
                        }
                        else
                        {
                            logger.Error("YまたはNで答えて下さい。");
                            continue;
                        }
                    }
                }
            }

            VideoInfo video;
            List <ComApi.CommentBody.Json.JsonComment> comment;

            using (var context = new NicoContext())
            {
                if (!await context.GetContent(id, "コメントのダウンロード"))
                {
                    logger.Error("セッションの確立に失敗しました。");
                    return(NicoEnums::GenelicErrorCode.ERROR);
                }

                //nullチェック
                if (context.ApiData == null)
                {
                    logger.Error("APIデータの取得に失敗しました。");
                    return(NicoEnums.GenelicErrorCode.ERROR);
                }

                //動画情報
                video = context.GetVideoInfo();

                //投稿日時を指定
                storeData.SetPostDate(video.PostedDateTime);

                var comCliet = new CommentClient(context);
                try
                {
                    comment = await comCliet.GetComment(context.ApiData, context, storeData.DoDownloadCommentLog());
                }
                catch (Exception e)
                {
                    logger.Error(e.Message);
                    return(NicoEnums.GenelicErrorCode.ERROR);
                }
            }


            //保存
            var  save     = new Nicome.IO.Save(video);
            bool ioResult = save.TryWriteComment(comment);

            if (!ioResult)
            {
                return(NicoEnums::GenelicErrorCode.ERROR);
            }

            logger.Log("コメントの保存が完了しました。");

            return(NicoEnums.GenelicErrorCode.OK);
        }
示例#5
0
文件: Comment.cs 项目: Hayao-H/Nicome
 public CommentClient(NicoContext _context)
 {
     context = _context;
 }