public int Insert(Model.RARGB.Torrent model) { try { db.BeginTransaction(); var category = SingleCategory(model.Category.CategoryName); if (category != null) { model.CategoryID = category.CategoryID; } else { model.CategoryID = InsertCategory(model.Category); } if (model.CategoryID <= 0) { throw new Exception("Category写入失败!"); } int id = Convert.ToInt32(db.Insert(model)); if (id <= 0) { throw new Exception("Torrent写入失败!"); } db.CompleteTransaction(); return(id); } catch (Exception ex) { db.AbortTransaction(); return(-1); } }
public Model.RARGB.Torrent CollectionRARGBHtmlMovieTorrent(string token, int timeout = 30000) { var res_str = ""; CookieCollection cookie = new CookieCollection(); var url = "https://rarbg.is/torrent/" + token; try { var model = new Model.RARGB.Torrent(); model.Token = token; var request = hwru.SendRequest(url, null, null, null, null, "GET", out res_str, out cookie, Encoding.UTF8, timeout, true); if (request == null || request.StatusCode != HttpStatusCode.OK || res_str.Contains("Please wait while we try to verify your browser...") || res_str.Contains("We have too many requests from your ip in the past 24h")) { if (request.StatusCode == HttpStatusCode.NotFound) { throw new Exception(); } if (res_str.Contains("Please wait while we try to verify your browser...") || res_str.Contains("We have too many requests from your ip in the past 24h")) { ChangeIP(); } return(CollectionRARGBHtmlMovieTorrent(token)); } else { HtmlDocument hd = new HtmlDocument(); hd.LoadHtml(res_str); //name var name_node = hd.DocumentNode.SelectSingleNode("//h1[@itemprop='name']"); if (name_node != null) { //name var name = name_node.InnerText.Trim(); model.Title = name; } Console.WriteLine("正在分析:" + model.Title); //download var torrent_td_node = hd.DocumentNode.SelectSingleNode("//td[text()=' Torrent:']"); if (torrent_td_node != null) { var torrent_node = torrent_td_node.ParentNode.SelectSingleNode("./td[last()]"); if (torrent_node != null) { var torrent_a_node = torrent_node.SelectSingleNode("./a[1]"); var magnet_a_node = torrent_node.SelectSingleNode("./a[2]"); if (torrent_a_node != null) { //https://rarbg.is var torrent_url = torrent_a_node.GetAttributeValue("href", "").Trim(); torrent_url = string.IsNullOrWhiteSpace(torrent_url) ? null : "https://rarbg.is" + torrent_url; model.TorrentUrl = torrent_url; } if (magnet_a_node != null) { var magnet_url = magnet_a_node.GetAttributeValue("href", "").Trim(); model.MagnetUrl = magnet_url; //magnet:?xt=urn:btih:84e8b76691d27356dcb5b898ec3a8d7cfc5435f4&dn=The.Lifeguard.2013.1080p.BluRay.H264.AAC-RARBG&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710 var magnet_token = magnet_url.Replace("magnet:?xt=urn:btih:", "").Trim(); if (!string.IsNullOrWhiteSpace(magnet_token)) { magnet_token = magnet_token.Contains("&") ? magnet_token.Substring(0, magnet_token.IndexOf("&")) : magnet_token; } model.MagnetHash = magnet_token; } } } //Poster var poster_td_node = hd.DocumentNode.SelectSingleNode("//td[text()=' Poster:']"); if (poster_td_node != null) { var poster_node = poster_td_node.ParentNode.SelectSingleNode("./td[last()]/img"); if (poster_node != null) { var poster_url = poster_node.GetAttributeValue("src", "").Trim(); poster_url = string.IsNullOrWhiteSpace(poster_url) ? null : (poster_url.Contains("http") ? poster_url : "http:" + poster_url); model.Poster = poster_url; } } //IMDb var imdb_img_node = hd.DocumentNode.SelectSingleNode("//img[@src='//dyncdn.me/static/20/img/imdb3.png']"); if (imdb_img_node != null) { var imdb_node = imdb_img_node.ParentNode.ParentNode.SelectSingleNode("./td[last()]/a"); if (imdb_node != null) { var imdb_url = imdb_node.InnerText.Trim(); var imdb_id = string.IsNullOrWhiteSpace(imdb_url) ? null : imdb_url.Replace("http://imdb.com/title/", "").Replace("/", "").Trim(); model.IMDbID = imdb_id; } } //Category var category_td_node = hd.DocumentNode.SelectSingleNode("//td[text()=' Category:']"); if (category_td_node != null) { var category_node = category_td_node.ParentNode.SelectSingleNode("./td[last()]/a"); if (category_node != null) { var category_str = category_node.InnerText.Trim(); if (!string.IsNullOrWhiteSpace(category_str)) { model.Category = new Model.RARGB.Category() { CategoryName = category_str }; } } } //Size var size_td_node = hd.DocumentNode.SelectSingleNode("//td[text()=' Size:']"); if (size_td_node != null) { var size_node = size_td_node.ParentNode.SelectSingleNode("./td[last()]"); if (size_node != null) { var size_str = size_node.InnerText.Trim(); double?size = null; try { size = string.IsNullOrWhiteSpace(size_str) ? 0 : ((size_str.Contains("GB") ? Utils.StrToFloat(size_str.Replace("GB", "").Trim(), 0) : ((size_str.Contains("MB") ? Utils.StrToFloat(size_str.Replace("MB", "").Trim(), 0) : (size_str.Contains("KB") ? Utils.StrToFloat(size_str.Replace("KB", "").Trim(), 0) : 0)) * 1024.0)) * 1024.0 * 1024.0); size = size == 0 ? null : size; } catch (Exception) { size = null; } model.Size = size; } } //Added var added_td_node = hd.DocumentNode.SelectSingleNode("//td[text()=' Added:']"); if (added_td_node != null) { var added_node = added_td_node.ParentNode.SelectSingleNode("./td[last()]/span"); if (added_node != null) { DateTime?added_time = null; try { added_time = Convert.ToDateTime(added_node.InnerText.Trim()); } catch (Exception) { } model.Added = added_time; } } } return(model); } catch (Exception ex) { return(CollectionRARGBHtmlMovieTorrent(token)); } }