public video_info gets_video_info(string aid) { var client = new RestClient("http://api.bilibili.com/x/web-interface/view?aid=" + aid); client.Timeout = -1; var request = new RestRequest(Method.GET); IRestResponse response = client.Execute(request); JObject recommend = (JObject)JsonConvert.DeserializeObject(response.Content); video_info videoinfo = new video_info(); JToken data = recommend["data"]; if (Convert.ToInt32(recommend["code"]) == 0) { videoinfo.Success = true; videoinfo.aid = aid; videoinfo.bvid = data["bvid"].ToString(); videoinfo.videos = Convert.ToInt32(data["videos"]); videoinfo.tid = Convert.ToInt32(data["tid"]); videoinfo.tname = data["tname"].ToString(); videoinfo.copyright = Convert.ToInt32(data["copyright"]); videoinfo.pic = data["pic"].ToString(); videoinfo.title = data["title"].ToString(); videoinfo.ctime = data["ctime"].ToString(); videoinfo.desc = data["desc"].ToString(); videoinfo.mid = data["owner"]["mid"].ToString(); videoinfo.name = data["owner"]["name"].ToString(); videoinfo.face = data["owner"]["face"].ToString(); videoinfo.view = Convert.ToInt32(data["stat"]["view"]); videoinfo.danmaku = Convert.ToInt32(data["stat"]["danmaku"]); videoinfo.reply = Convert.ToInt32(data["stat"]["reply"]); videoinfo.favorite = Convert.ToInt32(data["stat"]["favorite"]); videoinfo.coin = Convert.ToInt32(data["stat"]["coin"]); videoinfo.share = Convert.ToInt32(data["stat"]["share"]); videoinfo.like = Convert.ToInt32(data["stat"]["like"]); videoinfo.pages = new pages[videoinfo.videos]; for (int i = 0; i < videoinfo.videos; i++) { videoinfo.pages[i].cid = data["pages"][i]["cid"].ToString(); videoinfo.pages[i].page = Convert.ToInt32(data["pages"][i]["page"]); videoinfo.pages[i].part = data["pages"][i]["part"].ToString(); } client = null; request = null; response = null; return(videoinfo); } else { MessageBox.Show("该视频不存在"); videoinfo.Success = false; client = null; request = null; response = null; return(videoinfo); } }
public bool SaveVideoInfo(video_info videoInfo, List <video_label> videoLabels) { using (userEntities user = new userEntities()) { using (var tran = user.Database.BeginTransaction()) { try { videoInfo.v_create_time = HelpFunction.ConvertToTimestamp(DateTime.Now); user.video_info.Add(videoInfo); int iRent = user.SaveChanges(); if (iRent > 0) { if (videoLabels.Count > 0) { foreach (var item in videoLabels) { item.v_id = videoInfo.id; } user.video_label.AddRange(videoLabels); user.SaveChanges(); } } tran.Commit(); return(true); } catch (Exception ex) { tran.Rollback(); Trace.WriteLine(ex); } } } return(false); }
private void DownloadVideo(object obj) { string text = System.IO.File.ReadAllText(jsonpath); var jObject = Newtonsoft.Json.Linq.JObject.Parse(text); int index = 0; foreach (var section in jObject) { if (index < videoindex) { index++; continue; } Thread.Sleep(50); if (bPause == true) { videoindex = index; break; } if (section.Key.ToString().Length > 0) { video_info data = JsonConvert.DeserializeObject <video_info>(section.Value.ToString()); PrintMessage("URL: " + data.url); IEnumerable <VideoInfo> videoInfos = download.GetDownloadUrls(data.url, checkBox.Checked); if (videoInfos == null) { index++; PrintMessage("video fail: " + data.url); continue; } if (videoInfos.Count() == 0) { index++; PrintMessage("skip video"); continue; } string folder = String.Format(@".\{0}", data.subset); if (Directory.Exists(folder) == false) { Directory.CreateDirectory(folder); } if (data.subset != "testing") { folder = String.Format(@".\{0}\{1}", data.subset, data.array[0].label); if (Directory.Exists(folder) == false) { Directory.CreateDirectory(folder); } } videofile = String.Format(@".\{0}\{1}.mp4", folder, section.Key.ToString()); var th = new Thread(ExecuteInForeground); th.Start(videoInfos); th.Join(); Thread.Sleep(100); PrintMessage("download result: " + download_result); } index++; } PrintMessage("done"); }
private void ButtonOK_OnClick(object sender, RoutedEventArgs e) { if (!IsCheckInput()) { return; } video_info videoInfo = new video_info(); videoInfo.v_brief = this.TextBrief.Text; if (TextArtType.GetCategory() != null) { videoInfo.v_category = this.TextArtType.GetCategory().fc_id; } if (TextArtType.GetSecondCategory() != null) { videoInfo.v_second_category = this.TextArtType.GetSecondCategory().cs_id; } if (TextArtType.GetThirdCategory() != null) { videoInfo.v_third_category = this.TextArtType.GetThirdCategory().ct_id; } videoInfo.v_create_time = HelpFunction.ConvertToTimestamp(DateTime.Now); videoInfo.v_detail_intro = this.TextIntro.Text; videoInfo.v_duration = this.TextVideoDuration.Value; videoInfo.v_front_icon = this.TextFrontImg.GetUrl(); videoInfo.v_title = this.TextBoxTitle.Text; videoInfo.v_video_url = this.TextVideo.GetUrl(); List <video_label> listTag = new List <video_label>(); if (!string.IsNullOrEmpty(this.ArtTags.Label1.Trim())) { listTag.Add(new video_label() { label_text = ArtTags.Label1.Trim() }); } if (!string.IsNullOrEmpty(this.ArtTags.Label2.Trim())) { listTag.Add(new video_label() { label_text = ArtTags.Label2.Trim() }); } if (!string.IsNullOrEmpty(this.ArtTags.Label3.Trim())) { listTag.Add(new video_label() { label_text = ArtTags.Label3.Trim() }); } bool bl = VideoDataMgr.Instance.SaveVideoInfo(videoInfo, listTag); if (bl) { MessageBox.Show("保存成功"); this.DialogResult = true; } else { MessageBox.Show("保存失败"); this.DialogResult = false; } }