Ejemplo n.º 1
0
        private void AcquireAndPlay(Song song)
        {
            CurrentSong = song;
            IEnumerable <VideoInfo> infos = DownloadUrlResolver.GetDownloadUrls(song.Url);
            VideoInfo video = infos.OrderByDescending(info => info.AudioBitrate).FirstOrDefault();

            if (video != null)
            {
                var downloadingMsg = MusicTextChannel.SendMessageAsync("Downloading...").Result;
                if (video.RequiresDecryption)
                {
                    DownloadUrlResolver.DecryptDownloadUrl(video);
                }
                string videoFile       = Misaki.TempPath + Extensions.CleanFileName(song.Title + video.VideoExtension);
                string audioFile       = Misaki.TempPath + Extensions.CleanFileName(song.Title + ".mp3");
                var    videoDownloader = new VideoDownloader(video, videoFile);
                videoDownloader.Execute();
                Process process = new Process();
                process.StartInfo.FileName = Misaki.FfmpegPath + "ffmpeg.exe";
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;
                process.StartInfo.Arguments       = $"-i \"{videoFile}\" \"{audioFile}\"";
                process.StartInfo.UseShellExecute = false;
                process.StartInfo.CreateNoWindow  = true;
                process.Start();
                process.WaitForExit();
                process.Close();
                File.Delete(videoFile);
                downloadingMsg.DeleteAsync().GetAwaiter();
                new Task(() => PlayFile(audioFile)).Start();
            }
        }
Ejemplo n.º 2
0
        public void AddToQueue(string song)
        {
            var result = GetBestResult(song.Split(' ')).Result;

            if (result == null)
            {
                MusicTextChannel.SendMessageAsync("Could not find song!");
                return;
            }
            Queue.Add(new Song()
            {
                Title = result.Snippet.Title,
                Url   = $"https://www.youtube.com/watch?v={result.Id.VideoId}"
            });
            if (Queue.Count == 1 && CurrentState == AudioState.Playing && CurrentSong == null)
            {
                PlayNext();
            }
        }