Exemple #1
0
        public static string FillSongRequest(string requestBody, string songRequestor = "RazBot", bool bypassVet = false)
        {
            SongData songData = YTE.GetSongData(requestBody, requestor: songRequestor);

            if (songData.Duration <= TimeSpan.FromMinutes(10))
            {
                if (BotTools.Settings["vet_requests"] && !bypassVet)
                {
                    DiscordBot.PostVetRequestToDJChannel(songData);
                    return($"@{songData.Requestor}, Your request has been submitted for review! razBot");
                }
                else
                {
                    try
                    {
                        Music.GetPlaylist("request").AddSong(songData);
                        var placement = Music.GetPlaylist("request").Songs.Count;
                        if (DownloadedSong != null && placement == 1)
                        {
                            if (DownloadedSong.IsRequest)
                            {
                                placement++;
                            }
                            else
                            {
                                DownloadedSong = null;
                                GetPlaylist(LoadedPlaylist).CycleBack();
                            }
                        }
                        var placementWord = BotTools.GetPlacementWord(placement);

                        Music.SavePlaylists();
                        return($"@{songData.Requestor}, Your request is {placementWord} in the queue! razCool");
                    }
                    catch (ArgumentException)
                    {
                        BotTools.LogLine($"{songRequestor}'s request rejected: Already in queue");
                        return($"Sorry @{songRequestor}, that request is already queued!");
                    }
                    catch (FormatException e)
                    {
                        BotTools.LogToSessionLogFile(e.ToString());
                        BotTools.LogLine($"{songRequestor}'s request rejected: Bad url");
                        return($"Sorry @{songRequestor}, I can't access a YouTube video from that link! It may not be available in my region, or the url may not be properly formatted.");
                    }
                }
            }
            else
            {
                return($"{songData.Requestor}'s request was rejected: The audio was over 10 minutes long! razS");
            }
        }
Exemple #2
0
        public SongData(string url, string requestor)
        {
            SongData songData = YTE.GetSongData(url, requestor: requestor);

            Description = songData.Description;
            Thumbnails  = songData.Thumbnails;
            Requestor   = songData.Requestor;
            Duration    = songData.Duration;
            Author      = songData.Author;
            Title       = songData.Title;
            URL         = songData.URL;
            ID          = songData.ID;
        }
Exemple #3
0
        public static void QueueNextSong()
        {
            if (BotTools.Settings["random_play"] == true)
            {
                Random rand = new Random();
                var    playlistCandidates = Playlists.Where(p => p.Value.Songs.Count > 0);
                Music.LoadedPlaylist = playlistCandidates.ElementAt(rand.Next(playlistCandidates.Count())).Key;
                BotTools.Settings["loaded_playlist"] = Music.LoadedPlaylist;
                BotTools.SaveSettings();
            }

            DownloadedSong = QueuedSong;
            SongData nextSong = GetPlaylist("request").Songs.Count > 0 ?
                                GetPlaylist("request").GetNext() :
                                GetPlaylist(LoadedPlaylist).GetNext();

            if (nextSong != null)
            {
                QueuedSong = YTE.GetSongData(nextSong.URL, requestor: nextSong.Requestor);
            }
        }
Exemple #4
0
        private void OnLoadButtonClick(object sender, EventArgs e)
        {
            var playlistUrl  = tbUrl.Text.Replace(" ", "");
            var playlistName = tbName.Text;

            tbUrl.Clear();
            tbName.Clear();
            var playlistExists = Music.Playlists.Keys.Contains(playlistName);

            if (!Directory.Exists($"{BotTools.BasePath}\\playlists\\{playlistName}"))
            {
                Directory.CreateDirectory($"{BotTools.BasePath}\\playlists\\{playlistName}");
            }

            if (!playlistExists)
            {
                Music.Playlists[playlistName] = new Playlist();
            }
            YTE.FillPlaylistFromYoutube(playlistUrl, playlistName);
            returnForm.Show();
            returnForm.Location = this.Location;
            this.Hide();
        }
Exemple #5
0
        private async void BackgroundCycleAudioQueue(object sender, DoWorkEventArgs e)
        {
            // Priority 1: Load downloaded song
            try
            {
                if (Music.DownloadedSong != null && Music.LoadedSong == null)
                {
                    Music.LoadedSong     = Music.DownloadedSong;
                    Music.DownloadedSong = null;
                    //windowsMP.URL = Music.LoadedSong.URL;
                    //BotTools.LogLine($"Loaded {Music.LoadedSong.Title}");

                    try
                    {
                        string songID       = Music.LoadedSong.ID;
                        string playlistName = Music.LoadedSong.Requestor == "RazBot" ? Music.LoadedPlaylist : "request";
                        string filePathNorm = $"{BotTools.BasePath}\\playlists\\{playlistName}\\{songID}_Normalized.wav";
                        string filePath     = $"{BotTools.BasePath}\\playlists\\{playlistName}\\{songID}.mp4";

                        windowsMP.URL = File.Exists(filePathNorm) ? filePathNorm : filePath;
                    }
                    catch (NullReferenceException)
                    {
                        BotTools.LogLine($"Failed to play song, skipping...");
                        Music.QueueNextSong();
                    }

                    if (windowsMP.playState != WMPLib.WMPPlayState.wmppsPlaying && !playerStopped && windowsMP.playState != WMPLib.WMPPlayState.wmppsPaused)
                    {
                        try
                        {
                            windowsMP.Ctlcontrols.play();
                        }
                        catch (Exception playErr)
                        {
                            BotTools.LogToSessionLogFile(playErr.ToString());
                        }
                    }
                    else if (windowsMP.playState != WMPLib.WMPPlayState.wmppsPaused)
                    {
                        // Force stop since I can't get autoplay to stay disabled
                        windowsMP.Ctlcontrols.stop();
                    }
                }
                // Priority 2: Downloaded next song
                else if (Music.DownloadedSong == null && !downloadingAudio)
                {
                    if (BotTools.Settings["random_play"] == true)
                    {
                        Random rand = new Random();
                        var    playlistCandidates = Music.Playlists.Where(p => p.Value.Songs.Count > 0);
                        Music.LoadedPlaylist = playlistCandidates.ElementAt(rand.Next(playlistCandidates.Count())).Key;
                        BotTools.Settings["loaded_playlist"] = Music.LoadedPlaylist;
                    }

                    SongData nextSong = Music.GetPlaylist("request").Songs.Count > 0 ?
                                        Music.GetPlaylist("request").GetNext() :
                                        Music.GetPlaylist(Music.LoadedPlaylist).GetNext();

                    if (nextSong != null)
                    {
                        Music.QueuedSong = YTE.GetSongData(nextSong.URL, requestor: nextSong.Requestor);

                        downloadProgress = 0.0;
                        downloadingAudio = true;
                        var progress = new Progress <double>(percent =>
                        {
                            downloadProgress = percent;
                        });

                        Music.DownloadedSong = await YTE.DownloadAudio(Music.QueuedSong, progress);

                        Music.QueuedSong = null;
                        downloadingAudio = false;
                        while (bgwAudioNormalizer.IsBusy)
                        {
                            ;
                        }
                        if (cbNormalize.Checked && Music.DownloadedSong != null)
                        {
                            bgwAudioNormalizer.RunWorkerAsync();
                        }
                    }
                }
            }
            catch (Exception comExc)
            {
                BotTools.LogLine("Exception written to session log file");
                BotTools.LogToSessionLogFile(comExc.ToString());
            }
        }