コード例 #1
0
        /// <summary>
        /// Download a youtube video to a destination folder
        /// </summary>
        /// <param name="destinationFolder">A folder to create the file in</param>
        /// <param name="videoUrl">Youtube url (e.g. https://www.youtube.com/watch?v=VIDEO_ID)</param>
        /// <param name="progress">An object implementing `IProgress` to get download progress, from 0 to 1</param>
        /// <param name="cancellationToken">A CancellationToken used to cancel the current async task</param>
        /// <returns>Returns the path to the file where the video was downloaded</returns>
        /// <exception cref="NotSupportedException">When the youtube url doesn't contain any supported streams</exception>
        public async Task <string> DownloadVideoAsync(string destinationFolder = null, string videoUrl = null, CancellationToken cancellationToken = default)
        {
            try
            {
                videoUrl = videoUrl ?? youtubeUrl;

                var video = await YoutubeDl.GetVideoMetaDataAsync(videoUrl);

                cancellationToken.ThrowIfCancellationRequested();

                var fileName = $"{video.Title}.{video.Extension}";

                var invalidChars = Path.GetInvalidFileNameChars();
                foreach (var invalidChar in invalidChars)
                {
                    fileName = fileName.Replace(invalidChar.ToString(), "_");
                }

                var filePath = fileName;
                if (!string.IsNullOrEmpty(destinationFolder))
                {
                    Directory.CreateDirectory(destinationFolder);
                    filePath = Path.Combine(destinationFolder, fileName);
                }

                await YoutubeDownloader.DownloadAsync(video, filePath, cancellationToken);

                return(filePath);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
                return(null);
            }
        }
コード例 #2
0
ファイル: SongCommand.cs プロジェクト: MatanRad/Matbot
        public void Execute(Message message, string name)
        {
            //return;
            Client.Audio audio = YoutubeDownloader.DownloadAudioWithProgress(YoutubeParser.ParseVidFromName(name), message);
            audio.AudioStream.Position = 0;

            message.Client.SendAudioMessage(message.Chat, audio);
        }
コード例 #3
0
 protected override void Run()
 {
     ServerVoiceConnections = new ConcurrentDictionary <ulong, VoiceConnection>();
     UserVoiceConnections   = new ConcurrentDictionary <ulong, AudioInStream>();
     AudioQueue             = new AudioQueue();
     AcaBoxTTS  = new AcaBoxTTS(Provider.GetService <HttpService>(), Provider.GetService <MathService>());
     SoundCloud = new SoundCloud(Provider.GetService <Config>().SoundCloudClientId, Provider.GetService <HttpService>());
     Youtube    = new YoutubeDownloader("youtube-dl", $"-f mp4 --playlist-end {Provider.GetService<Config>().YouTubePlaylistMaxItems.ToString()} --ignore-errors");
 }
コード例 #4
0
 public MainWindow(string workingDirectory)
 {
     InitializeComponent();
     folderBrowserDialog.Description         = "Select the directory that you want to save files to";
     folderBrowserDialog.ShowNewFolderButton = false;
     downloader = new YoutubeDownloader(workingDirectory);
     SetWorkingDirectory(workingDirectory);
     downloadsList.DataSource = fileBinding;
 }
コード例 #5
0
        static void Main(string[] args)
        {
            YoutubeDownloader naiveDownloader = new YoutubeDownloader(new ThirdPartyYoutubeClass());
            YoutubeDownloader smartDownloader = new YoutubeDownloader(new YoutubeCacheProxy());

            long naive = Test(naiveDownloader);
            long smart = Test(smartDownloader);

            Console.WriteLine("Time saved by caching proxy: " + (naive - smart) + "ms");
            Console.ReadKey();
        }
コード例 #6
0
        public async void getYoutubeVideo(string youtubeUrl)
        {
            //typeOfVideo = "youtube";
            //youtubeWebElement.Stop();
            WebViewVisible       = Visibility.Collapsed;
            ProgressRingActive   = true;
            ProgressStackVisible = Visibility.Visible;

            ListOfVideos = await YoutubeDownloader.GetYouTubeVideoUrls(youtubeUrl);

            //youtube url to null
            youtubeUrl = "";
            int count = ListOfVideos.Count;

            for (int i = 0, j = 0; i < count; i++)
            {
                ListOfVideos.ElementAt(i).stringDimension = ListOfVideos.ElementAt(i).Dimension.ToString();
                //videos.ElementAt(j).stringDimension = videos.ElementAt(j).Dimension.ToString();
                //Uri uri = new Uri(videos.ElementAt(j).DownloadUrl);

                //WebRequest request = WebRequest.Create(uri);
                //try
                //{
                //    WebResponse response = await request.GetResponseAsync();
                //}
                //catch(WebException ex)
                //{
                //    //HelperMethods.HelperMethods.MessageUser(ex.ToString()+"\n"+ex.Message.ToString());
                //    videos.RemoveAt(j);
                //    continue;
                //}
                //j++;
            }
            if (_listOfVideos.Count == 0)
            {
                ProgressRingActive   = false;
                ProgressStackVisible = Visibility.Collapsed;
                await Helper.HelperMethods.MessageUser("Something unexpected happenned or Youtube doesnt allow to download this. Try again to find out");

                WebViewVisible = Visibility.Visible;
                //Frame.Navigate(typeof(videos));
                //youtubeWebElement.Visibility = Visibility.Visible;
            }
            else
            {
                //DataContext = videos;
                ProgressRingActive       = false;
                ProgressStackVisible     = Visibility.Collapsed;
                SelectedVideoTitle       = _listOfVideos.ElementAt(0).VideoTitle.ToString();
                SelectionGridViewVisible = Visibility.Visible;
                //await progIndicator.HideAsync();
            }
        }
コード例 #7
0
        private void BtnCheck_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                YoutubeSource ys = YoutubeDownloader.GetYoutubeSource_Offical(tbSearchLink.Text);

                GlobalViewModel.ExternalSourceViewModel.Sources.Insert(0, ys);
                tcSelectedIndex.SelectedIndex = 0;
                templates.SelectedIndex       = 0;
            }
            catch (Exception)
            {
                MessageBox.Show("링크가 잘못되었습니다. 확인 후 다시 시도해주세요.");
            }

            tbSearchLink.Clear();
        }
コード例 #8
0
        public static long Test(YoutubeDownloader downloader)
        {
            long startTime = CurrentTimeMillis();

            // User behavior in our app:
            downloader.RenderPopularVideos();
            downloader.RenderVideoPage("catzzzzzzzzz");
            downloader.RenderPopularVideos();
            downloader.RenderVideoPage("dancesvideoo");
            // Looks like out users visit same pages very often.
            downloader.RenderVideoPage("catzzzzzzzzz");
            downloader.RenderVideoPage("someothervid");

            long estimatedTime = CurrentTimeMillis() - startTime;

            Console.WriteLine("Time elapsed: " + estimatedTime + "ms\n");
            return(estimatedTime);
        }
コード例 #9
0
        public ExternalSourceViewModel()
        {
            //OpenFileDialog ofd = new OpenFileDialog();
            //if (ofd.ShowDialog().Value)
            //{
            //    LoadTemplates(ofd.FileName);
            //}

            Sources = new ObservableCollection <BaseSource>();

            Sources.Add(new UnitySource("대나무 숲", @"C:\Users\uutak\Downloads\대나무 숲.png"));
            //Sources.Add(new UnitySource("테스트", @"C:\Users\uutak\바탕 화면\SoMa\초반 인트로.jpg"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=zOcrB6ia_DA&ab_channel=DocOptic"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=4V1QTOqaELo&ab_channel=DANKO"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=n6ikm5qfx0g&ab_channel=AlexMercer"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=pBuZEGYXA6E&ab_channel=ibighit"));

            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=0pXYp72dwl0&list=PLMTfiLScYpP4a8MSHoyMcRmNdSwV7ghK9&ab_channel=MatthiasM.de"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=a0yaOFwKKJ8&list=PLMTfiLScYpP4a8MSHoyMcRmNdSwV7ghK9&index=4&ab_channel=floopyFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=Yq_fVXatChk&index=20&list=PLMTfiLScYpP4a8MSHoyMcRmNdSwV7ghK9&ab_channel=AlexRideout"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=PopWkg8-hsI&list=PLMTfiLScYpP4a8MSHoyMcRmNdSwV7ghK9&index=65&ab_channel=LuenWarneke"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=RzE62hW-w0s&index=4&list=PL11S5Ezd1D92ZLY5i1m4ly8OkAKYNJh6O&ab_channel=footageisland"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=ZFd7jVc7x2g&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=JMzfgPHLTxY&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&index=2&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=arwXMBEiyyk&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&index=6"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=2qWtx0RmEyA&index=17&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=brPVoQlFyx4&index=24&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=I6c097lMEiI&index=21&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=sdv-Uy4otZw&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&index=25&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=VgWfNG7E6dU&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&index=28&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=gWdv2t_AC-k&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&index=34&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=xvM86rb-Q-8&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&index=37&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=id8fQzm38mE&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&index=40"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=THSy-UHrUq4&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&index=45&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=Eco_Jh0mN0M&list=PLj6XzcqwRpN4CVMKhTUQi1jh36H3uSMnM&index=46&ab_channel=AAVFX"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=EjyzNY5qD3s&list=PLeRGwsngMKZzz1RhCT3HqA4HWjI8WvvWw&ab_channel=bestofgreenscreen"));
            Sources.Add(YoutubeDownloader.GetYoutubeSource_Offical("https://www.youtube.com/watch?v=UyLKvhM8HlE&index=2&list=PLeRGwsngMKZzz1RhCT3HqA4HWjI8WvvWw&ab_channel=BrunoVitaPintucci"));

            //AddFromYoutubeSource(ys);
        }
コード例 #10
0
        /// <summary>
        /// Download a youtube video to a destination folder
        /// </summary>
        /// <param name="destinationFolder">A folder to create the file in</param>
        /// <param name="videoUrl">Youtube url (e.g. https://www.youtube.com/watch?v=VIDEO_ID)</param>
        /// <param name="cancellationToken">A CancellationToken used to cancel the current async task</param>
        /// <returns>Returns the path to the file where the video was downloaded</returns>
        public async Task <string> DownloadVideoAsync(string destinationFolder = null, string videoUrl = null, CancellationToken cancellationToken = default)
        {
            videoUrl = videoUrl ?? youtubeUrl;

            var video = await YoutubeDl.GetVideoMetaDataAsync(videoUrl);

            cancellationToken.ThrowIfCancellationRequested();

            var fileName = GetVideoFileName(video);

            var filePath = fileName;

            if (!string.IsNullOrEmpty(destinationFolder))
            {
                Directory.CreateDirectory(destinationFolder);
                filePath = Path.Combine(destinationFolder, fileName);
            }

            await YoutubeDownloader.DownloadAsync(video, filePath, cancellationToken);

            return(filePath);
        }
コード例 #11
0
ファイル: frmMain.cs プロジェクト: sonhuytran/YoutubeToMp3
        private void btnDownloadSelected_Click(object sender, EventArgs ea)
        {
            foreach (YoutubeListView.AudioItem selectedItem in _LstYoutubes.SelectedItems())
            {
                if (selectedItem.DownloadStatus != YoutubeListView.AudioItem.DownloadStatuses.NotDownloaded)
                {
                    continue;
                }

                var    invalidChars = Path.GetInvalidFileNameChars();
                string fixedTitle   = new string(selectedItem._Audio.Title.Where(x => !invalidChars.Contains(x)).ToArray());

                YoutubeDownloader youtubeDownloader = new YoutubeDownloader();
                youtubeDownloader.OnDownloadProgressChanged += (s, e) =>
                {
                    selectedItem.DownloadStatus   = YoutubeListView.AudioItem.DownloadStatuses.Downloading;
                    selectedItem.DownloadProgress = e.ProgressPercentage * 0.5f;
                };
                youtubeDownloader.OnDownloadFailed += (s, ex) =>
                {
                    selectedItem.DownloadStatus = YoutubeListView.AudioItem.DownloadStatuses.Error;
                    MessageBox.Show(String.Format("An error has occured.\n{0}", ex.ToString()),
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                };
                youtubeDownloader.OnDownloadCompleted += (s, video) =>
                {
                    selectedItem.DownloadStatus = YoutubeListView.AudioItem.DownloadStatuses.Converting;

                    FFMpegConverter ffMpeg = new FFMpegConverter();
                    ffMpeg.ConvertProgress += (ss, progress) =>
                    {
                        selectedItem.DownloadProgress = 50 +
                                                        (float)((progress.Processed.TotalMinutes / progress.TotalDuration.TotalMinutes) * 50);
                    };

                    FileStream fileStream = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                                                           + "\\" + fixedTitle + ".mp3", FileMode.Create);

                    ffMpeg.LogReceived += async(ss, log) =>
                    {
                        if (!log.Data.StartsWith("video:0kB"))
                        {
                            return;
                        }

                        Invoke(new MethodInvoker(() =>
                        {
                            selectedItem.DownloadStatus = YoutubeListView.AudioItem.DownloadStatuses.Completed;
                        }));

                        await Task.Delay(1000);

                        fileStream.Close();
                        File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                                    + "\\" + fixedTitle + ".mp4");
                    };

                    new Thread(() => ffMpeg.ConvertMedia(
                                   Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + fixedTitle + ".mp4",
                                   "mp4",
                                   fileStream,
                                   "mp3",
                                   new ConvertSettings {
                        AudioCodec = "libmp3lame", CustomOutputArgs = "-q:a 0"
                    }
                                   )).Start();
                };

                var highestQualityAvailable = selectedItem._Audio.GetHighestQualityTuple();
                youtubeDownloader.DownloadAudioAsync(selectedItem._Audio, highestQualityAvailable.Item1,
                                                     highestQualityAvailable.Item2, Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
                                                     + "\\" + fixedTitle + ".mp4");
            }
        }