Пример #1
0
        private static void DownloadAudio(IEnumerable<VideoInfo> videoInfos)
        {
            /*
             * We want the first flash (only flash audio extraction is currently supported)
             * video with the highest audio quality.
             * See the VideoFormat enum for more info about the quality.
             */
            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .First(info =>
                       info.VideoFormat == VideoFormat.FlashAacHighQuality ||
                       info.VideoFormat == VideoFormat.FlashAacLowQuality ||
                       info.VideoFormat == VideoFormat.FlashMp3HighQuality ||
                       info.VideoFormat == VideoFormat.FlashMp3LowQuality);

            /*
             * Create the audio downloader.
             * The first argument is the video where the audio should be extracted from.
             * The second argument is the path to save the audio file.
             */
            var audioDownloader = new AudioDownloader(video, Path.Combine("D:/Downloads", video.Title + video.AudioExtension));

            // Register the ProgressChanged event and print the current progress
            audioDownloader.ProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage);

            /*
             * Execute the audio downloader.
             * For GUI applications note, that this method runs synchronously.
             */
            audioDownloader.Execute();
        }
Пример #2
0
        private static void DownloadAudio(IEnumerable<VideoInfo> videoInfos)
        {
            /*
             * We want the first extractable video with the highest audio quality.
             */
            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();

            /*
             * Create the audio downloader.
             * The first argument is the video where the audio should be extracted from.
             * The second argument is the path to save the audio file.
             */

            var audioDownloader = new AudioDownloader(video,
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), video.Title + video.AudioExtension));

            // Register the progress events. We treat the download progress as 85% of the progress and the extraction progress only as 15% of the progress,
            // because the download will take much longer than the audio extraction.
            audioDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage * 0.85);
            audioDownloader.AudioExtractionProgressChanged += (sender, args) => Console.WriteLine(85 + args.ProgressPercentage * 0.15);

            /*
             * Execute the audio downloader.
             * For GUI applications note, that this method runs synchronously.
             */
            audioDownloader.Execute();
        }
Пример #3
0
        private static void DownloadAudio(IEnumerable<VideoInfo> videoInfos)
        {
            /*
             * We want the first extractable video with the highest audio quality.
             */
            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();

            /*
             * Create the audio downloader.
             * The first argument is the video where the audio should be extracted from.
             * The second argument is the path to save the audio file.
             */
            var audioDownloader = new AudioDownloader(video, Path.Combine("D:/Downloads", video.Title + video.AudioExtension));

            // Register the ProgressChanged event and print the current progress
            audioDownloader.ProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage);

            /*
             * Execute the audio downloader.
             * For GUI applications note, that this method runs synchronously.
             */
            audioDownloader.Execute();
        }
Пример #4
0
        public static async Task DownloadAudioAsync(VideoInfo videoInfo, string downloadPath, IObserver<double> progress)
        {
            string cleanedTitle = RemoveIllegalPathCharacters(videoInfo.Title);
            var downloader = new AudioDownloader(videoInfo, Path.Combine(downloadPath, cleanedTitle + videoInfo.AudioExtension));

            downloader.DownloadProgressChanged += (sender, args) => progress.OnNext(args.ProgressPercentage * 0.95);
            downloader.AudioExtractionProgressChanged += (sender, args) => progress.OnNext(95 + args.ProgressPercentage * 0.05);

            await DownloadFromYoutube(downloader, new[] { typeof(IOException), typeof(WebException), typeof(AudioExtractionException) }, progress);
        }
        private void DownloadAudio()
        {
            if(VideoInfo.RequiresDecryption) {
                DownloadUrlResolver.DecryptDownloadUrl(VideoInfo);
            }

            AudioDownloader audioDownloader = new AudioDownloader(VideoInfo, Path.Combine("D:/Downloads", VideoInfo.Title + VideoInfo.AudioExtension));
            audioDownloader.DownloadProgressChanged += (sender, args) => Progress = Math.Round(args.ProgressPercentage * 0.85);
            audioDownloader.AudioExtractionProgressChanged += (sender, args) => Progress = Math.Round(85 + args.ProgressPercentage * 0.15);
        }
Пример #6
0
        public void DownloadAudio(string link)
        {
            // Our test youtube link
            //string link = "insert youtube link";

            /*
             * Get the available video formats.
             * We'll work with them in the video and audio download examples.
             */
            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);

            /*
             * We want the first extractable video with the highest audio quality.
             */
            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();
            /*
             * If the video has a decrypted signature, decipher it
             */
            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            /*
             * Create the audio downloader.
             * The first argument is the video where the audio should be extracted from.
             * The second argument is the path to save the audio file.
             */
            string fileName = video.Title;
            fileName =  Regex.Replace(fileName, @"[^\w\.@-]", "", RegexOptions.None, TimeSpan.FromSeconds(1.5));
            var audioDownloader = new AudioDownloader(video, Path.Combine(downloadLocation, fileName + video.AudioExtension));

            // Register the progress events. We treat the download progress as 85% of the progress and the extraction progress only as 15% of the progress,
            // because the download will take much longer than the audio extraction.
            audioDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage * 0.85);
            audioDownloader.AudioExtractionProgressChanged += (sender, args) => Console.WriteLine(85 + args.ProgressPercentage * 0.15);

            if (!File.Exists(Path.Combine(downloadLocation, fileName + video.AudioExtension)))
            {
                /*
                 * Execute the audio downloader.
                 * For GUI applications note, that this method runs synchronously.
                 */
                audioDownloader.Execute();
            }
        }
Пример #7
0
        private void DownloaderAudio()
        {
            try
            {
                string link = textBox1.Text;
                addItemToList("Iniciando Download...");
                IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);
                VideoInfo video = videoInfos
                    .Where(info => info.CanExtractAudio)
                    .OrderByDescending(info => info.AudioBitrate)
                    .First();

                if (video.RequiresDecryption)
                {
                    DownloadUrlResolver.DecryptDownloadUrl(video);
                }
                addItemToList("Baixando " + video.Title);
                string outputTitle = video.Title;
                foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                {
                    outputTitle = outputTitle.Replace(c, '_');
                }
                var audioDownloader = new AudioDownloader(video, Path.Combine("C:/Downloads", outputTitle + video.AudioExtension));
                audioDownloader.DownloadProgressChanged += (sender, args) => this.Invoke((MethodInvoker)delegate {
                    progressBar.Value = (int)(args.ProgressPercentage * 0.85);
                    rateLabel.Text = Math.Round(args.ProgressPercentage * 0.85, 2).ToString() + "%";
                });
                audioDownloader.AudioExtractionProgressChanged += (sender, args) => this.Invoke((MethodInvoker)delegate {
                    progressBar.Value = (int)(85 + args.ProgressPercentage * 0.15);
                    rateLabel.Text = Math.Round(85 + args.ProgressPercentage * 0.15, 2).ToString() + "%";
                });
                audioDownloader.DownloadFinished += (sender, args) => this.Invoke((MethodInvoker)delegate {
                    progressBar.Value = 0;
                    listVideos.Items.Add("Download Finalizado!");
                    rateLabel.Text = "";
                });

                audioDownloader.Execute();
            }
            catch(Exception e)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    MessageBox.Show("Falha ao Baixar o audio " + e.Message);
                });
            }
        }
Пример #8
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            // Our test youtube link
            string link = "youtube.com/watch?v=pv-6rweZR_s";

            /*
             * Get the available video formats.
             * We'll work with them in the video and audio download examples.
             */
            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);

            /*
             * We want the first extractable video with the highest audio quality.
             */
            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();

            /*
             * If the video has a decrypted signature, decipher it
             */
            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            /*
             * Create the audio downloader.
             * The first argument is the video where the audio should be extracted from.
             * The second argument is the path to save the audio file.
             */
            var audioDownloader = new AudioDownloader(video, Path.Combine(txtDownloadFolder.Text, video.Title + video.AudioExtension));

            // Register the progress events. We treat the download progress as 85% of the progress and the extraction progress only as 15% of the progress,
            // because the download will take much longer than the audio extraction.
            //audioDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage * 0.85);
            //audioDownloader.AudioExtractionProgressChanged += (sender, args) => Console.WriteLine(85 + args.ProgressPercentage * 0.15);

            /*
             * Execute the audio downloader.
             * For GUI applications note, that this method runs synchronously.
             */
            audioDownloader.Execute();
        }
Пример #9
0
        static void Main(string[] args)
        {
            // Our test youtube link
            string link = "http://www.youtube.com/watch?v=5y_KJAg8bHI";

            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);
            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();

            AudioDownloader audioDownloader = new AudioDownloader(video, Path.Combine(@"C:\Users\Tugberk\Downloads", video.Title + video.AudioExtension));

            audioDownloader.DownloadProgressChanged += (sender, _args) => Console.WriteLine(_args.ProgressPercentage * 0.85);
            audioDownloader.AudioExtractionProgressChanged += (sender, _args) => Console.WriteLine(85 + _args.ProgressPercentage * 0.15);
            audioDownloader.Execute();
            Console.ReadLine();
        }
        private static byte[] DownloadAudio(IEnumerable<VideoInfo> videoInfos)
        {
            /*
             * We want the first extractable video with the highest audio quality.
             */
            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();

            /*
             * If the video has a decrypted signature, decipher it
             */
            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            /*
             * Create the audio downloader.
             * The first argument is the video where the audio should be extracted from.
             * The second argument is the path to save the audio file.
             */

            var audioDownloader = new AudioDownloader(video,
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                RemoveIllegalPathCharacters(video.Title) + video.AudioExtension));

            // Register the progress events. We treat the download progress as 85% of the progress
            // and the extraction progress only as 15% of the progress, because the download will
            // take much longer than the audio extraction.
            audioDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage * 0.85);
            audioDownloader.AudioExtractionProgressChanged += (sender, args) => Console.WriteLine(85 + args.ProgressPercentage * 0.15);

            /*
             * Execute the audio downloader.
             * For GUI applications note, that this method runs synchronously.
             */
            var result = audioDownloader.GetMusicStream();
            return result;
            //audioDownloader.Execute();
            //return null;
        }
Пример #11
0
        public static void DownloadMP3(string video_url, string title, string folder_destination, Form1 form)
        {
            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(video_url);

            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();

            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            var audioDownloader = new AudioDownloader(video, Path.Combine(folder_destination, title + video.AudioExtension));

            audioDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage * 0.85);
            audioDownloader.AudioExtractionProgressChanged += (sender, args) => form.SetProgressBarValue(Convert.ToInt32(85 + args.ProgressPercentage * 0.15));

            audioDownloader.Execute();
            form.AfterUpload();
        }
        void DownloadAudioFrom(Downloadable InVideo, int count)
        {
            InVideo.Preparing = true;
            ListDelegate ld = new ListDelegate(Program.frm.UpdateList);
            Program.frm.Invoke(ld);

            string link = InVideo.Url;
            string countPrefix = count.ToString();
            countPrefix = countPrefix.PadLeft(padLeft, '0');

            VideoInfo video = DownloadUrlResolver.GetDownloadUrls(link);

            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            char[] legalTitleArray = video.Title.ToCharArray();
            string legalTitle = "";

            foreach (char c in legalTitleArray)
            {
                if (!(c == '/' || c == '\\' || c == ':' || c == '*' || c == '?' || c == '"' || c == '<' || c == '>' || c == '|'))
                {
                    legalTitle += c;
                }
            }

            if (incremental)
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + countPrefix + " " + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }
            else
            {
                var audioDownloader = new AudioDownloader(video, savePath + @"\" + legalTitle + video.AudioExtension);
                audioDownloader.DownloadProgressChanged += (sender, _args) => DownloadProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.AudioExtractionProgressChanged += (sender, _args) => ExtractionProgress(_args.ProgressPercentage, InVideo);
                audioDownloader.Execute();
            }

            lock (threadLocker)
            {
                Program.frm.remaining--;
            }
        }
Пример #13
0
        public void DownloadAudio(string filepath, DynValue callback)
        {
            Decrypt();
            AudioDownloader downloader = new AudioDownloader(obj, filepath);

            if (callback.IsNotNil())
                downloader.DownloadFinished += (sender, args) => Program.Call(callback, obj);

            downloader.Execute();
        }
Пример #14
0
        private void download()
        {
            try
            {

                Notify("Found URL: " + URL);

                VideoInfo video = getVideo(URL);

                FileName = getFileName(video);

                CurrentStatus = Status.VideoDownloading;

                if (File.Exists(Path.Combine(DownloadDirectory, FileName)))
                {
                    Notify("File Already Exist: " + FileName); //switched to complete
                    ThrowComplete();
                    return;
                }

                var audioDownloader = new AudioDownloader(video, Path.Combine(DownloadDirectory, FileName));

                audioDownloader.DownloadProgressChanged += (sender, args) =>
                    progressBar.BeginInvoke(
                    new Action(() =>
                    {
                        //if (_isClosing)
                        //    return;
                        progressBar.Value = (int)(args.ProgressPercentage);
                    }));

                audioDownloader.AudioExtractionProgressChanged += (sender, args) =>
                    progressBar.BeginInvoke(
                    new Action(() =>
                    {
                        if (args.ProgressPercentage == 0)
                        {
                            //if (_isClosing)
                            //    return;
                            SetInfoLable("Extracting: " + FileName);
                        }
                        progressBar.Value = (int)(args.ProgressPercentage);
                    }));

                SetInfoLable(FileName);

                audioDownloader.Execute();

                CurrentStatus = Status.VideoDownloadComplete;

                Notify("Completed Download of: " + FileName);
                ThrowComplete();
                return;
            }
            catch (Exception ex)
            {
                try
                {
                    if (ex.GetType() == typeof(YoutubeParseException))
                    {
                        Notify("Download Canceled: YoutubeParseException");
                        ThrowClose(ReasonForClose.Exception);
                    }
                    else
                    {
                        if (!_isClosing)
                        {
                            Notify("Download Canceled: Exception Thrown: " + ex.ToString());
                            ThrowClose(ReasonForClose.Exception);
                        }
                    }
                }
                catch (Exception) { }
            }
        }
Пример #15
0
        private void DownloadMp3(LinkInfo link, string downloadDir)
        {
            Directory.CreateDirectory(downloadDir);
            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link.Link);

            // Extracting stream with highest quality
            VideoInfo video = videoInfos.Where(info => info.CanExtractAudio).OrderByDescending(info => info.AudioBitrate).First();

            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            var audioDownloader = new AudioDownloader(video, Path.Combine(downloadDir, RemoveIllegalPathCharacters(video.Title) + video.AudioExtension));
            audioDownloader.DownloadProgressChanged += (sender, argss) =>
            {
                downloader.ReportProgress((int)argss.ProgressPercentage);

            };
            audioDownloader.DownloadFinished += (sender, argss) =>
            {
                

            };

            audioDownloader.Execute();
        }
Пример #16
0
 private static void bw_downloadAudio(object send, DoWorkEventArgs e)
 {
     isVideo_ = false;
     isAudio_ = true; 
     BackgroundWorker worker = send as BackgroundWorker;
     if (dir_ != " ")
     {
         //Parameter for video type
         IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(url_);
         VideoInfo video = videoInfos.Where(info => info.CanExtractAudio).OrderByDescending(info => info.AudioBitrate).First();
         
         if (video.RequiresDecryption)
         {
             DownloadUrlResolver.DecryptDownloadUrl(video);
         }
         audioDownloader_ = new AudioDownloader(video, dir_);
         audioDownloader_.AudioExtractionProgressChanged += (sender, args) => progBar_.Invoke((Action)(() => { worker.ReportProgress((int)(85 + args.ProgressPercentage * 0.15)); }));
         try
         {
             audioDownloader_.Execute();
         }
         catch (WebException we)
         {
             MessageBox.Show("The video returned an error, please try again later",
                              we.Response.ToString(),
             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Пример #17
0
        static void DownloadMusic(string videoID)
        {
            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls("https://www.youtube.com/watch?v="+videoID);

            VideoInfo video = videoInfos.Where(info => info.AudioType == AudioType.Mp3 && info.CanExtractAudio ).OrderByDescending(info => info.AudioBitrate).First();
            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }
            var audioDownload = new AudioDownloader(video, Path.Combine("Downloads/", RemoveIllegalPathCharacters(video.Title) + video.AudioExtension));
            audioDownload.DownloadStarted += (sender, args) =>
            {
                Console.WriteLine("Downloading " + video.Title + video.AudioExtension);
            };
            int ticks = 0;

            audioDownload.DownloadProgressChanged += (sender, args) =>
            {
                ticks++;
                if (ticks > 300)
                {
                    ticks -= 300;
                    Console.Write("|");
                }
                
            };
            audioDownload.DownloadFinished += (sender, args) =>
            {
                Console.WriteLine("Finished " + video.Title + video.AudioExtension);
            };
            audioDownload.Execute();
        }
Пример #18
0
 /// <summary>
 ///  Downloads the YouTube video to a .mp3 format
 /// </summary>
 /// <param name="type"></param>
 /// <param name="url"></param>
 /// <param name="path"></param>
 /// <param name="progressBar1"></param>
 /// <param name="progressBar"></param>
 private static void downloadAudio(ref string type, ref string url, ref string path,ProgressBar progressBar)
 {
     if (path != " ")
     {
         //Parameter for video type
         IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(url);
         
         VideoInfo video = videoInfos.Where(info => info.CanExtractAudio).OrderByDescending(info => info.AudioBitrate).First();
         if (video.RequiresDecryption)
         {
             DownloadUrlResolver.DecryptDownloadUrl(video);
         }
         var audioDownloader = new AudioDownloader(video, path);
         audioDownloader.DownloadProgressChanged += (sender, args) => progressBar.Invoke((Action)(() => { progressBar.Value = (int)(args.ProgressPercentage * 0.85); }));
         audioDownloader.AudioExtractionProgressChanged += (sender, args) => progressBar.Invoke((Action)(() => { progressBar.Value = (int)(85 + args.ProgressPercentage * 0.15); }));
         audioDownloader.DownloadFinished += completedDownload; 
         audioDownloader.Execute();
     }
 }
Пример #19
0
        private void DownloadFile()
        {
            if (radioAudio.Checked)
            {
                try
                {
                    setTextProgress("Iniciando Download...");
                    IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(txtLink.Text);
                    VideoInfo video = videoInfos
                        .Where(info => info.CanExtractAudio)
                        .OrderByDescending(info => info.AudioBitrate)
                        .First();

                    if (video.RequiresDecryption)
                    {
                        DownloadUrlResolver.DecryptDownloadUrl(video);
                    }
                    setTextMediaInfo(video.Title);
                    setTextProgress("Baixando " + video.Title);
                    string outputTitle = video.Title;
                    foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                    {
                        outputTitle = outputTitle.Replace(c, '_');
                    }
                    var audioDownloader = new AudioDownloader(video, Path.Combine("C:/Downloads", outputTitle + video.AudioExtension));
                    audioDownloader.DownloadProgressChanged += (sender, args) => this.Invoke((MethodInvoker)delegate {
                        progressFile.Value = (int)(args.ProgressPercentage * 0.85);
                        lblprogress.Text = Math.Round(args.ProgressPercentage * 0.85, 2).ToString() + "%";
                    });
                    audioDownloader.AudioExtractionProgressChanged += (sender, args) => this.Invoke((MethodInvoker)delegate {
                        progressFile.Value = (int)(85 + args.ProgressPercentage * 0.15);
                        lblprogress.Text = Math.Round(85 + args.ProgressPercentage * 0.15, 2).ToString() + "%";
                    });
                    audioDownloader.DownloadFinished += (sender, args) => this.Invoke((MethodInvoker)delegate {
                        progressFile.Value = 0;
                        lblprogress.Text = ("Download Finalizado!");
                    });
                    audioDownloader.Execute();
                }
                catch (Exception e)
                {
                    this.Invoke((MethodInvoker)delegate
                    {
                        MetroMessageBox.Show(this,"Falha ao Baixar o audio " + e.Message);
                    });
                }
            }
            else
            {
                try {
                setTextProgress("Iniciando Download...");
                IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(txtLink.Text);
                VideoInfo video = videoInfos.First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360);
                if (video.RequiresDecryption)
                {
                    DownloadUrlResolver.DecryptDownloadUrl(video);
                }
                setTextProgress("Baixando " + video.Title);
                setTextMediaInfo(video.Title);
                string outputTitle = video.Title;
                foreach (char c in System.IO.Path.GetInvalidFileNameChars())
                {
                    outputTitle = outputTitle.Replace(c, '_');
                }
                var videoDownloader = new VideoDownloader(video, Path.Combine("C:/Downloads", outputTitle + video.VideoExtension));
                videoDownloader.DownloadProgressChanged += (sender2, args) => this.Invoke((MethodInvoker)delegate {
                    progressFile.Value = (int)(Math.Round(args.ProgressPercentage, 2));
                    lblprogress.Text = Math.Round(args.ProgressPercentage, 2) + "%";
                });
                videoDownloader.DownloadFinished += (sender2, args) => this.Invoke((MethodInvoker)delegate {
                    progressFile.Value = 0;
                    lblprogress.Text = ("Download Finalizado!");
                });
                videoDownloader.Execute();
            }
            catch (Exception e)
            {
                this.Invoke((MethodInvoker)delegate
                {
                    MetroMessageBox.Show(this,"Falha ao Baixar o vídeo " + e.Message);
                });
            }
            }
        }
Пример #20
0
        void DownloadAudio(String Id)
        {
            // TODO: FIX THIS SHIT
            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls("http://www.youtube.com/watch?v=" + Id);

            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();

            if (video.RequiresDecryption) DownloadUrlResolver.DecryptDownloadUrl(video);

            var audioDownloader = new AudioDownloader(video, Path.Combine("C:/Downloads", Id + video.AudioExtension));

            double progress = 0;
            audioDownloader.DownloadProgressChanged += (sender, args) =>
            {
                if (!Math.Round(args.ProgressPercentage * 0.85, 0, MidpointRounding.AwayFromZero).Equals(progress))
                {
                    progress = Math.Round(args.ProgressPercentage * 0.85, 0, MidpointRounding.AwayFromZero);
                    Console.WriteLine(progress);
                }
            };
            audioDownloader.AudioExtractionProgressChanged += (sender, args) =>
            {
                if (!Math.Round(args.ProgressPercentage * 0.15, 0, MidpointRounding.AwayFromZero).Equals(progress))
                {
                    progress = Math.Round(args.ProgressPercentage * 0.15, 0, MidpointRounding.AwayFromZero);
                    Console.WriteLine(progress);
                }
            };

            if (DownloadExists(GetVideoBySearch(Id), true)) return;

            try
            {
                audioDownloader.Execute();
            }

            catch(System.Net.WebException e)
            {
                LRC.SendMessage("Sorry, that video cannot be added");
                try { VidList.Remove(GetVideoBySearch(Id)); } catch { }
                return;
            }
            
            
            int dotIndex = audioDownloader.SavePath.LastIndexOf(".");
            String NewName = audioDownloader.SavePath.Insert(dotIndex, "!done");
            audioDownloader.DownloadFinished += (s, e) => System.IO.File.Move(audioDownloader.SavePath, NewName);
            System.IO.File.Move(audioDownloader.SavePath, NewName);
            Console.WriteLine("Download finished!");
            return;

        }
Пример #21
0
        private void DownloadAudioTrack(VideoInfo video, string tempPath)
        {
            var downloader = new AudioDownloader(video, tempPath);

            // We need a factor at which the downlaod progress is preferred to the audio extraction progress
            const double factor = 0.95;

            downloader.DownloadProgressChanged += (sender, args) =>
            {
                this.CachingProgress = (int)(args.ProgressPercentage * factor);
            };

            downloader.AudioExtractionProgressChanged += (sender, args) =>
            {
                this.CachingProgress = (int)(factor * 100) + (int)(args.ProgressPercentage * (1 - factor));
            };

            downloader.Execute();
        }
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            //Set the path to a temp directory on the desktop.
            var folderpath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            folderpath += "\\temp\\";

            if (!Directory.Exists(folderpath))
            {
                Directory.CreateDirectory(folderpath);
            }
            /*
              * Create the audio downloader.
              * The first argument is the video where the audio should be extracted from.
              * The second argument is the path to save the audio file.
              * Automatic video title infering will be supported later.
              */
            //var audioDownloader = new AudioDownloader(video, folderpath + video.AudioExtension);
            var audioDownloader = new AudioDownloader(Video, Path.Combine(folderpath, Video.Title + Video.AudioExtension));
            // Register the ProgressChanged event and print the current progress
            audioDownloader.DownloadProgressChanged += (senders, args) => updatePercentage(args.ProgressPercentage);

            /*
             * Execute the audio downloader.
             * For GUI applications note, that this method runs synchronously.
             */

            audioDownloader.Execute();
        }
Пример #23
0
        public void Execute(ISYMMSettings settings)
        {
            try
            {
                string link = "http://youtube.com/watch?v=" + Video.VideoWatchID;
                IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);

                if (settings.Action == Actions.ExtractAudio)
                {
                    VideoInfo videoInfo = videoInfos
                        .Where(info => info.CanExtractAudio && info.AudioBitrate > 0)
                        .OrderBy(info => info.AudioBitrate)
                        .OrderBy(info => info.AdaptiveType == AdaptiveType.Audio)
                        .OrderBy(info => info.AudioBitrate == settings.AudioBitrate)
                        .Last();

                    if (videoInfo.RequiresDecryption)
                    {
                        DownloadUrlResolver.DecryptDownloadUrl(videoInfo);
                    }

                    var audioDownloader = new AudioDownloader(videoInfo, settings.SavePath + String.Format("\\{0}.{1}", settings.PathSafefileName, settings.AudioFormat.ToString()), settings.AudioFormat.ToString());

                    // Track the amount of progress we had the last time, so we can prevent multiple calls without change
                    int lastPrgs = -1;

                    // Register the progress events. We treat the download progress as 85% of the progress and the extraction progress only as 15% of the progress,
                    // because the download will take much longer than the audio extraction.
                    audioDownloader.DownloadProgressChanged += (sender, args) =>
                    {
                        if (lastPrgs != (int)args.ProgressPercentage)
                        {
                            if (this.DownloadProgressChanged != null)
                                this.DownloadProgressChanged(this, new SYMM_Backend.DownloadProgressEventArgs(args.ProgressPercentage, this.video));

                            lastPrgs = (int)args.ProgressPercentage;
                        }
                    };

                    lastPrgs = -1;

                    audioDownloader.AudioExtractionProgressChanged += (sender, args) =>
                    {
                        if (lastPrgs != (int)args.ProgressPercentage)
                        {
                            if (this.AudioExtractionProgressChanged != null)
                                this.AudioExtractionProgressChanged(this, new SYMM_Backend.DownloadProgressEventArgs(args.ProgressPercentage, this.video));

                            lastPrgs = (int)args.ProgressPercentage;
                        }
                    };

                    audioDownloader.DownloadFinished += (sender, args) =>
                    {
                        if (this.VideoDownloadComplete != null)
                            this.VideoDownloadComplete(this, new VideoDownloadCompleteEventArgs(this.Video));
                    };

                    /*
                     * Execute the audio downloader.
                     * For GUI applications note, that this method runs synchronously.
                     */
                    audioDownloader.Execute();
                }
                else if(settings.Action == Actions.Download)
                {
                    VideoInfo videoInfo = videoInfos
                        .Where(info => info.AudioBitrate > 0 && info.Resolution > 0)
                        .OrderBy(info => info.AudioBitrate)
                        .OrderBy(info => info.Resolution)
                        .OrderBy(info => info.Resolution == settings.VideoResolution)
                        .Last();

                    if (videoInfo.RequiresDecryption)
                    {
                        DownloadUrlResolver.DecryptDownloadUrl(videoInfo);
                    }

                    YoutubeExtractor.VideoDownloader videoDownloader = new YoutubeExtractor.VideoDownloader(videoInfo, settings.SavePath + String.Format("\\{0}{1}", settings.PathSafefileName, videoInfo.VideoExtension));

                    // Track the amount of progress we had the last time, so we can prevent multiple calls without change
                    int lastPrgs = -1;

                    // Register the progress events. We treat the download progress as 85% of the progress and the extraction progress only as 15% of the progress,
                    // because the download will take much longer than the audio extraction.
                    videoDownloader.DownloadProgressChanged += (sender, args) =>
                    {
                        if (lastPrgs != (int)args.ProgressPercentage)
                        {
                            if (this.DownloadProgressChanged != null)
                                this.DownloadProgressChanged(this, new SYMM_Backend.DownloadProgressEventArgs(args.ProgressPercentage, this.video));

                            lastPrgs = (int)args.ProgressPercentage;
                        }
                    };

                    videoDownloader.DownloadFinished += (sender, args) =>
                    {
                        if (this.VideoDownloadComplete != null)
                            this.VideoDownloadComplete(this, new VideoDownloadCompleteEventArgs(this.Video));
                    };

                    /*
                     * Execute the audio downloader.
                     * For GUI applications note, that this method runs synchronously.
                     */
                    videoDownloader.Execute();
                }
                else if(settings.Action == Actions.Stream)
                {
                    VideoInfo videoInfo = videoInfos
                        .Where(info => info.CanExtractAudio && info.AudioBitrate > 0)
                        .OrderBy(info => info.AudioBitrate)
                        .OrderBy(info => info.AdaptiveType == AdaptiveType.Audio)
                        .OrderBy(info => info.AudioBitrate == settings.AudioBitrate)
                        .Last();

                    if (videoInfo.RequiresDecryption)
                    {
                        DownloadUrlResolver.DecryptDownloadUrl(videoInfo);
                    }

                    var aduioStream = new AduioStreamer(videoInfo);

                    // Track the amount of progress we had the last time, so we can prevent multiple calls without change
                    int lastPrgs = -1;
                    aduioStream.StreamPositionChanged += (sender, args) =>
                    {
                        if (lastPrgs != (int)args.ProgressPercentage)
                        {
                            if (this.StreamPositionChanged != null)
                                this.StreamPositionChanged(this, new DownloadProgressEventArgs(args.ProgressPercentage, this.video));

                            lastPrgs = (int)args.ProgressPercentage;
                        }
                    };

                    aduioStream.StreamFinished += (sender, args) =>
                    {
                        if (this.StreamFinished != null)
                            this.StreamFinished(this, new VideoDownloadCompleteEventArgs(this.Video));
                    };

                    aduioStream.Execute();
                }
            }
            catch(YoutubeParseException ex)
            {
                if (this.VideoDownloadFailed != null)
                    this.VideoDownloadFailed(this, new VideoDownloadFailedEventArgs(this.Video, ex));
            }
        }
Пример #24
0
        static void DownloadMP3(string link, string downloadDir)
        {
            Directory.CreateDirectory(downloadDir);
            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);

            // Extracting stream with highest quality
            VideoInfo video = videoInfos.Where(info => info.CanExtractAudio).OrderByDescending(info => info.AudioBitrate).First();

            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }
            
            var audioDownloader = new AudioDownloader(video, Path.Combine(downloadDir, RemoveIllegalPathCharacters(video.Title) + video.AudioExtension));
            int ticks = 0;
            audioDownloader.DownloadProgressChanged += (sender, argss) =>
            {
                ticks++;

                if (ticks > 1000)
                {
                    Console.Write("#");
                    ticks -= 1000;
                }
                
            };
            audioDownloader.DownloadFinished += (sender, argss) =>
            {
                
                Console.WriteLine("\nFinished download " + video.Title + video.AudioExtension);
            };

            audioDownloader.Execute();
        }
Пример #25
0
        private void DownloadVideo(VideoInfo video, string tempPath)
        {
            var downloader = new AudioDownloader(video, tempPath);

            downloader.ProgressChanged += (sender, args) =>
            {
                this.CachingProgress = (int)args.ProgressPercentage;
            };

            downloader.Execute();
        }
Пример #26
0
        public String DownloadYoutubeVideo(String url)
        {
            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(url);
            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();

            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            String result = Path.Combine(ApplicationFolder, video.Title + video.AudioExtension);

            AudioDownloader audioDownloader = new AudioDownloader(video, result);
            audioDownloader.Execute();

            return result;
        }
Пример #27
0
        private async Task RequestCommand(CommandEventArgs e)
        {
                var urlToDownload = e.Args[0];
                var newFilename = Guid.NewGuid().ToString();
                var mp3OutputFolder = @"c:\mp3\";

            if (urlToDownload.Contains("soundcloud"))
            {
                Track track = _soundCloud.GetTrack(e.Args[0]);
                string inPath = Path.Combine(mp3OutputFolder, newFilename + ".mp3");

                if (!track.Streamable)
                {
                    await e.Channel.SendMessage("\"" + track.Title + "\" is not streamable :C");
                }

                try
                {
                    using (var client = new WebClient())
                    {
                        client.DownloadFile(track.StreamUrl + "?client_id=" + _soundCloud.ClientID, inPath);
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.ToString());
                }

                var outFile = inPath.Remove(inPath.Length - 4) + "_c" + ".wav";

                try
                {
                    using (var reader = new MediaFoundationReader(inPath))
                    {
                        var outFormat = new WaveFormat(48000, 16, 2);
                        using (var resampler = new MediaFoundationResampler(reader, outFormat))
                        {
                            resampler.ResamplerQuality = 60;
                            VolumeWaveProvider16 vol = new VolumeWaveProvider16(resampler);
                            vol.Volume = 0.3f;
                            WaveFileWriter.CreateWaveFile(outFile, vol);
                        }
                    }

                    File.Delete(inPath);

                }
                catch (Exception e2)
                {
                    Console.Write(e2.ToString());
                    return;
                }

                await e.Channel.SendMessage("Added \"" + track.Title + "\" to the queue. It will be played soon.");

                _queue.musicQueue.Enqueue(Tuple.Create<string, string>(outFile, track.Title));
                Thread thread = new Thread(() => { _queue.PlayNextMusicToAllVoiceClients(); });
                thread.Start();

            }
            else
            {

                IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(e.Args[0]);

                VideoInfo video = videoInfos.Where(info => info.CanExtractAudio).OrderByDescending(info => info.AudioBitrate).First();

                if (video.RequiresDecryption)
                {
                    DownloadUrlResolver.DecryptDownloadUrl(video);
                }

                string inPath = Path.Combine(mp3OutputFolder, newFilename + video.AudioExtension);

                try
                {
                    var audioDownloader = new AudioDownloader(video, inPath);
                    audioDownloader.Execute();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error while trying to download youtube link.");
                    Console.Write(ex.ToString());
                }

                var outFile = inPath.Remove(inPath.Length - 4) + "_c" + ".wav";

                try
                {
                    using (var reader = new MediaFoundationReader(inPath))
                    {
                        var outFormat = new WaveFormat(48000, 16, 2);
                        using (var resampler = new MediaFoundationResampler(reader, outFormat))
                        {
                            resampler.ResamplerQuality = 60;
                            VolumeWaveProvider16 vol = new VolumeWaveProvider16(resampler);
                            vol.Volume = 0.3f;
                            WaveFileWriter.CreateWaveFile(outFile, vol);
                        }
                    }

                    File.Delete(inPath);

                }
                catch (Exception e2)
                {
                    Console.Write(e2.ToString());
                    return;
                }

                await e.Channel.SendMessage("Added \"" + video.Title + "\" to the queue. It will be played soon.");

                _queue.musicQueue.Enqueue(Tuple.Create<string, string>(outFile, video.Title));

                Thread thread = new Thread(() => { _queue.PlayNextMusicToAllVoiceClients(); });
                thread.Start();
            }
        }
        private void Downloader (IEnumerable<VideoInfo> videoInfos, MainProgramElements mainWindow, Video videoToUse)
        {
        	bool audioTrack = videoToUse.IsAudioFile;
            VideoInfo video = videoInfos.First(info => !audioTrack ? (info.VideoType == videoToUse.VideoFormat && info.Resolution == videoToUse.Quality) : (info.AudioType == videoToUse.AudioFormat && info.AudioBitrate == videoToUse.Quality));
            
            if (video.RequiresDecryption) DownloadUrlResolver.DecryptDownloadUrl(video);
            
            string videoName = string.Format(CultureInfo.InvariantCulture, "{0}{1}", RemoveIllegalPathCharacters(video.Title), !audioTrack ? video.VideoExtension : video.AudioExtension);
            string temporaryDownloadPath = Path.Combine(this.UserSettings.TemporarySaveLocation, videoName);
            string movingPath = Path.Combine(this.UserSettings.MainSaveLocation, videoName);
            if (this.UserSettings.ValidationLocations.All(path => !File.Exists(Path.Combine(path, videoName))) && !File.Exists(movingPath))
            {
        		if(audioTrack)
        		{
			        var audioDownloader = new AudioDownloader (video, temporaryDownloadPath);;
			        audioDownloader.AudioExtractionProgressChanged += (sender, args) => mainWindow.CurrentDownloadProgress = (int)(85 + args.ProgressPercentage * 0.15);
			        audioDownloader.Execute();
        		}
        		else
        		{
        			var videoDownloader = new VideoDownloader (video, temporaryDownloadPath);
        			videoDownloader.DownloadProgressChanged += ((sender, args) => mainWindow.CurrentDownloadProgress = (int)args.ProgressPercentage);
	                videoDownloader.Execute();
        		}
        		if (!temporaryDownloadPath.Equals(movingPath, StringComparison.OrdinalIgnoreCase)) File.Move(temporaryDownloadPath, movingPath);
            }
            else
            {
            	throw new DownloadCanceledException(string.Format(CultureInfo.CurrentCulture, "The download of #{0} '{1}({2})' has been canceled because it already existed.", videoToUse.Position, RemoveIllegalPathCharacters(video.Title).Truncate(10), videoToUse.Location.Truncate(100)));
            }
        }
Пример #29
0
        public Archivo Descargar(string videoId)
        {
            // Our test youtube link
            //string link = "https://www.youtube.com/watch?v=r0ypUaCDrLI";

            /*
             * Get the available video formats.
             * We'll work with them in the video and audio download examples.
             */
            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls($"https://www.youtube.com/watch?v={videoId}");
            /*
            * We want the first extractable video with the highest audio quality.
            */
            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .OrderByDescending(info => info.AudioBitrate)
                .First();

            /*
             * If the video has a decrypted signature, decipher it
             */
            if (video.RequiresDecryption)
            {
                DownloadUrlResolver.DecryptDownloadUrl(video);
            }

            /*
             * Create the audio downloader.
             * The first argument is the video where the audio should be extracted from.
             * The second argument is the path to save the audio file.
             */
            var tempFileName = Path.GetTempFileName();
            var audioDownloader = new AudioDownloader(video, tempFileName);

            // Register the progress events. We treat the download progress as 85% of the progress and the extraction progress only as 15% of the progress,
            // because the download will take much longer than the audio extraction.
            //audioDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage * 0.85);
            //audioDownloader.AudioExtractionProgressChanged += (sender, args) => Console.WriteLine(85 + args.ProgressPercentage * 0.15);

            /*
             * Execute the audio downloader.
             * For GUI applications note, that this method runs synchronously.
             */
            audioDownloader.Execute();

            using (MemoryStream ms = new MemoryStream())
            using (FileStream file = new FileStream(tempFileName, FileMode.Open, FileAccess.Read))
            {
                byte[] bytes = new byte[file.Length];
                file.Read(bytes, 0, (int)file.Length);
                ms.Write(bytes, 0, (int)file.Length);
                return new Archivo { Stream = ms, Nombre = video.Title.RemoveInvalidChars() + video.AudioExtension };
            }
        }
Пример #30
0
        public override void LoadToCache()
        {
            this.IsCaching = true;

            string tempPath = Path.GetTempFileName();

            IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(this.OriginalPath);

            VideoInfo video = videoInfos
                .Where(info => info.CanExtractAudio)
                .First(info =>
                        info.VideoFormat == VideoFormat.FlashMp3HighQuality ||
                        info.VideoFormat == VideoFormat.FlashMp3LowQuality);

            var downloader = new AudioDownloader(video, tempPath);

            downloader.ProgressChanged += (sender, args) =>
            {
                this.CachingProgress = (int)args.ProgressPercentage;
            };

            downloader.Execute();
            this.StreamingPath = tempPath;

            this.IsCached = true;
        }