Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Comments
- // The program was coded by Andrew J S.
- // The program is NOT meant to steal music off youtube, was just a personal experiment.
- // The video function was removed due to the other website is now experiencing problems and un reliable.
- // 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
- {
- int seconds = 10;
- string folderPath = "C:\\YouTubeCloud";
- string audioPath = "C:\\YouTubeCloud\\Audio";
- void directoryCheck()
- {
- try
- {
- if (!Directory.Exists(folderPath)) // Check if the directory (folder) does not exist.
- {
- Directory.CreateDirectory(folderPath);
- Directory.CreateDirectory(audioPath);
- }
- }
- catch { }
- }
- void downloadFile()
- {
- 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(downloadComplete);
- webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgress);
- webClient.DownloadFileAsync(new Uri(downloadUrl), audioPath + "\\" + songName + ".mp3");
- }
- catch { }
- }
- private void downloadProgress(object sender, DownloadProgressChangedEventArgs e)
- {
- progressBar1.Value = e.ProgressPercentage; // Progress bar value is the same as the percentage of the download
- }
- private void downloadComplete(object sender, AsyncCompletedEventArgs e)
- {
- textBox1.Clear();
- textBox1.Enabled = true;
- button1.Enabled = true;
- progressBar1.Value = 0;
- }
- public Form1()
- {
- InitializeComponent();
- directoryCheck(); // Call the function.
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- Process.Start(folderPath); // Open the folder so the user knows where it is located. This line is NOT NEEDED and is just a reminder to the user every time they open the program.
- }
- private void button1_Click(object sender, EventArgs e)
- {
- directoryCheck(); // Call the function.
- 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 Form1_FormClosed(object sender, FormClosedEventArgs e)
- {
- MessageBox.Show("Program created by : Andrew");
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- seconds--;
- if (seconds == 0)
- {
- timer1.Stop();
- seconds = 10;
- downloadFile();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment