Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Program.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Forms;
- namespace YouTubeCloud
- {
- static class Program
- {
- private static Form1 form1;
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- form1 = new Form1();
- Application.Run(form1);
- }
- public static Form1 MainForm
- {
- get { return form1; }
- }
- }
- }
- // Form1.cs
- // Comments
- // The program was coded by Andrew S.
- // The program is NOT meant to steal music off youtube, it was merely an experiment with HTML and c# coding.
- // Thanks to youtube-mp3.org as without them this program would not exist.
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- using System.IO;
- using System.Net;
- namespace YouTubeCloud
- {
- public partial class Form1 : Form
- {
- directoryLogic directory = new directoryLogic();
- downloadLogic download = new downloadLogic();
- int ticks = 15;
- public Form1()
- {
- InitializeComponent();
- directory.Check();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void Form1_FormClosed(object sender, FormClosedEventArgs e)
- {
- MessageBox.Show("The program was created by : Andrew S");
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (textBox1.Text.Trim().Length != 0) // Determine whether the textbox is empty.
- {
- webBrowser1.Document.GetElementById("youtube-url").SetAttribute("value", textBox1.Text); // Put text into textbox.
- webBrowser1.Document.GetElementById("submit").InvokeMember("onclick"); // Click button.
- textBox1.Enabled = false;
- button1.Enabled = false;
- timer1.Start();
- }
- }
- private void button2_Click(object sender, EventArgs e)
- {
- try
- {
- Process.Start("C:\\YouTubeCloud");
- }
- catch (InvalidOperationException)
- {
- directory.Check();
- }
- finally { }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- ticks--;
- if (ticks == 0)
- {
- timer1.Stop();
- ticks = 15;
- download.Start(webBrowser1);
- }
- }
- }
- }
- // directoryLogic.cs
- using System;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Collections.Generic;
- namespace YouTubeCloud
- {
- class directoryLogic
- {
- public void Check()
- {
- try
- {
- if (!Directory.Exists("C:\\YouTubeCloud"))
- {
- Directory.CreateDirectory("C:\\YouTubeCloud");
- }
- }
- catch (Exception e)
- {
- MessageBox.Show("The CreateDirectory failed: {0}", e.ToString());
- }
- finally { }
- }
- }
- }
- // downloadLogic.cs
- using System;
- using System.Net;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.ComponentModel;
- using System.Collections.Generic;
- namespace YouTubeCloud
- {
- class downloadLogic
- {
- public void Start(System.Windows.Forms.WebBrowser webBrowser1)
- {
- try
- {
- HtmlElement dl_link = webBrowser1.Document.GetElementById("dl_link").All[0]; // Get all the information under the id 'dl_link'.
- string downloadUrl = dl_link.GetAttribute("href"); // Grab the link which is located in 'href' under dl_link.
- string songName = webBrowser1.Document.GetElementById("title").InnerText.Substring(7); // Get the title in the element title and remove the text 'Title: '.
- WebClient webClient = new WebClient(); // Used to remove dialog of saving a file
- webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Complete);
- webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(Progress);
- webClient.DownloadFileAsync(new Uri(downloadUrl), "C:\\YouTubeCloud\\" + songName + ".mp3");
- }
- catch (WebException e)
- {
- MessageBox.Show("There was an error with the download: " + e.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
- }
- finally { }
- }
- public void Progress(object sender, DownloadProgressChangedEventArgs e)
- {
- 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
- }
- public void Complete(object sender, AsyncCompletedEventArgs e)
- {
- Program.MainForm.textBox1.Clear(); // The control is INTERNEL under modifiers
- Program.MainForm.textBox1.Enabled = true; // The control is INTERNEL under modifiers
- Program.MainForm.button1.Enabled = true; // The control is INTERNEL under modifiers
- Program.MainForm.progressBar1.Value = 0; // The control is INTERNEL under modifiers
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment