Exemplo n.º 1
0
        /// <summary>>動画の詳細情報を取得するストリームを取得する、情報は0番目の配列に格納される</summary>
        /// <param name="IsHtml">合わせてHtmlから情報を取得するか、現在動画説明文のみ</param>
        public Streams <VideoInfoResponse> OpenVideoInfoDownloadStreams(bool IsHtml = true)
        {
            var streamDataList       = new List <StreamData>();
            VideoInfoResponse result = null;

            #region APIアクセス
            streamDataList.Add(
                new StreamData()
            {
                StreamType = StreamType.Read,
                GetStream  = () =>
                {
                    try
                    {
                        return(context.Client.OpenDownloadStream(string.Format(ApiUrls.GetVideoInfo, target.ID)));
                    }
                    catch (WebException e)
                    {
                        throw new WebException("動画情報取得APIにアクセス出来ませんでした", e);
                    }
                },
                SetReadData = (data) =>
                {
                    var serialize = new XmlSerializer(typeof(Serial.GetInfo.NicovideoThumbResponse));
                    var serial    = (Serial.GetInfo.NicovideoThumbResponse)serialize.Deserialize(
                        new MemoryStream(data));

                    result = converter.ConvertVideoInfoResponse(serial);
                }
            });
            #endregion

            #region HTMLアクセス
            if (IsHtml)//HTMLから取得する
            {
                var videoPageStreamData = OpenVideoPageStreamData();
                if (videoPageStreamData != null)
                {
                    var super = videoPageStreamData.SetReadData;

                    videoPageStreamData.SetReadData = (data) =>
                    {
                        if (result.Status != Status.OK)
                        {
                            return;
                        }

                        super(data);
                        result.VideoInfos[0].Description = HtmlTextRegex.VideoDescription.Match(htmlCache).Groups["value"].Value;
                    };

                    streamDataList.Add(videoPageStreamData);
                }
            }
            #endregion

            return(new Streams <VideoInfoResponse>(
                       streamDataList.ToArray(),
                       () => result));
        }
Exemplo n.º 2
0
        /// <summary>動画を検索するストリームを取得する</summary>
        /// <param name="Keyword">検索キーワード</param>
        /// <param name="SearchPage">検索ページの指定、1~nの間の数値を指定する</param>
        /// <param name="SearchType">検索方法を指定する</param>
        /// <param name="SearchOption">検索オプションを指定する</param>
        public Streams <Video.VideoInfoResponse> OpenSearchStreams(
            string Keyword,
            int SearchPage,
            SearchType SearchType,
            SearchOption SearchOption)
        {
            var serialize      = new DataContractJsonSerializer(typeof(Serial.Search.Contract));
            var streamDataList = new List <StreamData>();

            Video.VideoInfoResponse lastData = null;

            streamDataList.Add(
                new StreamData()
            {
                StreamType = StreamType.Read,
                GetStream  = () =>
                {
                    return(context.Client.OpenDownloadStream(
                               String.Format(
                                   ApiUrls.VideoSearch,
                                   SearchType.ToKey(),
                                   Keyword,
                                   SearchPage,
                                   SearchOption.ToKey())));
                },
                SetReadData = (data) =>
                {
                    lastData = converter.ConvertVideoInfoResponse(
                        (Serial.Search.Contract)serialize.ReadObject(new MemoryStream(data)));
                }
            });

            return(new Streams <Video.VideoInfoResponse>(
                       streamDataList.ToArray(),
                       () => lastData));
        }