PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/Amaze.RK Downloader/Form1.cs

https://gitlab.com/PXgamer/A.RK
C# | 479 lines | 340 code | 83 blank | 56 comment | 59 complexity | 9b7571c8f3d67cf1ac4ddc4ce5648e01 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Web.Script.Serialization;
  8. using System.Xml.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using System.Net;
  13. using System.IO;
  14. using Newtonsoft.Json;
  15. using Newtonsoft.Json.Linq;
  16. using System.Text.RegularExpressions;
  17. using System.Xml;
  18. namespace Amaze.RK_Downloader
  19. {
  20. public partial class Form1 : Form
  21. {
  22. public Form1()
  23. {
  24. InitializeComponent();
  25. }
  26. //Set Strings
  27. string title = "";
  28. string year = "";
  29. string imdb = "";
  30. string aURL = "";
  31. string tvID = "";
  32. string gbID = "";
  33. // string q720p = "";
  34. // string q1080p = "";
  35. string XMLURL = "";
  36. string XMLURL2 = "";
  37. private void Form1_Load(object sender, EventArgs e)
  38. {
  39. }
  40. private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  41. {
  42. Application.Exit();
  43. }
  44. private void button1_Click(object sender, EventArgs e)
  45. {
  46. if (radioButton1.Checked == true)
  47. {
  48. movie();
  49. }
  50. else if (radioButton2.Checked == true)
  51. {
  52. tv();
  53. }
  54. else if (radioButton4.Checked == true)
  55. {
  56. game();
  57. }
  58. }
  59. private void button2_Click(object sender, EventArgs e)
  60. {
  61. if (this.Width == 1049)
  62. {
  63. this.Width = 662;
  64. button2.Text = ">";
  65. }
  66. else
  67. {
  68. this.Width = 1049;
  69. button2.Text = "<";
  70. }
  71. }
  72. private void button4_Click(object sender, EventArgs e)
  73. {
  74. }
  75. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  76. {
  77. }
  78. private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
  79. {
  80. if (e.KeyChar == (char)Keys.Enter)
  81. {
  82. button1.PerformClick();
  83. }
  84. }
  85. private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
  86. {
  87. if (e.KeyChar == (char)Keys.Enter)
  88. {
  89. button1.PerformClick();
  90. }
  91. }
  92. private void pictureBox1_Click(object sender, EventArgs e)
  93. {
  94. System.Diagnostics.Process.Start("http://Amaze.RK/");
  95. }
  96. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  97. {
  98. if (radioButton1.Checked == true)
  99. {
  100. label1.Text = "Movie Name:";
  101. label2.Text = "Movie Year:";
  102. label3.Text = "IMDB ID:";
  103. textBox1.Enabled = true;
  104. textBox2.Enabled = true;
  105. textBox3.Enabled = true;
  106. button2.Enabled = true;
  107. button1.Text = "Search for Movie";
  108. }
  109. }
  110. private void radioButton2_CheckedChanged(object sender, EventArgs e)
  111. {
  112. if (radioButton2.Checked == true)
  113. {
  114. label1.Text = "TV Show Name:";
  115. label2.Text = "TV Show Year:";
  116. label3.Text = "TVDB ID:";
  117. label5.Text = "TVDB ID:";
  118. label6.Text = "TVRage ID:";
  119. textBox1.Enabled = true;
  120. textBox2.Enabled = false;
  121. textBox3.Enabled = true;
  122. button2.Enabled = false;
  123. this.Width = 662;
  124. button2.Text = ">";
  125. button1.Text = "Search for TV Show";
  126. }
  127. }
  128. public void movie()
  129. {
  130. //Define Strings
  131. if (textBox1.Text != "")
  132. {
  133. title = textBox1.Text;
  134. aURL = "http://omdbapi.com/?t=" + title + "&type=movie&tomatoes=true";
  135. XMLURL = "https://yts.to/rss/" + title + "/1080p/0";
  136. XMLURL2 = "https://yts.to/rss/" + title + "/720p/0";
  137. if (textBox2.Text != "")
  138. {
  139. year = textBox2.Text;
  140. aURL = "http://omdbapi.com/?t=" + title + "&y=" + year + "&type=movie&tomatoes=true";
  141. if (textBox3.Text != "")
  142. {
  143. imdb = textBox3.Text;
  144. }
  145. }
  146. }
  147. else if (textBox3.Text != "")
  148. {
  149. imdb = textBox3.Text;
  150. aURL = "http://omdbapi.com/?i=" + imdb + "&type=movie&tomatoes=true";
  151. if (textBox2.Text != "")
  152. {
  153. year = textBox2.Text;
  154. aURL = "http://omdbapi.com/?i=" + imdb + "&y=" + year + "&type=movie&tomatoes=true";
  155. }
  156. }
  157. else
  158. {
  159. MessageBox.Show("Please enter something...");
  160. }
  161. WebClient c = new WebClient();
  162. var data = c.DownloadString(aURL);
  163. //Console.WriteLine(data);
  164. JObject o = JObject.Parse(data);
  165. Genre.Text = o["Genre"].ToString();
  166. Rating.Text = o["Rated"].ToString();
  167. string aTitle = o["Title"].ToString();
  168. Title.Text = Regex.Replace(o["Title"].ToString(), @"[Â]", "") + " (" + o["Year"].ToString() + ")";
  169. IMDB.Text = o["imdbID"].ToString();
  170. Plot.Text = o["Plot"].ToString();
  171. Director.Text = o["Director"].ToString();
  172. Language.Text = o["Language"].ToString();
  173. Country.Text = o["Country"].ToString();
  174. Metascore.Text = o["Metascore"].ToString() + "/100";
  175. IMDBRating.Text = o["imdbRating"].ToString() + "/10";
  176. TomatoMeter.Text = o["tomatoMeter"].ToString() + "/100";
  177. TomatoRating.Text = o["tomatoRating"].ToString() + "/10";
  178. DVDRelease.Text = o["DVD"].ToString();
  179. /*
  180. //YTS XML to JSON
  181. WebClient d = new WebClient();
  182. var xml = d.DownloadString(XMLURL);
  183. var xml2 = d.DownloadString(XMLURL2);
  184. XmlDocument doc = new XmlDocument();
  185. doc.LoadXml(xml);
  186. string jsonText = JsonConvert.SerializeXmlNode(doc);
  187. XmlDocument doc2 = new XmlDocument();
  188. doc2.LoadXml(xml2);
  189. string jsonText2 = JsonConvert.SerializeXmlNode(doc2);
  190. //Use JSON Data 1080p
  191. JObject l = JObject.Parse(jsonText);
  192. MessageBox.Show(l.ToString());
  193. if (l.SelectToken("rss.channel.item.title").ToString() == aTitle + " (" + year + ") 1080p")
  194. {
  195. q1080p = l.SelectToken("rss.channel.item.enclosure.@url").ToString();
  196. MessageBox.Show(q1080p);
  197. }
  198. else
  199. {
  200. MessageBox.Show("Cannot find this movie in 1080p");
  201. }
  202. */
  203. //Start poster loading
  204. p.Load(o["Poster"].ToString());
  205. //create a new Bitmap with the proper dimensions
  206. Bitmap finalImg = new Bitmap(p.Image, p.Width, p.Height);
  207. //center the new image
  208. p.SizeMode = PictureBoxSizeMode.CenterImage;
  209. //set the new image
  210. p.Image = finalImg;
  211. p.Show();
  212. }
  213. public void tv()
  214. {
  215. if (textBox1.Text != "")
  216. {
  217. title = textBox1.Text;
  218. aURL = "http://api.tvmaze.com/singlesearch/shows?q=" + title;
  219. WebClient c = new WebClient();
  220. var data = c.DownloadString(aURL);
  221. JObject l = JObject.Parse(data);
  222. try
  223. {
  224. Title.Text = l["name"].ToString();
  225. Genre.Text = l["genres"][0].ToString();
  226. Plot.Text = Regex.Replace(l["summary"].ToString(), "<.*?>", string.Empty);
  227. if (l.SelectToken("externals.tvrage") != null)
  228. {
  229. IMDB.Text = l.SelectToken("externals.tvrage").ToString();
  230. }
  231. else { }
  232. if (l.SelectToken("rating.average") != null)
  233. {
  234. Rating.Text = l.SelectToken("externals.thetvdb").ToString();
  235. }
  236. else { }
  237. string poster = l.SelectToken("image.original").ToString();
  238. //Start poster loading
  239. p.Load(poster);
  240. //create a new Bitmap with the proper dimensions
  241. Bitmap finalImg = new Bitmap(p.Image, p.Width, p.Height);
  242. //center the new image
  243. p.SizeMode = PictureBoxSizeMode.CenterImage;
  244. //set the new image
  245. p.Image = finalImg;
  246. p.Show();
  247. }
  248. catch
  249. {
  250. Console.WriteLine("Sorry. This TV show could not be found!");
  251. }
  252. }
  253. else if (textBox3.Text != "")
  254. {
  255. tvID = textBox3.Text;
  256. aURL = "http://api.tvmaze.com/lookup/shows?thetvdb=" + tvID;
  257. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(aURL);
  258. HttpWebResponse myResp = (HttpWebResponse)req.GetResponse();
  259. aURL = myResp.ResponseUri.ToString();
  260. WebClient c = new WebClient();
  261. var data = c.DownloadString(aURL);
  262. JObject l = JObject.Parse(data);
  263. try
  264. {
  265. Title.Text = l["name"].ToString();
  266. Genre.Text = l["genres"][0].ToString();
  267. Plot.Text = Regex.Replace(l["summary"].ToString(), "<.*?>", string.Empty);
  268. if (l.SelectToken("externals.tvrage") != null)
  269. {
  270. IMDB.Text = l.SelectToken("externals.tvrage").ToString();
  271. }
  272. else { }
  273. if (l.SelectToken("rating.average") != null)
  274. {
  275. Rating.Text = l.SelectToken("externals.thetvdb").ToString();
  276. }
  277. else { }
  278. string poster = l.SelectToken("image.original").ToString();
  279. //Start poster loading
  280. p.Load(poster);
  281. //create a new Bitmap with the proper dimensions
  282. Bitmap finalImg = new Bitmap(p.Image, p.Width, p.Height);
  283. //center the new image
  284. p.SizeMode = PictureBoxSizeMode.CenterImage;
  285. //set the new image
  286. p.Image = finalImg;
  287. p.Show();
  288. }
  289. catch
  290. {
  291. Console.WriteLine("Sorry. This TV show could not be found!");
  292. }
  293. }
  294. }
  295. private void pictureBox2_Click(object sender, EventArgs e)
  296. {
  297. About abt = new About();
  298. abt.Show();
  299. }
  300. private void radioButton4_CheckedChanged(object sender, EventArgs e)
  301. {
  302. if (radioButton4.Checked == true)
  303. {
  304. label1.Text = "Game Name:";
  305. label2.Text = "Game Year:";
  306. label3.Text = "GiantBomb ID:";
  307. label5.Text = "GiantBomb ID:";
  308. label6.Text = "";
  309. label7.Text = "Age Rating:";
  310. textBox1.Enabled = true;
  311. textBox2.Enabled = false;
  312. textBox3.Enabled = true;
  313. button2.Enabled = false;
  314. this.Width = 662;
  315. button2.Text = ">";
  316. button1.Text = "Search for Game";
  317. }
  318. }
  319. public void game()
  320. {
  321. if (textBox1.Text != "")
  322. {
  323. title = textBox1.Text;
  324. aURL = "http://www.giantbomb.com/api/search/?api_key=a01f1e8993d3aad94887ac0f137672acb1cf224d&format=json&query=%22" + title + "%22&resources=game";
  325. WebClient d = new WebClient();
  326. var data = d.DownloadString(aURL);
  327. JObject l = JObject.Parse(data);
  328. try
  329. {
  330. Title.Text = l.SelectToken("results[0].name").ToString();
  331. Genre.Text = l.SelectToken("results[0].original_game_rating[0].name").ToString();
  332. Plot.Text = Regex.Replace(l.SelectToken("results[0].deck").ToString(), "<.*?>", string.Empty);
  333. if (l.SelectToken("results[0].id") != null)
  334. {
  335. IMDB.Text = l.SelectToken("results[0].id").ToString();
  336. }
  337. else { }
  338. string poster = Regex.Unescape(l.SelectToken("results[0].image.super_url").ToString());
  339. //Start poster loading
  340. p.Load(poster);
  341. //create a new Bitmap with the proper dimensions
  342. Bitmap finalImg = new Bitmap(p.Image, p.Width, p.Height);
  343. //center the new image
  344. p.SizeMode = PictureBoxSizeMode.CenterImage;
  345. //set the new image
  346. p.Image = finalImg;
  347. p.Show();
  348. }
  349. catch
  350. {
  351. Console.WriteLine("Sorry. This game could not be found!");
  352. }
  353. }
  354. else if (textBox3.Text != "")
  355. {
  356. gbID = textBox3.Text;
  357. aURL = "http://www.giantbomb.com/api/game/3030-" + gbID + "/?api_key=a01f1e8993d3aad94887ac0f137672acb1cf224d&format=json";
  358. WebClient d = new WebClient();
  359. var data = d.DownloadString(aURL);
  360. JObject l = JObject.Parse(data);
  361. try
  362. {
  363. Title.Text = l.SelectToken("results.name").ToString();
  364. Genre.Text = l.SelectToken("results.original_game_rating[0].name").ToString();
  365. Plot.Text = Regex.Replace(l.SelectToken("results.deck").ToString(), "<.*?>", string.Empty);
  366. if (l.SelectToken("results.id") != null)
  367. {
  368. IMDB.Text = l.SelectToken("results.id").ToString();
  369. }
  370. else { }
  371. string poster = Regex.Unescape(l.SelectToken("results.image.super_url").ToString());
  372. //Start poster loading
  373. p.Load(poster);
  374. //create a new Bitmap with the proper dimensions
  375. Bitmap finalImg = new Bitmap(p.Image, p.Width, p.Height);
  376. //center the new image
  377. p.SizeMode = PictureBoxSizeMode.CenterImage;
  378. //set the new image
  379. p.Image = finalImg;
  380. p.Show();
  381. }
  382. catch
  383. {
  384. Console.WriteLine("Sorry. This game could not be found!");
  385. }
  386. }
  387. }
  388. }
  389. }