Ejemplo n.º 1
0
        private static void DownloadAudio(VideoInfo video, string pth)
        {
            /*
             * We want the first extractable video with the highest audio quality.
             */

            /*
             * 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, pth);

            // 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();
        }
Ejemplo n.º 2
0
 public void Start()
 {
     if (VideoClient == null)
     {
         DownloadTask = Task.Factory.StartNew(() =>
         {
             try
             {
                 AudioClient.Execute();
             }
             catch (Exception e)
             {
                 Ready   = true;
                 Error   = true;
                 Message = e.Message;
             }
         });
     }
     if (AudioClient == null)
     {
         DownloadTask = Task.Factory.StartNew(() =>
         {
             try
             {
                 VideoClient.Execute();
             }
             catch (Exception e)
             {
                 Ready   = true;
                 Error   = true;
                 Message = e.Message;
             }
         });
     }
 }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
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();
        }
Ejemplo n.º 5
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();
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
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);
                }
            }
        }
Ejemplo n.º 9
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;
        }
Ejemplo n.º 10
0
        public void Download(string filename)
        {
            var video = GetVideoInfo();

            /*
             * 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, filename);

            // 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) => RaiseProgressEvent(args.ProgressPercentage * 0.85);
            audioDownloader.AudioExtractionProgressChanged += (sender, args) => RaiseProgressEvent(85 + args.ProgressPercentage * 0.15);
            audioDownloader.DownloadFinished += (sender, args) => RaiseProgressEvent(101.0);

            /*
             * Execute the audio downloader.
             * For GUI applications note, that this method runs synchronously.
             */
            audioDownloader.Execute();
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Downloads the audio
 /// </summary>
 private void DownloadAudio()
 {
     //Start the download
     Downloader.Execute();
     //Set the download progress to complete
     DownloadProgress = "Complete";
 }
Ejemplo n.º 12
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();
        }
        public static void DownloadAudio(IEnumerable <VideoInfo> videoInfos)
        {
            try
            {
                VideoInfo video = videoInfos.Where(info => info.CanExtractAudio).OrderByDescending(info => info.AudioBitrate).First();

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

                string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\YouTubeAudios";

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                var savePath = Path.Combine(path, YouTubeHelpers.RemoveIllegalPathCharacters(video.Title) + video.AudioExtension);

                var audioDownloader = new AudioDownloader(video, savePath);

                audioDownloader.DownloadProgressChanged += (sender, args) => Console.WriteLine(args.ProgressPercentage * 0.85);

                audioDownloader.AudioExtractionProgressChanged += (sender, args) => Console.WriteLine(85 + args.ProgressPercentage * 0.15);

                audioDownloader.Execute();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 14
0
        private void Downloader (YouTubeVideo video, MainProgramElements mainWindow, bool isAudio)
        {
            string temporaryDownloadPath = Path.Combine(this.UserSettings.TemporarySaveLocation, video.FullName);
            string movingPath = Path.Combine(this.UserSettings.MainSaveLocation, video.FullName);
            if (this.UserSettings.ValidationLocations.All(path => !File.Exists(Path.Combine(path, video.FullName)) && !File.Exists(movingPath))
            {
        		if(isAudio)
        		{
			        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)));
            }
        }
        public void EventListeningTest()
        {
            var yc = new YoutubeContext(Url, true) {BaseDirectory = new DirectoryInfo(Path.GetTempPath())};
            var ad = new AudioDownloader(yc);

            var sb = new StringBuilder();

            yc.DownloadFailed += (sender, args) => {
                Debug.WriteLine(args.Subject + "\n" + args.Exception);
                sb.AppendLine(args.Subject + "\n" + args.Exception);
            };

            yc.ProgresStateChanged += (sender, args) => {
                if (args.UIHandled || args.Stage != YoutubeStage.ExtractingAudio)
                    return;
                Debug.Write(args.Precentage.ToString("A###") + " ");
                sb.Append(args.Precentage.ToString("A###") + " ");
                args.UIHandled = true;
            };
            yc.ProgresStateChanged += (sender, args) => {
                if (args.UIHandled || args.Stage != YoutubeStage.Downloading)
                    return;
                Debug.Write(args.Precentage.ToString("D###") + " ");
                sb.Append(args.Precentage.ToString("D###") + " ");
                args.UIHandled = true;
            };

            yc.ProgresStateChanged += (sender, args) => {
                if (args.UIHandled)
                    return;
                Debug.Write($"{{{args.Stage.ToString()}}}");
                sb.Append($"{{{args.Stage.ToString()}}}");
            };

            DownloadUrlResolver.FindHighestAudioQualityDownloadUrl(yc);

            try {
                ad.Execute();
                yc.WaitForThumbnail();
                Assert.IsTrue(File.Exists(yc.AudioPath?.FullName ?? "/"));
                Debug.WriteLine(yc.AudioPath?.FullName ?? "");
            } finally {
                if (yc.AudioPath != null && File.Exists(yc.AudioPath.FullName))
                    File.Delete(yc.AudioPath.FullName);
            }

            var events = Enum.GetValues(typeof(YoutubeStage)).Cast<YoutubeStage>()
                .Where(s =>
                    s != YoutubeStage.DecipheringUrls
                    && s != YoutubeStage.Downloading
                    && s != YoutubeStage.ExtractingAudio
                    && s != YoutubeStage.Undefined
                )
                .Select(ys => $"{{{ys}}}").ToArray();
            var c = sb.ToString();
            foreach (var @event in events)
                Assert.IsTrue(c.Contains(@event), $"c.Contains(YoutubeStage.{@event})");
        }
 /// <summary>
 ///     Downloads context to audio, requires Url, Optional - VideoInfo (Default: Highest Quality), Optional - BaseDirectory
 /// </summary>
 public static void ToAudio(this YoutubeContext context) {
     if (context==null)
         throw new ArgumentException(nameof(context));
     if (string.IsNullOrEmpty(context.Url))
         throw new ArgumentException(nameof(context.Url));
     
     if (context.VideoInfo == null)
         context.FindHighestAudioQualityDownloadUrl();
     
     var ad = new AudioDownloader(context);
     ad.Execute();
 }
Ejemplo n.º 17
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();
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// The thread's method which in place executes the audiodownloader
        /// </summary>
        private void DownloadThreadMethod()
        {
            AudioDownloader audioDownloader = new AudioDownloader(this.VideoInfo, Application.StartupPath + "/_SESSIONS/" + this.SessionID + "/" + VideoInfo.Title + VideoInfo.AudioExtension, this.Url);

            audioDownloader.DownloadProgressChanged        += new EventHandler <ProgressEventArgs>(audioDownloader_DownloadProgressChanged);
            audioDownloader.AudioExtractionProgressChanged += new EventHandler <ProgressEventArgs>(audioDownloader_AudioExtractionProgressChanged);
            audioDownloader.Execute();

            while (!this.IsComplete)
            {
                ///
            }
        }
Ejemplo n.º 19
0
        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--;
            }
        }
Ejemplo n.º 20
0
        private 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();

            /*
             * 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 defaultFileName = removeIllegalPathCharacters(video.Title) + video.AudioExtension;
            string fileName        = getFileName(defaultFileName);

            var audioDownloader = new AudioDownloader(video, fileName);

            progressBar.Value = 0;

            labelStatus.Text = "Downloading - " + video.Title;
            labelStatus.Refresh();

            // 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) => { progressBar.Value = (int)(args.ProgressPercentage * 0.85); };
            audioDownloader.AudioExtractionProgressChanged += (sender, args) => { progressBar.Value = (85 + (int)(args.ProgressPercentage * 0.15)); };

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

            progressBar.Value = 0;
            labelStatus.Text  = "Complete.";
        }
Ejemplo n.º 21
0
        private void DownloadAudio(IEnumerable <VideoInfo> videoInfos, out string fileName)
        {
            /*
             * We want the first extractable video with the highest audio quality.
             */
            VideoInfo video = videoInfos
                              .Where(info => info.CanExtractAudio)
                              .OrderByDescending(info => info.AudioBitrate)
                              .FirstOrDefault();

            if (video == null)
            {
                //throw new Exception("Can not extract audio");
                DownloadVideo(videoInfos, out fileName);
                AlternativeAudioExtraction(fileName);
                return;
            }

            /*
             * 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.
             */

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

            // 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();
        }
Ejemplo n.º 22
0
        private static string DownloadYoutubeAudio(string youtubeId)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();

            var downloadFolderPath = PathToProject + "/downloads";

            var youtubeLink = GetYoutubeLink(youtubeId);

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

            /*
             * 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 pathToAudioFile = Path.Combine(downloadFolderPath, youtubeId + video.AudioExtension);

            if (!File.Exists(pathToAudioFile))
            {
                var audioDownloader = new AudioDownloader(video, pathToAudioFile);

                // 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 += AudioDownloaderOnDownloadProgressChanged;

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

                stopWatch.Stop();
                Console.WriteLine("Download done in " + stopWatch.Elapsed);
            }

            return(pathToAudioFile);
        }
Ejemplo n.º 23
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);
                });
            }
        }
Ejemplo n.º 24
0
        private static void DownloadAudio(string videoURL)
        {
            try {
                IEnumerable <VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(videoURL);

                /*
                 * 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 pathUser        = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
                string pathDownload    = Path.Combine(pathUser, "Downloads");
                var    audioDownloader = new AudioDownloader(video, Path.Combine(pathDownload, 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();
                Console.WriteLine("SUCCESSFULL OPERATION");
            } catch (Exception e) {
                Console.WriteLine("ERROR: {0}\n{1}", e.Message, e.InnerException.Message);
            }
        }
Ejemplo n.º 25
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();
        }
Ejemplo n.º 26
0
        public async void PlayYT(SocketMessage msg, string url)
        {
            await msg.Channel.SendMessageAsync("url = " + url);

            await JoinChannel(msg);

            try
            {
                IEnumerable <VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(url);

                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);
                }

                var audioDownloader = new AudioDownloader(video, Path.Combine("F:\tmp", 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();
                if (currentClient != null)
                {
                    try
                    {
                        await SendAsync(currentClient, Path.Combine("F:\tmp", video.Title + video.AudioExtension));
                    }
                    catch (Exception)
                    {
                        await msg.Channel.SendMessageAsync("url invalid");
                    }
                }
            }
            catch (Exception)
            {
                await msg.Channel.SendMessageAsync("error in youtube parsing, f*****g googles at it again");
            }
        }
Ejemplo n.º 27
0
        private void download(IEnumerable <VideoInfo> videoInfos)
        {
            VideoInfo video = videoInfos
                              .Where(info => info.CanExtractAudio)
                              .OrderByDescending(info => info.AudioBitrate)
                              .First();

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

            m_mp3File = System.IO.Path.Combine("C:/temp", video.Title + video.AudioExtension);

            var audioDownloader = new AudioDownloader(video, m_mp3File);

            audioDownloader.Execute();
        }
Ejemplo n.º 28
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();
        }
Ejemplo n.º 29
0
        void PreformDownload(string playlistPath, string videoUrl)
        {
            ////Hackiest way to rip out an arg
            //var uri = new Uri(videoUrl);
            //var args = HttpUtility.ParseQueryString(uri.Query);
            //var songFileName = args.Get("v");

            var videoInfos = DownloadUrlResolver.GetDownloadUrls(videoUrl);

            //Grab the video with best audio quality
            var videos = videoInfos
                         .Where(info => info.CanExtractAudio)
                         .OrderByDescending(info => info.AudioBitrate)
                         .ToList();
            var video = videos.First();

            var invalidChars = Path.GetInvalidFileNameChars().ToList();

            invalidChars.Add('/');
            invalidChars.Add('\\');

            var songFileName = "";

            foreach (var c in video.Title)
            {
                songFileName += invalidChars.Contains(c) ? '_' : c;
            }
            ;

            SetSongName(songFileName + video.AudioExtension);


            //SetSongName(video.Title);

            //var videoPath = Path.Combine(playlistPath, songFileName + video.VideoExtension);
            var audioPath = Path.Combine(playlistPath, songFileName + video.AudioExtension);

            SetDownloadState(SongState.YT_Download);
            var audioDownloader = new AudioDownloader(video, audioPath);

            //audioDownloader.OnBeginExtractAudio += () => SetDownloadState(SongState.YT_Extracting);
            audioDownloader.Execute();
        }
Ejemplo n.º 30
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 += (sender, args) => completedDownload();
                audioDownloader.Execute();
            }
        }
Ejemplo n.º 31
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();
        }
Ejemplo n.º 32
0
        private 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();


            /*
             * 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) => progressBar1.Value = (int)args.ProgressPercentage;



            /*
             * Execute the audio downloader.
             * For GUI applications note, that this method runs synchronously.
             */
            audioDownloader.Execute();
        }
        public void UrlDownloadingFileAlreadyExistsTest()
        {
            var yc = new YoutubeContext(Url) {BaseDirectory = new DirectoryInfo(Path.GetTempPath())};
            var yc2 = new YoutubeContext(Url) {BaseDirectory = new DirectoryInfo(Path.GetTempPath())};
            DownloadUrlResolver.FindHighestAudioQualityDownloadUrlAsync(yc).Wait();
            DownloadUrlResolver.FindHighestAudioQualityDownloadUrlAsync(yc2).Wait();

            if (yc.VideoInfo.RequiresDecryption)
                DownloadUrlResolver.DecryptDownloadUrl(yc.VideoInfo);
            var tf = Path.GetTempPath();
            var ad = new AudioDownloader(yc);
            var ad2 = new AudioDownloader(yc2);
            try {
                ad.Execute();
                ad2.Execute();
                Debug.WriteLine(yc.AudioPath.FullName);
                Debug.WriteLine(yc2.AudioPath.FullName);
                Assert.IsTrue(File.Exists(yc.AudioPath.FullName));
                Assert.IsTrue(File.Exists(yc2.AudioPath.FullName));
                Assert.IsTrue(yc.AudioPath.FullName != yc2.AudioPath.FullName);
            } finally {
                if (ad != null && File.Exists(yc.AudioPath.FullName))
                    File.Delete(yc.AudioPath.FullName);
                if (ad2 != null && File.Exists(yc2.AudioPath.FullName))
                    File.Delete(yc2.AudioPath.FullName);
            }
        }
        public void UrlDownloadingTest()
        {
            var yc = new YoutubeContext(Url) {BaseDirectory = new DirectoryInfo(Path.GetTempPath())};
            DownloadUrlResolver.FindHighestAudioQualityDownloadUrl(yc);

            var ad = new AudioDownloader(yc);
            try {
                ad.Execute();
                Assert.IsTrue(File.Exists(yc.AudioPath.FullName));
                Debug.WriteLine(yc.AudioPath.FullName);
            } finally {
                if (yc != null && File.Exists(yc.AudioPath.FullName))
                    File.Delete(yc.AudioPath.FullName);
            }
        }