Arzon.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using AVSORTER;
  6. using System.Text.RegularExpressions;
  7. using HtmlAgilityPack;
  8. using System.IO;
  9. using System.Runtime.Serialization.Formatters.Binary;
  10. namespace Gets
  11. {
  12. public class Arzon : AVSORTER.IGetable, ICloneable
  13. {
  14. Uri uri;
  15. MyWebClient wc;
  16. /// <summary>
  17. /// 构造函数
  18. /// </summary>
  19. /// <param name="IsInit">决定是否初始化Cookie,初始化Cookie需要耗费时间并且需要联网,或者根据需要手动调用CookiesInit()方法</param>
  20. public Arzon(bool IsInit)
  21. {
  22. wc = new MyWebClient();
  23. if (IsInit)
  24. {
  25. CookiesInit();
  26. }
  27. }
  28. public void CookiesInit()
  29. {
  30. const string url = @"http://www.arzon.jp/index.php?action=adult_customer_agecheck&agecheck=1";//&redirect=http%3A%2F%2Fwww.arzon.jp%2F";
  31. uri = new Uri(url);
  32. wc.DownloadDataCompleted += wc_DownloadDataCompleted;
  33. wc.DownloadDataAsync(uri, "init");
  34. }
  35. public event EventHandler InitCompleted;
  36. void wc_DownloadDataCompleted(object sender, System.Net.DownloadDataCompletedEventArgs e)
  37. {
  38. if ((e.UserState as string) == "init")
  39. {
  40. this.IsInitCompleted = true;
  41. if (this.InitCompleted!=null)
  42. {
  43. this.InitCompleted(this, new EventArgs());
  44. }
  45. }
  46. }
  47. public bool IsInitCompleted { get; set; }
  48. public List<MovieBasic> Query(string fcode)
  49. {
  50. Uri u = urlCombine(fcode);
  51. HtmlAgilityPack.HtmlDocument doc = new HtmlDocument();
  52. doc.LoadHtml(wc.GetHTML(u));
  53. //doc.DocumentNode.SelectNodes("//li[@class='saledate']/span")[3].InnerText
  54. var listitems = doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div[@class='data']/ul[1]/li[2]");
  55. var htmnode = doc.DocumentNode.SelectSingleNode("//div[@class='autopagerize_page_element']");
  56. if (htmnode == null)
  57. {
  58. //查无此片
  59. return new List<MovieBasic>();
  60. }
  61. string htm = htmnode.InnerHtml;
  62. List<MovieBasic> l = new List<MovieBasic>();
  63. //<div class="autopagerize_page_element">
  64. int cou = doc.DocumentNode.SelectNodes("//div[@id='itemd']").Count;
  65. for (int i = 0; i < cou; i++)
  66. {
  67. string n_title = doc.DocumentNode.SelectNodes("//div[@id='itemd']")[i].ChildNodes["ul"].ChildNodes["li"].ChildNodes["h3"].InnerText;
  68. n_title = Tools.RemoveInvalidChars(n_title);
  69. string n_itemURL = "http://" + u.Host + doc.DocumentNode.SelectNodes("//div[@id='itemd']")[i].ChildNodes["ul"].ChildNodes["li"].ChildNodes["h3"].ChildNodes["a"].Attributes["href"].Value;
  70. string n_date = doc.DocumentNode.SelectSingleNode("//div[@id='itemd']/ul/li/span[@class='date']").InnerText;
  71. var datanode = doc.DocumentNode.SelectNodes("//div[@class='data']")[i];
  72. HtmlDocument docData = new HtmlDocument();
  73. docData.LoadHtml(datanode.InnerHtml);
  74. int k = docData.DocumentNode.SelectNodes("//ul[1]/li").Count;
  75. string n_actor = string.Empty;
  76. List<string> actors = new List<string>();
  77. if (k > 1)
  78. {
  79. for (int j = k; j > 1; j--)
  80. {
  81. n_actor = docData.DocumentNode.SelectNodes("//ul[1]/li[" + j + "]")[0].InnerText.Trim();
  82. actors.Add(n_actor);
  83. }
  84. }
  85. string n_maker = docData.DocumentNode.SelectSingleNode("//ul[2]/li[2]").InnerText.Trim();
  86. string n_company = docData.DocumentNode.SelectSingleNode("//ul[3]/li[2]").InnerText.Trim();
  87. var n_ticai_node = docData.DocumentNode.SelectSingleNode("//ul[4]/li[2]");
  88. string n_ticai;
  89. if (n_ticai_node == null)
  90. {
  91. n_ticai = string.Empty;
  92. }
  93. else
  94. {
  95. n_ticai = n_ticai_node.InnerText.Trim();
  96. }
  97. string s_img = doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div/a/img")[i].Attributes["src"].Value;
  98. MovieBasic mb = new MovieBasic()
  99. {
  100. Title = n_title,
  101. ItemURL = n_itemURL,
  102. Img_s = s_img,
  103. Actor = actors,
  104. Maker = n_company,
  105. Label = n_ticai
  106. };
  107. l.Add(mb);
  108. }
  109. return l;
  110. //List<MovieBasic> l = new List<MovieBasic>();
  111. //for (int i = 0; i < listitems.Count; i++)
  112. //{
  113. // string title = doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div/a")[i].Attributes["title"].Value;
  114. // string itemurl = "http://" + uri.Host + doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div/a")[i].Attributes["href"].Value;
  115. // string actor = doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div[@class='data']/ul[1]/li[2]")[i].InnerText.Trim();
  116. // string marker = doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div[@class='data']/ul[2]/li[2]")[i].InnerText.Trim();
  117. // string label = doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div[@class='data']/ul[3]/li[2]")[i].InnerText.Trim();
  118. // string s_img = doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div/a/img")[i].Attributes["src"].Value;
  119. // //GetMovie(itemurl, cookies);
  120. // //GetImage(itemurl, cookies);
  121. // //http://www.arzon.jp/itemlist.html?t=&m=all&s=&q=iptd+999
  122. // MovieBasic mb = new MovieBasic()
  123. // {
  124. // Title = title,
  125. // ItemURL = itemurl,
  126. // Actor = actor,
  127. // Img_s = s_img,
  128. // Label = label,
  129. // Maker = marker
  130. // };
  131. // l.Add(mb);
  132. //}
  133. }
  134. public Movie GetMovie(MovieBasic basic)
  135. {
  136. try
  137. {
  138. string html = wc.GetHTML(new Uri(basic.ItemURL));
  139. var docc = new HtmlDocument();
  140. docc.LoadHtml(html);
  141. string Title = docc.DocumentNode.SelectSingleNode("//div[@id='detail_new']/div[@class='detail_title']/h1").InnerText.Trim();
  142. Title = Tools.RemoveInvalidChars(Title);
  143. //var ddd ="[MIDD-983]Baby Entertainment×MOODYZコラボ作品 淫神の女泥棒 哀しき痙攣の追憶 Dear.F 1 恥辱的、屈辱的なイカせの拷問! 反反复复反反复复方法";
  144. if (Title.Length>82)
  145. {
  146. Title = Title.Substring(0, 81);
  147. }
  148. //string Title = basic.Title;
  149. string label = docc.DocumentNode.SelectSingleNode("//div[@id='detail_new']/table/tr/td/table[@class='item_detail']/tr/td[@class='caption']/table[@class='item']/tr[3]/td/a").InnerText.Trim();
  150. string changjia = docc.DocumentNode.SelectSingleNode("//div[@id='detail_new']/table/tr/td/table[@class='item_detail']/tr/td[@class='caption']/table[@class='item']/tr[2]/td/a").InnerText.Trim();
  151. string jiandu = docc.DocumentNode.SelectSingleNode("//div[@id='detail_new']/table/tr/td/table[@class='item_detail']/tr/td[@class='caption']/table[@class='item']/tr[5]/td[2]").InnerText.Trim();
  152. string date = docc.DocumentNode.SelectSingleNode("//div[@id='detail_new']/table/tr/td/table[@class='item_detail']/tr/td[@class='caption']/table[@class='item']/tr[6]/td[2]").InnerText.Trim();
  153. //2008/01/25 (DVD レンタル版)
  154. System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"\d{4}/\d{2}/\d{2}");
  155. if (r.IsMatch(date))
  156. {
  157. date = r.Match(date).Value;
  158. }
  159. else
  160. {
  161. date = "1900/01/01";
  162. }
  163. DateTime dtime = DateTime.Parse(date);
  164. string minutes = docc.DocumentNode.SelectSingleNode("//div[@id='detail_new']/table/tr/td/table[@class='item_detail']/tr/td[@class='caption']/table[@class='item']/tr[7]/td[2]").InnerText.Trim();
  165. string f_code = docc.DocumentNode.SelectSingleNode("//div[@id='detail_new']/table/tr/td/table[@class='item_detail']/tr/td[@class='caption']/table[@class='item']/tr[8]/td[2]").InnerText.Trim();
  166. f_code = Tools.Fcode(f_code);
  167. string xilie = docc.DocumentNode.SelectSingleNode("//div[@id='detail_new']/table/tr/td/table[@class='item_detail']/tr/td[@class='caption']/table[@class='item']/tr[4]/td[2]").InnerText.Trim();
  168. //f_code = Tools.Fcode(f_code);
  169. string intro = docc.DocumentNode.SelectSingleNode("//table[@class='item_detail']/tr/td[@class='text']").InnerText.Trim();
  170. string coverImg = docc.DocumentNode.SelectSingleNode("//table[@class='item_detail']/tr/td/div/a").Attributes["href"].Value.Trim();
  171. Movie m = new Movie()
  172. {
  173. Actor = basic.Actor,
  174. Title = Title,
  175. Lable = label,
  176. Maker = changjia,
  177. ReleaseDate = dtime,
  178. Minutes = minutes,
  179. AVCode = f_code,
  180. Introduction = intro,
  181. CoverURL = coverImg,
  182. ItemURL = basic.ItemURL,
  183. Series = xilie,
  184. Producer = jiandu
  185. };
  186. //Console.WriteLine(string.Format("Actor:{0}\r\nTitle:{1}\r\nLabel:{2}\r\nMaker:{3}\r\nReleaseDate:{4}\r\n番号:{5}\r\n ", m.Actor[0], m.Title, m.Lable, m.Maker, m.ReleaseDate.ToShortDateString(), m.AVCode));
  187. return m;
  188. }
  189. catch (Exception)
  190. {
  191. throw new Exception("获取影片信息失败!");
  192. }
  193. }
  194. public bool GetCover(Movie mo)
  195. {
  196. wc.ReferURL = mo.ItemURL;
  197. FileInfo f = new FileInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cover", mo.AVCode + ".jpg"));
  198. try
  199. {
  200. if (!Directory.Exists(Path.GetDirectoryName(f.FullName)))
  201. {
  202. Directory.CreateDirectory(Path.GetDirectoryName(f.FullName));
  203. }
  204. if (!File.Exists(f.FullName))
  205. {
  206. wc.DownloadFile(mo.CoverURL, f.FullName);
  207. }
  208. else
  209. {
  210. Console.WriteLine("已有封面 " + mo.Title);
  211. }
  212. }
  213. catch (Exception err)
  214. {
  215. return false;
  216. }
  217. mo.CoverFile = f.FullName;
  218. return true;
  219. }
  220. Uri urlCombine(string fcode)
  221. {
  222. string ur = "http://www.arzon.jp/itemlist.html?t=&m=all&s=&mkt=all&disp=30&sort=-saledate&list=list&q=" + fcode;
  223. return new Uri(ur);
  224. }
  225. public object Clone()
  226. {
  227. //MemoryStream ms = new MemoryStream();
  228. //BinaryFormatter bf = new BinaryFormatter();
  229. //bf.Serialize(ms, this);
  230. //ms.Seek(0, 0);
  231. //object value = bf.Deserialize(ms);
  232. //ms.Close();
  233. //return value;//this.MemberwiseClone();
  234. MemoryStream ms = new MemoryStream();
  235. BinaryFormatter bf = new BinaryFormatter();
  236. bf.Serialize(ms, this.wc.m_container);
  237. ms.Seek(0, 0);
  238. object value = bf.Deserialize(ms);
  239. Arzon ar = new Arzon(false);
  240. ar.wc.m_container = value as System.Net.CookieContainer;
  241. return ar;
  242. }
  243. }
  244. }