private void btSave_Click(object sender, EventArgs e) { if (listView1.SelectedItems.Count == 0) { return; } var subject = (DoubanSubject)listView1.SelectedItems[0].Tag; if (!subject.TryQueryDetail(out var msg)) { MessageBox.Show($"查找豆瓣详细信息失败:{msg}", Properties.Resources.TextError, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!_torrentFile.UpdateDoubanInfo(FormMain.DbConnectionString, subject, out msg)) { MessageBox.Show(msg, Properties.Resources.TextError, MessageBoxButtons.YesNo, MessageBoxIcon.Error); return; } DoubanSubject = subject; DialogResult = DialogResult.OK; }
public static List <DoubanSubject> SearchById(string text, out string msg) { var subjectId = string.Empty; var list = new List <DoubanSubject>(); var match = Regex.Match(text, "https:\\/\\/movie.douban.com\\/subject\\/(\\d+)", RegexOptions.IgnoreCase); if (match.Success) { subjectId = match.Groups[1].Value; } else { match = Regex.Match(text, "(\\d+)"); if (match.Success) { subjectId = match.Groups[1].Value; } } if (string.IsNullOrEmpty(subjectId)) { msg = "不正确的豆瓣ID"; } else { var subject = new DoubanSubject() { id = subjectId }; subject.TryQueryDetail(out msg); subject.title = subject.name; subject.sub_title = subject.othername; list.Add(subject); } return(list); }
public static List <DoubanSubject> SearchSuggest(string text, out string msg) { msg = string.Empty; var list = new List <DoubanSubject>(); var q = Uri.EscapeDataString(text); var sUrl = $"https://movie.douban.com/j/subject_suggest?q={q}"; var uri = new Uri(sUrl); BuildCookies(); var jsonText = string.Empty; #if !DEBUG try { var request = (HttpWebRequest)WebRequest.Create(uri); request.CookieContainer = _cookieContainer; request.Method = "GET"; request.Accept = "application/json; charset=utf-8"; var response = (HttpWebResponse)request.GetResponse(); using (var sr = new StreamReader(response.GetResponseStream())) { jsonText = sr.ReadToEnd(); Debug.WriteLine(jsonText); } } catch (Exception e) { Debug.WriteLine(e.Message); msg = e.Message; } #else jsonText = File.ReadAllText(FormMain.CurrentPath + "\\temp\\douban_suggest_sbuject.json"); #endif if (string.IsNullOrEmpty(jsonText)) { return(list); } try { var subjects = JArray.Parse(jsonText).ToList(); foreach (var jobject in subjects) { var subject = new DoubanSubject { id = (string)jobject["id"], title = (string)jobject["title"], sub_title = (string)jobject["sub_title"], type = (string)jobject["type"], year = (string)jobject["year"], img_url = (string)jobject["img"] }; list.Add(subject); } } catch (Exception ex) { msg = ex.Message; } return(list); }
public bool UpdateDoubanInfo(string dbConnString, DoubanSubject subject, out string msg) { msg = string.Empty; var posterImageFileName = string.Empty; var mDbConnection = new SQLiteConnection(dbConnString); var sql = @"update tb_file set year=$year,zone=$zone,keyname=$keyname,othername=$othername,doubanid=$doubanid,posterpath=$posterpath, rating=$rating,genres=$genres,directors=$directors,casts=$casts where file_nid=$fid"; var ok = true; try { if (!string.IsNullOrEmpty(subject.img_local)) { posterImageFileName = FormMain.CurrentPath + "\\poster\\douban\\" + Path.GetFileName(subject.img_local); File.Copy(subject.img_local, posterImageFileName, true); posterImageFileName = posterImageFileName.Replace("\\", "/");//zogvm的路径使用正斜杠 } mDbConnection.Open(); try { var command = new SQLiteCommand(sql, mDbConnection); command.Parameters.AddWithValue("$year", string.IsNullOrEmpty(subject.year)?year:subject.year); command.Parameters.AddWithValue("$zone", subject.zone); command.Parameters.AddWithValue("$keyname", subject.name); command.Parameters.AddWithValue("$othername", string.IsNullOrEmpty(subject.othername)?otherName:subject.othername); command.Parameters.AddWithValue("$doubanid", subject.id); command.Parameters.AddWithValue("$posterpath", posterImageFileName); command.Parameters.AddWithValue("$rating", subject.Rating); command.Parameters.AddWithValue("$genres", subject.genres); command.Parameters.AddWithValue("$directors", subject.directors); command.Parameters.AddWithValue("$casts", subject.casts); command.Parameters.AddWithValue("$fid", fid); command.ExecuteNonQuery(); } catch (Exception e) { msg = e.Message; ok = false; } mDbConnection.Close(); } catch (Exception e) { msg = e.Message; ok = false; } if (!ok) { return(false); } genres = subject.genres; keyname = subject.name; otherName = string.IsNullOrEmpty(subject.othername) ? otherName : subject.othername; year = string.IsNullOrEmpty(subject.year) ? year : subject.year; zone = string.IsNullOrEmpty(subject.zone) ? zone : subject.zone; posterpath = posterImageFileName; doubanid = subject.id; rating = subject.Rating; return(true); }