AVEntertainments.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections.Specialized;
  6. using HtmlAgilityPack;
  7. using AVSORTER;
  8. using System.IO;
  9. namespace Gets
  10. {
  11. public class AVEntertainments:IGetable
  12. {
  13. MyWebClient wc;
  14. public AVEntertainments()
  15. {
  16. wc = new MyWebClient();
  17. }
  18. public List<MovieBasic> Query(string keyword)
  19. {
  20. Uri u = urlCombine(keyword);
  21. HtmlDocument doc = new HtmlDocument();
  22. wc.Headers.Set("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-TW; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5");
  23. wc.Headers.Set("Referer", "http://aventertainments.com/Main.aspx?languageID=2");
  24. wc.Headers.Set("Content-Type", "application/x-www-form-urlencoded");
  25. string htmlString = wc.GetHTML(u);
  26. doc.LoadHtml(htmlString );
  27. var listItems = doc.DocumentNode.SelectNodes("//table[@id='ctl00_ContentPlaceHolder1_Rows2Items1_MyList']/tr/td[@valign='top']/table");
  28. List<MovieBasic> l = new List<MovieBasic>();
  29. if (listItems == null)
  30. {
  31. return l;
  32. }
  33. foreach (var item in listItems)
  34. {
  35. var title = item.ChildNodes["tr"].ChildNodes["td"].ChildNodes["h4"].InnerText;
  36. //listItems[0].ChildNodes["table"].ChildNodes["tr"].ChildNodes["td"].ChildNodes["h4"].InnerText;
  37. title = title.Trim("&nbsp;".ToArray());
  38. var img_s = item.ChildNodes["tr"].ChildNodes["td"].ChildNodes["div"].ChildNodes["a"].ChildNodes["img"].Attributes["src"].Value;
  39. var actor = item.ChildNodes["tr"].ChildNodes["td"].ChildNodes["a"].InnerText;
  40. var maker = item.ChildNodes["tr"].ChildNodes["td"].Elements("a").ElementAt(1).InnerText;
  41. var itemURL = item.ChildNodes["tr"].ChildNodes["td"].ChildNodes["h4"].ChildNodes["a"].Attributes["href"].Value;
  42. var label = item.ChildNodes["tr"].ChildNodes["td"].InnerText;
  43. int st = label.IndexOf("商品番号:") + 5;
  44. int ed = label.IndexOf("発売日");
  45. label = label.Substring(st, ed - st).Trim().Trim("&nbsp;".ToArray());
  46. var _actorList = new List<string>();
  47. _actorList.Add(actor);
  48. MovieBasic mb = new MovieBasic()
  49. {
  50. Title = title,
  51. Img_s = img_s,
  52. Actor = _actorList,
  53. ItemURL = itemURL,
  54. Label = label,
  55. Maker = maker
  56. };
  57. l.Add(mb);
  58. }
  59. return l;
  60. //wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
  61. //wc.Headers.Add(System.Net.HttpRequestHeader.Referer, "https://www.aventertainments.com/login.aspx?languageID=1");
  62. //NameValueCollection nvc = new NameValueCollection();
  63. //nvc.Add("ctl00$ContentPlaceHolder1$uid","hansi-go@163.com");
  64. //nvc.Add("ctl00$ContentPlaceHolder1$passwd", "177991");
  65. //wc.UploadData("https://www.aventertainments.com/login.aspx?languageID=1", "POST", nvc);
  66. }
  67. private Uri urlCombine(string keyword)
  68. {
  69. return new Uri("http://www.aventertainments.com/search_Products.aspx?languageID=2&searchby=keyword&keyword=" + keyword);
  70. }
  71. public Movie GetMovie(MovieBasic movieBasic)
  72. {
  73. //wc.Headers.Set("Referer", "http://www.aventertainments.com/search_Products.aspx?languageID=2&searchby=keyword&keyword=cwp");
  74. //wc.Headers.Set("Host", "www.aventertainments.com");
  75. //wc.Headers.Set("Content-Type", "application/x-www-form-urlencoded");
  76. wc.Headers.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36");
  77. string html = wc.GetHTML(new Uri(movieBasic.ItemURL));
  78. var docc = new HtmlDocument();
  79. docc.LoadHtml(html);
  80. string Title = movieBasic.Title;
  81. string label = docc.DocumentNode.SelectNodes("//span[@class='redtitle']")[3].ParentNode.InnerText;
  82. string changjia = docc.DocumentNode.SelectNodes("//span[@class='redtitle']")[1].ParentNode.ChildNodes["a"].InnerText;
  83. string jiandu = string .Empty;
  84. string date = docc.DocumentNode.SelectNodes("//span[@class='redtitle']")[4].ParentNode.InnerText;
  85. string minutes = docc.DocumentNode.SelectNodes("//span[@class='redtitle']")[5].ParentNode.InnerText;
  86. string f_code = docc.DocumentNode.SelectNodes("//div[@class='top-title']")[0].InnerText.Replace("商品番号:","");
  87. string xilie = docc.DocumentNode.SelectNodes("//span[@class='redtitle']")[2].ParentNode.ChildNodes["a"].InnerText;
  88. string intro = docc.DocumentNode.SelectNodes("//div[@id='titlebox']/div[5]/p")[0].InnerText;
  89. string coverImage = docc.DocumentNode.SelectNodes("//div[@class='top_sample']")[0].InnerText.Trim();
  90. var imageFlag = "image: '";
  91. //找到imageFlag
  92. var st_num = coverImage.IndexOf(imageFlag);
  93. //找到imageFlag之后的引号
  94. var ed_num = coverImage.IndexOf('\'', st_num +imageFlag.Length);
  95. //截取刚才的两个找到的中间部分
  96. coverImage = coverImage.Substring(st_num + imageFlag.Length, ed_num - st_num - imageFlag.Length);
  97. System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"\d{1,2}/\d{1,2}/\d{4}");
  98. date = r.Match(date).Value;
  99. //*[@id="titlebox"]/ul[3]/li[5]
  100. Movie m = new Movie()
  101. {
  102. Title = Title,
  103. Lable = label,
  104. Maker = changjia,
  105. ReleaseDate = DateTime.Parse(date),
  106. Minutes = minutes,
  107. AVCode = f_code,
  108. Introduction = intro,
  109. Actor = movieBasic.Actor,
  110. ItemURL = movieBasic.ItemURL,
  111. CoverURL = coverImage,
  112. Producer = jiandu,
  113. Series = xilie
  114. };
  115. return m;
  116. }
  117. public bool GetCover(Movie mo)
  118. {
  119. wc.ReferURL = mo.ItemURL;
  120. FileInfo f = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AVE_Cover", mo.AVCode + ".jpg"));
  121. try
  122. {
  123. if (!Directory.Exists(Path.GetDirectoryName(f.FullName)))
  124. {
  125. Directory.CreateDirectory(Path.GetDirectoryName(f.FullName));
  126. }
  127. if (!File.Exists(f.FullName))
  128. {
  129. wc.DownloadFile(mo.CoverURL, f.FullName);
  130. }
  131. else
  132. {
  133. Console.WriteLine("已有封面 " + mo.Title);
  134. }
  135. }
  136. catch (Exception err)
  137. {
  138. return false;
  139. }
  140. mo.CoverFile = f.FullName;
  141. return true;
  142. }
  143. public string GetScreen_shotURL(Movie mo)
  144. {
  145. if (!string.IsNullOrEmpty(mo.CoverURL))
  146. {
  147. return mo.CoverURL.Replace("bigcover", "screen_shot");
  148. }
  149. else
  150. {
  151. return string.Empty;
  152. }
  153. }
  154. public bool IsInitCompleted
  155. {
  156. get
  157. {
  158. return true;
  159. }
  160. set
  161. {
  162. return;
  163. }
  164. }
  165. }
  166. }