/// <summary>マイリストを更新するストリームを取得する</summary> /// <param name="UpdateItem">更新するマイリスト</param> /// <param name="IsGetToken">トークンを取得するかどうか</param> public Streams <Response> OpenMylistUpdateStreams(Mylist.Mylist UpdateItem, bool IsGetToken = true) { var streamDataList = new List <StreamData>(); Response result = null; if (IsGetToken) { streamDataList.AddRange(host.GetToken()); } var updateStreamDatas = context.Client.OpenUploadStreams(ApiUrls.UpdateMylist, ContentType.Form).GetStreamDatas(); updateStreamDatas[0].GetWriteData = () => Encoding.UTF8.GetBytes(string.Format( PostTexts.UpdateMylist, UpdateItem.ID, UpdateItem.Title, UpdateItem.Description, (UpdateItem.IsPublic) ? "1" : "0", host.token)); updateStreamDatas[1].SetReadData = (data) => { var serialize = new DataContractJsonSerializer(typeof(Serial.UpdateMylist.Contract)); result = converter.ConvertResponse((Serial.UpdateMylist.Contract)serialize.ReadObject(new MemoryStream(data))); }; streamDataList.AddRange(updateStreamDatas); return(new Streams <Response>( streamDataList.ToArray(), () => result)); }
/// <summary>マイリストへ動画を追加するストリームを取得する</summary> /// <param name="AddItem">追加する動画</param> /// <param name="IsGetToken">トークンを取得するかどうか</param> public Streams <Response> OpenMylistAddVideoStreams(Mylist.MylistItem AddItem, bool IsGetToken = true) { var streamDataList = new List <StreamData>(); StreamData[] uploadStreamDatas = null; Response result = null; if (IsGetToken) { streamDataList.AddRange(host.GetToken()); } if (target.ID == "")//とりあえずマイリスト { uploadStreamDatas = context.Client.OpenUploadStreams(ApiUrls.DeflistAddVideo, ContentType.Form).GetStreamDatas(); uploadStreamDatas[0].GetWriteData = () => { return(Encoding.UTF8.GetBytes(string.Format( PostTexts.DeflistAddVideo, AddItem.VideoInfo.ID, AddItem.Description, host.token))); }; } else { uploadStreamDatas = context.Client.OpenUploadStreams(ApiUrls.MylistAddVideo, ContentType.Form).GetStreamDatas(); uploadStreamDatas[0].GetWriteData = () => { return(Encoding.UTF8.GetBytes(string.Format( PostTexts.MylistAddVideo, target.ID, AddItem.VideoInfo.ID, AddItem.Description, "", host.token))); }; } uploadStreamDatas[1].SetReadData = (data) => { var serialize = new DataContractJsonSerializer(typeof(Serial.MylistAddVideo.Contract)); result = converter.ConvertResponse( (Serial.MylistAddVideo.Contract)serialize.ReadObject(new MemoryStream(data))); }; streamDataList.AddRange(uploadStreamDatas); return(new Streams <Response>( streamDataList.ToArray(), () => result)); }
/// <summary>コメントをアップロードするストリームを取得する</summary> /// <param name="Comment">投稿するコメント</param> public Streams <Response> OpenCommentUploadStreams(Comment Comment) { var videoAccessStreamData = OpenVideoAccessStreamData(); var streamDataList = new List <StreamData>(); var uploadStreamData = new StreamData[2]; string postkey = null; Response result = null; for (int i = 0; i < 2; i++) { uploadStreamData[i] = new StreamData(); } if (videoAccessStreamData != null) { streamDataList.Add(videoAccessStreamData); } if (videoCache == null || videoCache.Count < 15) { streamDataList.AddRange(OpenCommentDownloadStreams().GetStreamDatas()); } streamDataList.Add( new StreamData() { StreamType = StreamType.Read, GetStream = () => { return(context.Client.OpenDownloadStream( string.Format(ApiUrls.PostVideoComment, videoCache["block_no"], videoCache["thread_id"]))); }, SetReadData = (data) => { postkey = Uri.UnescapeDataString(Encoding.UTF8.GetString(data)).Replace("postkey=", ""); }, }); //コメント投稿ストリームデータ生成 var super = streamDataList[0].SetReadData; streamDataList[0].SetReadData = (data) => { super(data); var streamData = context.Client.OpenUploadStreams(videoCache["ms"], ContentType.XML).GetStreamDatas(); for (int i = 0; i < 2; i++) { uploadStreamData[i].StreamType = streamData[i].StreamType; uploadStreamData[i].GetStream = streamData[i].GetStream; } }; uploadStreamData[0].GetWriteData = () => { return(Encoding.UTF8.GetBytes( string.Format(PostTexts.PostVideoComment, videoCache["thread_id"], ((int)(Comment.PlayTime.TotalMilliseconds / 10)).ToString(), Comment.Command, videoCache["ticket"], videoCache["user_id"], postkey, Comment.Body))); }; uploadStreamData[1].SetReadData = (data) => { var serialize = new XmlSerializer(typeof(Serial.PostComment.Packet)); var serial = (Serial.PostComment.Packet)serialize.Deserialize(new MemoryStream(data)); result = converter.ConvertResponse(serial); videoCache["block_no"] = ((int)((serial.chat_result.no + 1) / 100)).ToString();//更新 }; streamDataList.AddRange(uploadStreamData); return(new Streams <Response>( streamDataList.ToArray(), () => result)); }