Shrooms

YouTubeCloud *NEW*

Sep 12th, 2012
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.83 KB | None | 0 0
  1. // Program.cs
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Windows.Forms;
  7.  
  8. namespace YouTubeCloud
  9. {
  10.     static class Program
  11.     {
  12.         private static Form1 form1;
  13.  
  14.         /// <summary>
  15.         /// The main entry point for the application.
  16.         /// </summary>
  17.         [STAThread]
  18.         static void Main()
  19.         {
  20.             Application.EnableVisualStyles();
  21.             Application.SetCompatibleTextRenderingDefault(false);
  22.             form1 = new Form1();
  23.             Application.Run(form1);
  24.         }
  25.        
  26.         public static Form1 MainForm
  27.         {
  28.             get { return form1; }
  29.         }
  30.     }
  31. }
  32.  
  33. // Form1.cs
  34.  
  35. // Comments
  36.  
  37. // The program was coded by Andrew S.
  38.  
  39. // The program is NOT meant to steal music off youtube, it was merely an experiment with HTML and c# coding.
  40.  
  41. // Thanks to youtube-mp3.org as without them this program would not exist.
  42.  
  43. using System;
  44. using System.Collections.Generic;
  45. using System.ComponentModel;
  46. using System.Data;
  47. using System.Drawing;
  48. using System.Linq;
  49. using System.Text;
  50. using System.Windows.Forms;
  51. using System.Runtime.InteropServices;
  52. using System.Diagnostics;
  53. using System.IO;
  54. using System.Net;
  55.  
  56. namespace YouTubeCloud
  57. {
  58.     public partial class Form1 : Form
  59.     {
  60.         directoryLogic directory = new directoryLogic();
  61.         downloadLogic download = new downloadLogic();
  62.  
  63.         int ticks = 15;
  64.  
  65.         public Form1()
  66.         {
  67.             InitializeComponent();
  68.             directory.Check();
  69.         }
  70.  
  71.         private void Form1_Load(object sender, EventArgs e)
  72.         {
  73.  
  74.         }
  75.  
  76.         private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  77.         {
  78.             MessageBox.Show("The program was created by : Andrew S");
  79.         }
  80.  
  81.         private void button1_Click(object sender, EventArgs e)
  82.         {
  83.             if (textBox1.Text.Trim().Length != 0) // Determine whether the textbox is empty.
  84.             {
  85.                 webBrowser1.Document.GetElementById("youtube-url").SetAttribute("value", textBox1.Text); // Put text into textbox.
  86.                 webBrowser1.Document.GetElementById("submit").InvokeMember("onclick"); // Click button.
  87.  
  88.                 textBox1.Enabled = false;
  89.                 button1.Enabled = false;
  90.  
  91.                 timer1.Start();
  92.             }
  93.         }
  94.  
  95.         private void button2_Click(object sender, EventArgs e)
  96.         {
  97.             try
  98.             {
  99.                 Process.Start("C:\\YouTubeCloud");
  100.             }
  101.             catch (InvalidOperationException)
  102.             {
  103.                 directory.Check();
  104.             }
  105.             finally { }
  106.         }
  107.  
  108.         private void timer1_Tick(object sender, EventArgs e)
  109.         {
  110.             ticks--;
  111.  
  112.             if (ticks == 0)
  113.             {
  114.                 timer1.Stop();
  115.                 ticks = 15;
  116.                 download.Start(webBrowser1);
  117.             }
  118.         }
  119.     }
  120. }
  121.  
  122. // directoryLogic.cs
  123.  
  124. using System;
  125. using System.IO;
  126. using System.Linq;
  127. using System.Text;
  128. using System.Windows.Forms;
  129. using System.Collections.Generic;
  130.  
  131. namespace YouTubeCloud
  132. {
  133.     class directoryLogic
  134.     {
  135.         public void Check()
  136.         {
  137.             try
  138.             {
  139.                 if (!Directory.Exists("C:\\YouTubeCloud"))
  140.                 {
  141.                     Directory.CreateDirectory("C:\\YouTubeCloud");
  142.                 }
  143.             }
  144.             catch (Exception e)
  145.             {
  146.                 MessageBox.Show("The CreateDirectory failed: {0}", e.ToString());
  147.             }
  148.             finally { }
  149.         }
  150.     }
  151. }
  152.  
  153. // downloadLogic.cs
  154.  
  155. using System;
  156. using System.Net;
  157. using System.Linq;
  158. using System.Text;
  159. using System.Windows.Forms;
  160. using System.ComponentModel;
  161. using System.Collections.Generic;
  162.  
  163. namespace YouTubeCloud
  164. {
  165.     class downloadLogic
  166.     {
  167.         public void Start(System.Windows.Forms.WebBrowser webBrowser1)
  168.         {
  169.             try
  170.             {
  171.                 HtmlElement dl_link = webBrowser1.Document.GetElementById("dl_link").All[0]; // Get all the information under the id 'dl_link'.
  172.  
  173.                 string downloadUrl = dl_link.GetAttribute("href"); // Grab the link which is located in 'href' under dl_link.
  174.                 string songName = webBrowser1.Document.GetElementById("title").InnerText.Substring(7); // Get the title in the element title and remove the text 'Title: '.
  175.  
  176.                 WebClient webClient = new WebClient(); // Used to remove dialog of saving a file
  177.                 webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Complete);
  178.                 webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Progress);
  179.                 webClient.DownloadFileAsync(new Uri(downloadUrl), "C:\\YouTubeCloud\\" + songName + ".mp3");
  180.             }
  181.             catch (WebException e)
  182.             {
  183.                 MessageBox.Show("There was an error with the download: " + e.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  184.             }
  185.             finally { }
  186.         }
  187.  
  188.         public void Progress(object sender, DownloadProgressChangedEventArgs e)
  189.         {
  190.            Program.MainForm.progressBar1.Value = e.ProgressPercentage; // Progress bar value is the same as the percentage of the download and the control is INTERNEL under modifiers
  191.         }
  192.  
  193.         public void Complete(object sender, AsyncCompletedEventArgs e)
  194.         {
  195.             Program.MainForm.textBox1.Clear(); // The control is INTERNEL under modifiers
  196.             Program.MainForm.textBox1.Enabled = true; // The control is INTERNEL under modifiers
  197.             Program.MainForm.button1.Enabled = true; // The control is INTERNEL under modifiers
  198.             Program.MainForm.progressBar1.Value = 0; // The control is INTERNEL under modifiers
  199.         }
  200.     }
  201. }
Advertisement
Add Comment
Please, Sign In to add comment