PageRenderTime 20ms CodeModel.GetById 2ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 1ms

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