Как сделать Downloader YouTube

Lomanu4 Оффлайн

Lomanu4

Команда форума
Администратор
1 Мар 2015
1,072
276
155
VK
#1
C#:
new pastetrends 


Untitled
 A GUEST   MAR 1ST, 2017   928  NEVER

Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
rawdownloadreport 2.78 KB
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using YoutubeExtractor;
using System.IO;
 
namespace YoutubeDown
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("Http://www.youtube.com");
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            if (webBrowser1.CanGoBack)
            {
                webBrowser1.GoBack();
            }
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            if (webBrowser1.CanGoForward)
            {
                webBrowser1.GoForward();
            }
        }
 
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button3.PerformClick();
            }
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate(textBox1.Text);
        }
 
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            textBox1.Text = webBrowser1.Url.AbsoluteUri;
        }
 
        private void button4_Click(object sender, EventArgs e)
        {
            IEnumerable<VideoInfo> videos = DownloadUrlResolver.GetDownloadUrls(textBox1.Text);
            VideoInfo video = videos.First(p => p.VideoType == VideoType.Mp4 && p.Resolution == Convert.ToInt32(480));
            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }
            VideoDownloader downloader = new VideoDownloader(video, Path.Combine("C:\\Users\\" + Environment.UserName + "\\Downloads\\", video.Title + video.VideoExtension));
            downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged;
            Thread thread = new Thread(() => { downloader.Execute(); }) { IsBackground = true };
            thread.Start();
        }
 
        private void Downloader_DownloadProgressChanged(object sender, ProgressEventArgs e)
        {
            Invoke(new MethodInvoker(delegate ()
            {
                toolStripStatusLabel1.Text = $"Downloading: {string.Format("{0:0.##}", e.ProgressPercentage)}%";
                if (toolStripStatusLabel1.Text == "Downloading: 100%")
                {
                    toolStripStatusLabel1.Text = "";
                }
            }));
        }
    }
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using YoutubeExtractor;
using System.IO;

namespace YoutubeDown
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("

Please Login or Register to view hidden text.

");
}

private void button1_Click(object sender, EventArgs e)
{
if (webBrowser1.CanGoBack)
{
webBrowser1.GoBack();
}
}

private void button2_Click(object sender, EventArgs e)
{
if (webBrowser1.CanGoForward)
{
webBrowser1.GoForward();
}
}

private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
button3.PerformClick();
}
}

private void button3_Click(object sender, EventArgs e)
{
webBrowser1.Navigate(textBox1.Text);
}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
textBox1.Text = webBrowser1.Url.AbsoluteUri;
}

private void button4_Click(object sender, EventArgs e)
{
IEnumerable<VideoInfo> videos = DownloadUrlResolver.GetDownloadUrls(textBox1.Text);
VideoInfo video = videos.First(p => p.VideoType == VideoType.Mp4 && p.Resolution == Convert.ToInt32(480));
if (video.RequiresDecryption)
{
DownloadUrlResolver.DecryptDownloadUrl(video);
}
VideoDownloader downloader = new VideoDownloader(video, Path.Combine("C:\\Users\\" + Environment.UserName + "\\Downloads\\", video.Title + video.VideoExtension));
downloader.DownloadProgressChanged += Downloader_DownloadProgressChanged;
Thread thread = new Thread(() => { downloader.Execute(); }) { IsBackground = true };
thread.Start();
}

private void Downloader_DownloadProgressChanged(object sender, ProgressEventArgs e)
{
Invoke(new MethodInvoker(delegate ()
{
toolStripStatusLabel1.Text = $"Downloading: {string.Format("{0:0.##}", e.ProgressPercentage)}%";
if (toolStripStatusLabel1.Text == "Downloading: 100%")
{
toolStripStatusLabel1.Text = "";
}
}));
}
}
}