Esempio n. 1
0
        static string VideoDownload(string url)
        {
            var youtubeDl = new YoutubeDL();

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                youtubeDl.YoutubeDlPath = "./tools/youtube-dl.exe";
            }
            else
            {
                youtubeDl.YoutubeDlPath = "./tools/youtube-dl";
            }
            string filename = url.Split("/")[url.Split("/").Length - 2] + ".mp4";

            youtubeDl.Options.FilesystemOptions.Output = filename;
            youtubeDl.VideoUrl = "https://reddit.com" + url;
            Console.WriteLine("https://reddit.com" + url);
            youtubeDl.StandardOutputEvent += (sender, output) => Console.WriteLine(output);
            youtubeDl.StandardErrorEvent  += (sender, errorOutput) => Console.WriteLine(errorOutput);
            string commandToRun = youtubeDl.PrepareDownload();

            youtubeDl.Download();
            youtubeDl = null;
            return(filename);
        }
Esempio n. 2
0
        static async Task GetAudio(string location, string fileName)

        {
            var yt = new YoutubeDL();

            yt.Options.FilesystemOptions.Output           = $@"e:\test\{fileName}";
            yt.Options.PostProcessingOptions.ExtractAudio = true;
            yt.Options.PostProcessingOptions.AudioFormat  = Enums.AudioFormat.mp3;
            yt.VideoUrl = location;
            yt.Options.GeneralOptions.Update = true;
            yt.YoutubeDlPath = $@"e:\test\youtube-dl.exe";


            yt.StandardOutputEvent += (sender, output) => Console.WriteLine(output);
            yt.StandardErrorEvent  += (sender, errorOutput) => Console.WriteLine(errorOutput);



            //  string commandToRun = await yt.PrepareDownloadAsync();
            // Alternatively
            string commandToRun = yt.PrepareDownload();

            // Just let it run
            await yt.DownloadAsync();

            // Wait for it
            //    yt.Download();
        }
Esempio n. 3
0
        public void TestIntOption()
        {
            YoutubeDL    ydlClient = new YoutubeDL();
            const string socketTimeoutIntOption = " --socket-timeout 5 ";

            ydlClient.Options.NetworkOptions.SocketTimeout = 5;

            Assert.Contains(socketTimeoutIntOption, ydlClient.PrepareDownload());
        }
Esempio n. 4
0
        public async Task PlayLocal(params string[] search)
        {
            int querypages = 1;

            var items   = new VideoSearch();
            var message = await Context.Channel.SendMessageAsync("Searching...");

            var urls      = items.SearchQuery(string.Join(" ", search), querypages);
            var duration  = urls.First().Duration;
            var thumbnail = urls.First().Thumbnail;

            await message.ModifyAsync(msg => msg.Content = "Downloading " + urls.First().Title + "...");

            var urlToDownload   = urls.First().Url;
            var newFilename     = Guid.NewGuid().ToString();
            var mp3OutputFolder = Environment.CurrentDirectory + "/songs/";
            var downloader      = new YoutubeDL();

            downloader.VideoUrl      = urlToDownload;
            downloader.YoutubeDlPath = @"C:\Users\thoma\source\repos\CoolDiscordBot\CoolDiscordBot\bin\Debug\youtube-dl.exe";
            downloader.Options.FilesystemOptions.Output = Environment.CurrentDirectory + "/songs/" + newFilename;
            downloader.PrepareDownload();
            downloader.Download();
            var info = downloader.GetDownloadInfo();

            while (downloader.ProcessRunning == true)
            {
                await Task.Delay(50);
            }

            EmbedBuilder builder = new EmbedBuilder();

            builder.Title = Context.User.Username + "#" + Context.User.Discriminator;
            builder.AddField("Name", info.Title);
            builder.ThumbnailUrl = thumbnail;
            builder.AddField("Duration", duration);
            builder.AddField("Url", urlToDownload);


            await ReplyAsync("t", false, builder.Build());

            audioModule = new audiomodule();
            var voiceChannel = ((IVoiceState)Context.User).VoiceChannel;

            if (voiceChannel is null)
            {
                await ReplyAsync($"{Context.User.Mention} you are not in a voice channel!");

                return;
            }
            var audioClient = await voiceChannel.ConnectAsync().ConfigureAwait(false);

            Console.WriteLine(newFilename);
            string path = "\"" + Environment.CurrentDirectory + "/songs/" + newFilename + ".mkv" + "\"";

            await audioModule.PlayLocalMusic(path, audioClient);
        }
Esempio n. 5
0
        public void TestEnumOption()
        {
            YoutubeDL    ydlClient             = new YoutubeDL();
            const string audioFormatEnumOption = " --audio-format mp3 ";

            ydlClient.Options.PostProcessingOptions.AudioFormat = Enums.AudioFormat.mp3;

            Assert.Contains(audioFormatEnumOption, ydlClient.PrepareDownload());
        }
Esempio n. 6
0
        public void TestFileSizeRateOption2()
        {
            YoutubeDL    ydlClient = new YoutubeDL();
            const string bufferSizeFileSizeRateOption = " --buffer-size 5.5M ";

            ydlClient.Options.DownloadOptions.BufferSize = new FileSizeRate("5.5M");

            Assert.Contains(bufferSizeFileSizeRateOption, ydlClient.PrepareDownload());
        }
Esempio n. 7
0
        public void TestBoolOption()
        {
            YoutubeDL    ydlClient = new YoutubeDL();
            const string extractAudioOptionString = " -x ";

            ydlClient.Options.PostProcessingOptions.ExtractAudio = true;

            Assert.Contains(extractAudioOptionString, ydlClient.PrepareDownload());
        }
Esempio n. 8
0
        public void TestDateTimeOption()
        {
            YoutubeDL    ydlClient          = new YoutubeDL();
            const string dateDateTimeOption = " --date 20170201 ";

            ydlClient.Options.VideoSelectionOptions.Date = new DateTime(2017, 02, 01);

            Assert.Contains(dateDateTimeOption, ydlClient.PrepareDownload());
        }
Esempio n. 9
0
        public void TestStringOption()
        {
            YoutubeDL    ydlClient            = new YoutubeDL();
            const string usernameStringOption = " -u testUser ";

            ydlClient.Options.AuthenticationOptions.Username = "******";

            Assert.Contains(usernameStringOption, ydlClient.PrepareDownload());
        }
Esempio n. 10
0
        public void TestStringOptionWithWhiteSpace()
        {
            YoutubeDL    ydlClient            = new YoutubeDL();
            const string ffmpegLocationOption = " --ffmpeg-location \"test location\" ";

            ydlClient.Options.PostProcessingOptions.FfmpegLocation = "test location";

            Assert.Contains(ffmpegLocationOption, ydlClient.PrepareDownload());
        }
Esempio n. 11
0
        public void TestIntOptionNegativeIsInfinite()
        {
            YoutubeDL    ydlClient        = new YoutubeDL();
            const string retriesIntOption = " -R infinite ";

            ydlClient.Options.DownloadOptions.Retries = -1;

            Assert.Contains(retriesIntOption, ydlClient.PrepareDownload());
        }
Esempio n. 12
0
        public void TestFileSizeRateOption1()
        {
            YoutubeDL    ydlClient = new YoutubeDL();
            const string bufferSizeFileSizeRateOption = " --buffer-size 5.5M ";

            ydlClient.Options.DownloadOptions.BufferSize = new FileSizeRate(5.5, Enums.ByteUnit.M);

            Assert.True(ydlClient.PrepareDownload().Contains(bufferSizeFileSizeRateOption));
        }
Esempio n. 13
0
        public async void ProcessQueue()
        {
            processingQueue = true;
            Parallel.ForEach(Queue, async item =>
                             //foreach (var item in Queue)
            {
                if (item.Status == "Queued")
                {
                    var fileName = item.Title + ".mp4";
                    var location = item.Url;

                    var items = new List <string>();

                    var yt = new YoutubeDL();
                    yt.Options.FilesystemOptions.Output           = $@"e:\test\{fileName}";
                    yt.Options.PostProcessingOptions.ExtractAudio = true;
                    yt.Options.PostProcessingOptions.AudioFormat  = Enums.AudioFormat.mp3;
                    yt.VideoUrl = location;
                    yt.Options.GeneralOptions.Update = true;
                    yt.YoutubeDlPath        = $@"e:\test\youtube-dl.exe";
                    yt.StandardOutputEvent += (sender, output) =>
                    {
                        Console.WriteLine(output);
                        ConsoleText = output;
                        items.Add(output);

                        var pct = item.Percent;

                        if (output.Contains("[download]") && output.Contains('%'))
                        {
                            var s        = output.IndexOf('%');
                            var num      = output.Substring(10, s - 10);
                            var numc     = num.Trim();
                            pct          = Decimal.Parse(numc);
                            item.Percent = pct;
                            item.Status  = "Downloading";
                        }

                        if (item.Percent == 100)
                        {
                            item.Status = "Processing";
                        }

                        if (output.StartsWith("Deleting"))
                        {
                            item.Status = "Done";
                        }
                    };
                    yt.StandardErrorEvent += (sender, errorOutput) => Console.WriteLine(errorOutput);
                    string commandToRun    = yt.PrepareDownload();
                    await yt.DownloadAsync();
                }
            });

            processingQueue = false;
        }
Esempio n. 14
0
        static void VideoDownload(string url)
        {
            var youtubeDl = new YoutubeDL();

            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                youtubeDl.YoutubeDlPath = "./tools/youtube-dl.exe";
            }
            else
            {
                youtubeDl.YoutubeDlPath = "./tools/youtube-dl";
            }

            youtubeDl.Options.FilesystemOptions.Output = "./video.mp4";
            youtubeDl.VideoUrl = "https://reddit.com" + url;
            Console.WriteLine("https://reddit.com" + url);
            youtubeDl.StandardOutputEvent += (sender, output) => Console.WriteLine(output);
            youtubeDl.StandardErrorEvent  += (sender, errorOutput) => Console.WriteLine(errorOutput);
            string commandToRun = youtubeDl.PrepareDownload();

            youtubeDl.Download();
            youtubeDl = null;
        }
Esempio n. 15
0
        private void UiDownloadButton_Click(object sender, EventArgs e)
        {
            string url = uiUrlTextBox.Text;

            if (String.IsNullOrWhiteSpace(url))
            {
                MessageBox.Show("Please enter a video URL", "No URL Entered", MessageBoxButtons.OK, MessageBoxIcon.Error);
                uiUrlTextBox.Focus();
                return;
            }

            uiDownloadButton.Enabled = false;
            string videoLocation = Path.Combine(Constants.VideoCacheLocation, "temp_video_download.mp4");

            this.InvokeIfRequired(() => uiStatusLabel.Text = "Starting download... Please wait as this can take a few seconds to start.");

            try
            {
                youtubeDl = new YoutubeDL
                {
                    YoutubeDlPath = "youtube-dl.exe",
                    VideoUrl      = url,
                };
                youtubeDl.Options.FilesystemOptions.Output    = videoLocation;
                youtubeDl.Options.GeneralOptions.IgnoreErrors = true;
                youtubeDl.PrepareDownload();

                youtubeDl.Info.PropertyChanged += (o, args) =>
                {
                    DownloadInfo info   = (DownloadInfo)o;
                    string       status = info.Status;
                    this.InvokeIfRequired(() => uiDownloadProgressBar.Value = info.VideoProgress);
                    this.InvokeIfRequired(() => uiStatusLabel.Text          = $"Status: {status} Video size: {info.VideoSize} Download speed: {info.DownloadRate} ETA: {info.Eta}");

                    if (status == "Error")
                    {
                        this.InvokeIfRequired(() => uiStatusLabel.Text       = "Error downloading video.");
                        this.InvokeIfRequired(() => uiDownloadButton.Enabled = true);
                        youtubeDl.KillProcess();
                    }

                    if (status == "Done" || info.VideoProgress == 100)
                    {
                        this.InvokeIfRequired(() => uiDownloadButton.Enabled = true);
                        this.InvokeIfRequired(() => uiStatusLabel.Text       = "Status: Download complete. Processing video.");
                        if (!hasFired) //this can fire multiple times, so stop it from happening with flag. Need to reset after download completed!
                        {
                            hasFired = true;
                            youtubeDl.KillProcess();
                            VideoDownloadComplete?.Invoke(this, EventArgs.Empty);
                            this.InvokeIfRequired(() => Close());
                        }
                    }
                };
                youtubeDl.DownloadAsync();
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("An error has occured attempting to download this video.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }