Beispiel #1
0
        public static void QueueRandomSong()
        {
            var files = Directory.GetFiles(Program.Configuration.MusicPath, "*.mp3", SearchOption.AllDirectories)
                        .Where(r => !MasterQueue.Any(s => s.Name == Path.GetFileNameWithoutExtension(r))).ToArray();

            QueueSong(files[Random.Next(files.Length)]);
        }
Beispiel #2
0
        /// <summary>
        /// Returns true if the user can request another song.
        /// </summary>
        public static bool QueueUserSong(string mp3, string user, out Song song)
        {
            var file     = new AudioFile(mp3);
            var duration = file.Properties.Duration;

            song = new Song
            {
                Name      = Path.GetFileNameWithoutExtension(mp3),
                Stream    = "/" + Path.GetFileName(mp3),
                Download  = "/download/" + Path.GetFileName(mp3),
                Duration  = duration,
                UserAdded = true
            };
            var name = song.Name;

            if (MasterQueue.Any(s => s.Name == name))
            {
                return(true);
            }
            if (!UserRequests.ContainsKey(user))
            {
                UserRequests[user] = new List <DateTime>();
                UserRequests[user].Add(DateTime.Now);
            }
            else
            {
                foreach (var item in UserRequests[user].ToArray())
                {
                    if (item.AddMinutes(Program.Configuration.RequestLimitResetMinutes) < DateTime.Now)
                    {
                        UserRequests[user].Remove(item);
                    }
                }
                if (UserRequests[user].Count >= Program.Configuration.MaximumRequestsPerUser)
                {
                    return(false);
                }
                UserRequests[user].Add(DateTime.Now);
            }
            UserQueue.Enqueue(song);
            return(UserRequests[user].Count < Program.Configuration.MaximumRequestsPerUser);
        }
Beispiel #3
0
 public void Start()
 {
     masterQ = FindObjectOfType <MasterQueue>();
 }