コード例 #1
0
        public static bool IsElementExisting(IElement element)
        {
            switch (element.Type)
            {
            case ElementType.Author: return(ServerMusics.Any(a => a.MID == element.MID));

            case ElementType.Album: return(ServerMusics.SelectMany(x => x.Albums).Any(a => a.MID == element.MID));

            case ElementType.Music: return(MusicsInfo.TryFindMusic(element.MID, out XmlNode node));

            case ElementType.Playlist: throw new NotImplementedException();

            default: throw new InvalidOperationException();
            }
        }
コード例 #2
0
        private static TagLib.File AddMusicToindexation(string m, ref int NumberofMusics, Author CurrentArtist, Album CurrentAlbum, ConcurrentBag <Music> musics)
        {
            TagLib.File file;
            if (Path.GetExtension(m) == ".mp3" || Path.GetExtension(m) == ".flac")
            {
                file = TagLib.File.Create(m);
                string Musicname = file.Tag.Title;
                if (Musicname == null)
                {
                    try
                    {
                        Musicname = Path.GetFileNameWithoutExtension(m).Split('-')[1].Remove(0, 1);
                    }
                    catch
                    {
                        Musicname = Path.GetFileNameWithoutExtension(m);
                    }
                }

                Music current = new Music(Musicname, CurrentArtist, CurrentAlbum, m)
                {
                    Format = Path.GetExtension(m),
                    Genre  = file.Tag.Genres,
                    N      = file.Tag.Track,
                    Image  = file.Tag.Pictures.LastOrDefault()?.Data.ToArray()
                };

                if (current.Genre.Length == 0)
                {
                    current.Genre = new string[] { "Unknown" };
                }
                if (MusicsInfo.TryFindMusic(current.MID, out XmlNode node))
                {
                    var a = MusicsInfo.GetMusicInfo(node);
                    current.Rating = a.Rating;
                    current.Tags   = a.Tags;
                }

                NumberofMusics++;
                musics.Add(current);

                Console.Write(".");
                return(file);
            }
            return(null);
        }