Esempio n. 1
0
        public static void UpdateSingleTag(Song song)
        {
            try
            {

                using (TagLib.File taglibFile = TagLib.File.Create(song.FileName))
                {
                    if (taglibFile.Tag != null)
                    {
                        if (!string.IsNullOrEmpty(taglibFile.Tag.Title))
                            song.Name = taglibFile.Tag.Title;

                        song.Artist = taglibFile.Tag.JoinedPerformers;
                        song.Duration = (int)taglibFile.Properties.Duration.TotalSeconds;

                        FileInfo fileInfo = new FileInfo(song.FileName);
                        song.DateCreated = fileInfo.CreationTime.ToString("yyyy-MM-dd HH:mm");
                    }
                }
                song.TagRead = true;
                song.ErrorReadingTag = false;
            }
            catch (System.IO.IOException)
            {
                song.TagRead = false;
                song.ErrorReadingTag = true;
            }
            catch (Exception)
            {
                song.TagRead = true;
            }
        }
        public void Enqueue(Song song, string requesterName)
        {
            if (!ClientAllowed(requesterName))
                return;

            int maximalsonginqueue;

            if (!int.TryParse(SongPlayerFactory.GetConfigFile().GetValue("player.maximalsonginqueue"), out maximalsonginqueue))
                maximalsonginqueue = int.MaxValue;

            if (_queue.Count >= maximalsonginqueue)
                return;

            SongLibrary.UpdateSingleTag(song);
            _queue.Add(new RequestedSong { Song = song, RequesterName = requesterName, RequestedDate = DateTime.Now });
        }
        public void Dequeue(Song song, string requesterName)
        {
            if (!ClientAllowed(requesterName))
                return;

            _queue.Remove(song.TempId);
        }
Esempio n. 4
0
 public void AddSong(Song song)
 {
     lock (lockObject)
     {
         _songs.Add(song);
     }
 }
Esempio n. 5
0
        private int ScanSongs()
        {
            int changesMade = 0;
            Config.ConfigFile config = SongPlayerFactory.GetConfigFile();
            string[] directories = config.GetValue("library.path").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string[] extensions = config.GetValue("library.extensions").Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (extensions.Length == 0)
                extensions = new string[] { "mp3" };

            List<string> files = new List<string>();
            foreach (string directory in directories)
            {
                if (Directory.Exists(directory))
                {
                    foreach (string extension in extensions)
                    {
                        files.AddRange(Directory.GetFiles(directory, "*." + extension, SearchOption.AllDirectories).AsEnumerable<string>());
                    }
                }
            }

            //Find removed songs
            lock (lockObject)
            {
                if (_songs.RemoveAll(s => !files.Any(f => f == s.FileName)) > 0)
                    changesMade++;
            }

            //Find added songs
            foreach (string fileName in files)
            {
                lock (lockObject)
                {
                    if (_songs.Any(s => s.FileName == fileName))
                        continue;
                }

                Song song = new Song();
                song.FileName = fileName;
                FileInfo fileInfo = new FileInfo(fileName);
                song.Name = Regex.Replace(fileInfo.Name, @"\" + fileInfo.Extension + "$", string.Empty, RegexOptions.IgnoreCase);

                AddSong(song);

                changesMade++;
            }

            return changesMade;
        }