Example #1
0
File: SYMM.cs Project: Kimmax/SYMM
        public void DownloadVideoNonBlocking(IYouTubeVideo video, ISYMMSettings settings)
        {
            VideoDownloader downloader = new VideoDownloader(video);
            downloader.DownloadProgressChanged += (s, e) =>
            {
                if (OnVideoDownloadProgressChanged != null)
                    OnVideoDownloadProgressChanged(this, e);
            };

            downloader.AudioExtractionProgressChanged += (s, e) =>
            {
                if (OnVideoAudioExtractionProgressChanged != null)
                    OnVideoAudioExtractionProgressChanged(this, e);
            };

            downloader.VideoDownloadComplete += (s, e) =>
            {
                if (OnVideoDownloadComplete != null)
                    OnVideoDownloadComplete(this, e);
            };

            downloader.VideoDownloadFailed += (s, e) =>
            {
                if (OnVideoDownloadFailed != null)
                    OnVideoDownloadFailed(this, e);
            };

            new Thread(() => { downloader.Execute(settings); }).Start();
        }
Example #2
0
File: SYMM.cs Project: Kimmax/SYMM
        public void Execute(IYouTubeVideo video, ISYMMSettings settings)
        {
            VideoDownloader downloader = new VideoDownloader(video);
            downloader.DownloadProgressChanged += (s, e) =>
            {
                if (OnVideoDownloadProgressChanged != null)
                    OnVideoDownloadProgressChanged(this, e);
            };

            downloader.AudioExtractionProgressChanged += (s, e) =>
            {
                if (OnVideoAudioExtractionProgressChanged != null)
                    OnVideoAudioExtractionProgressChanged(this, e);
            };

            downloader.VideoDownloadComplete += (s, e) =>
            {
                if (OnVideoDownloadComplete != null)
                    OnVideoDownloadComplete(this, e);
            };

            downloader.VideoDownloadFailed += (s, e) =>
            {
                if (OnVideoDownloadFailed != null)
                    OnVideoDownloadFailed(this, e);
            };

            downloader.StreamPositionChanged += (s, e) =>
            {
                if (OnStreamPostionChanged != null)
                    OnStreamPostionChanged(this, e);
            };

            downloader.StreamFinished += (s, e) =>
            {
                if (OnStreamComplete != null)
                    OnStreamComplete(this, e);
            };

            downloader.Execute(settings);
            downloader = null;
        }
Example #3
0
        public static void Execute(ISYMMSettings settings)
        {
            symmBackend = new SYMMHandler(Properties.Settings.Default.youtubeApiKey);
            rawVideoList = new List<IYouTubeVideo>();

            // Create save folder, when not existent and not streaming
            if (settings.Action != Actions.Stream && !Directory.Exists(settings.SavePath))
                Directory.CreateDirectory(settings.SavePath);

            symmBackend.OnVideoInformationLoaded += (s, e) =>
            {
                rawVideoList.Add(e.Video);
            };

            symmBackend.OnStreamPostionChanged += (dsender, deventargs) =>
            {
                // Show progress on GUI
                DrawProgressBar((int)Math.Floor(deventargs.ProgressPercentage), 100, 60, '#');
            };

            // Register finished download of one video
            symmBackend.OnStreamComplete += (dsender, deventargs) =>
            {
                Console.WriteLine(String.Format("\nVideo finsihed: \"{0}\"", deventargs.Video.VideoTitle));
            };

            // Register changed download progress of one video Audio process counts as 75% work
            symmBackend.OnVideoDownloadProgressChanged += (dsender, deventargs) =>
            {
                // Show progress on GUI
                if (settings.Action == Actions.ExtractAudio)
                {
                    DrawProgressBar((int)Math.Floor(deventargs.ProgressPercentage) / 4, 100, 60, '#');
                }
                else
                {
                    DrawProgressBar((int)Math.Floor(deventargs.ProgressPercentage), 100, 60, '#');
                }
            };

            // Register changed audio extraction progress of one video. Audio process counts as 25% work
            symmBackend.OnVideoAudioExtractionProgressChanged += (dsender, deventargs) =>
            {
                // Show progress on GUI
                if (settings.Action == Actions.ExtractAudio)
                {
                    DrawProgressBar((int)Math.Floor(deventargs.ProgressPercentage) / 4 + 75, 100, 60, '#');
                }
                else
                {
                    DrawProgressBar((int)Math.Floor(deventargs.ProgressPercentage), 100, 60, '#');
                }

            };

            // Register finished download of one video
            symmBackend.OnVideoDownloadComplete += (dsender, deventargs) =>
            {
                Console.WriteLine(String.Format("\nVideo finsihed: \"{0}\"", deventargs.Video.VideoTitle));
            };

            // Register when a video failed to download
            symmBackend.OnVideoDownloadFailed += (dsender, deventargs) =>
            {
                Console.WriteLine(String.Format("Video failed to download: \"{0}\"", deventargs.Video.VideoTitle));
            };

            Console.WriteLine("Loading data..");
            symmBackend.LoadVideosFromURL(settings);
            Console.WriteLine("Loaded. Starting work!");

            // We want to download every video in this list
            foreach (IYouTubeVideo video in rawVideoList)
            {
                Console.WriteLine(String.Format("\"{0}\"", video.VideoTitle));

                if (settings.Action != Actions.Stream)
                {
                    // Prepare backend
                    settings.PathSafefileName = symmBackend.BuildPathSafeName(video.VideoTitle);

                    if (settings.CheckDuplicate && Directory.GetFiles(settings.SavePath, settings.PathSafefileName + ".*").Length > 0)
                    {
                        // Looks like we downloaded that already. Skip.
                        Console.WriteLine(String.Format("Looks like we already downloaded \"{0}\".\nSet 'settings.duplicatecheck' to false to ignore this.", video.VideoTitle));

                        // Skip the rest
                        continue;
                    }
                }

                // Tell backend to download the video spceifed to destination spceifed in the variable
                symmBackend.Execute(video, settings);
            }

            symmBackend = null;
        }
Example #4
0
File: SYMM.cs Project: Kimmax/SYMM
        public void LoadVideosFromURL(ISYMMSettings settings)
        {
            YouTubeHandler.OnAllVideoInformationLoaded += (s, e) =>
            {
                if (OnAllVideoInformationLoaded != null)
                    OnAllVideoInformationLoaded(this, new AllVideoInformationLoadedEventArgs(e.Videos));
            };

            YouTubeHandler.OnVideoInformationLoaded += (s, e) =>
            {
                if (OnVideoInformationLoaded != null)
                    OnVideoInformationLoaded(this, new VideoInformationLoadedEventArgs(e.Video));
            };

            YouTubeHandler.LoadURLVideos(settings);
        }
Example #5
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));
            }
        }