示例#1
0
        public async Task Music(CommandContext ctx, [Description("Name")] params string[] name)
        {
            var _interactivity = ctx.Client.GetInteractivity();
            var query          = string.Join(" ", name);
            var musics         = await GetMusic.SearchMusic(query).ConfigureAwait(false);

            if (musics == null)
            {
                await ctx.Channel.SendMessageAsync("Music not found!");

                return;
            }

            var musicInfo = MusicEmbedBuilder.GenerateDescriptionMessage(musics);
            var message   = await ctx.Channel.SendMessageAsync(musicInfo).ConfigureAwait(false);

            await MusicEmbedBuilder.AddEmotions(ctx.Client, message);

            var interactive = await _interactivity
                              .WaitForReactionAsync(x => x.User == ctx.User)
                              .ConfigureAwait(false);

            var indexOfMusic = CheckUserChoose.CheckInteractivity(interactive);
            var musicEmbed   = MusicEmbedBuilder.GenerateMusicEmbed(musics[indexOfMusic]);
            await ctx.Channel.SendMessageAsync(embed : musicEmbed).ConfigureAwait(false);
        }
示例#2
0
        public static async Task <string> GetMusicVideo(string videoId, ChromiumWebBrowser youtubePlayer)
        {
            //use video id to get the song
            VideoId = videoId;

#if OFFLINE_IMPLEMENTED
            if (!FilePaths.InCache())
            {
                Console.WriteLine("Video not in cache; video is downloading now");
                return(await GetMusic.DownloadVideo(youtubePlayer));
            }
            // Client
            var client    = new YoutubeClient();
            var videoInfo = await client.GetVideoInfoAsync(VideoId);

            // Print metadata
            // Console.WriteLine($"Id: {videoInfo.Id} | Title: {videoInfo.Title} | Author: {videoInfo.Author.Title}");
            var fullName = videoInfo.Title;
            //code for the video library api
            var saveName = FilePaths.RemoveIllegalPathCharacters(fullName.Replace("- YouTube", ""));
            saveName = saveName.Replace("_", "");
            string savePath = Path.Combine(FilePaths.SaveLocation(),
                                           (saveName));

            return(savePath);
#endif
            return(await DownloadVideo(youtubePlayer));
        }
示例#3
0
        /// <summary>
        ///     Gets the song
        /// </summary>
#if OFFLINE_IMPLEMENTED
        public static async Task PlaySpecifiedSong(System.Windows.Shapes.Rectangle backgroundRect, MediaElement mediaElement,
                                                   string musicLink, int index, string songTitle, Label songLabel, ChromiumWebBrowser youtubePlayer)
        {
            songLabel.Content    = "Now Playing: " + songTitle;
            MusicPanel.IsPlaying = true;
            MusicPanel.SetIndex(index);
            if (GetMusic.IsConverting)
            {
                GetMusic.FFMpeg.Stop();
            }
            //songLabel.Content = "Loading...";
            Console.WriteLine("Music links: " + musicLink + " " + VideoId);
            //TODO: test for possible issue
            var fullSavePath = await GetMusicVideo(musicLink, youtubePlayer);

            ///<summary>Set the background</summary>
            var fileName = SongThumb.GetSongThumb(
                QueryVideo.SongSearchListResponse.Items[MusicPanel.GetIndex()].Snippet.Thumbnails.High.Url,
                Path.GetFileNameWithoutExtension(fullSavePath));
            var image        = System.Drawing.Image.FromFile(fileName);
            var blur         = new GaussianBlur(image as Bitmap);
            var blurredThumb = blur.Process(50);

            image.Dispose();
            var hBitmap = blurredThumb.GetHbitmap();
            var backgroundImageBrush = new ImageBrush();

            backgroundImageBrush.ImageSource = Imaging.CreateBitmapSourceFromHBitmap(hBitmap,
                                                                                     IntPtr.Zero,
                                                                                     Int32Rect.Empty,
                                                                                     BitmapSizeOptions.FromEmptyOptions()
                                                                                     );
            DeleteObject(hBitmap);
            blurredThumb.Dispose();
            backgroundImageBrush.Stretch = Stretch.UniformToFill;
            backgroundRect.Fill          = backgroundImageBrush;
            backgroundRect.Effect        = null;
            mediaElement.Opacity         = 100;


            var saveName = Path.GetFileName(fullSavePath);

            Console.WriteLine("Save name variable in PlaySpecifiedSong method " + saveName);
            try
            {
                var mp4SaveName = saveName.Replace(".webm", ".mp4");

                fullSavePath = Path.Combine(FilePaths.SaveLocation(), mp4SaveName);
                //Console.WriteLine(fullSavePath);
                if (saveName.Contains(".webm") && !File.Exists(fullSavePath))
                {
                    songLabel.Content = "Converting...";
                    await GetMusic.ConvertWebmToMp4(Path.Combine(FilePaths.SaveLocation(),
                                                                 saveName), mp4SaveName);

                    mediaElement.Source = new Uri(fullSavePath);
                }
                else
                {
                    mediaElement.Source = new Uri(fullSavePath);
                }
            }
            catch (NullReferenceException nullReferenceException)
            {
                Console.WriteLine("Some how fullSavePath was not a file path...");
            }


            Console.WriteLine(mediaElement.Source.ToString());
            ///<summary>Renable this when coding in the offline mode</summary>
            ///
            //mediaElement.Play();
        }