コード例 #1
0
        private void GetTokens(string fullName, string extension)
        {
            string genre = "", catalog = "", media = "", artist, album = "", title, file, path, t1;
            int    l;

            try
            {
                #region Path
                l    = fullName.LastIndexOf("\\");
                path = fullName.Substring(0, l);
                #endregion

                #region File
                string   container = Helpers.GetContainer(fullName);
                string[] ar        = container.Split('\\');
                file = ar[ar.Length - 1];
                #endregion

                #region Album
                if (ar[4] == "_Various Artists")
                {
                    album = ar[5];
                }
                else
                {
                    album = ar[5];
                }
                #endregion

                #region Artist
                t1     = $" - ";
                l      = l = file.IndexOf(t1);
                artist = file.Substring(0, l);
                #endregion

                #region Title
                t1    = $" - ";
                l     = l = file.IndexOf(t1);
                title = file.Substring(l + t1.Length).Replace(extension, "");
                #endregion

                #region Genre
                var genreList = GenreList.Instance;
                var genres    = genreList.Get();

                foreach (var g in genres)
                {
                    if (fullName.IndexOf(g) > -1)
                    {
                        genre = g;
                        break;
                    }
                }
                #endregion

                #region Catalog
                var catalogList = CatalogList.Instance;
                var catalogs    = catalogList.Get();

                foreach (var c in catalogs)
                {
                    if (fullName.IndexOf(c) > -1)
                    {
                        catalog = c;
                        break;
                    }
                }
                #endregion

                #region Media
                var mediaList = MediaList.Instance;
                var medias    = mediaList.Get();

                foreach (var m in medias)
                {
                    if (fullName.IndexOf($"\\{m}\\") > -1)
                    {
                        media = m;
                        break;
                    }
                }
                #endregion

                FileInfo fi = new FileInfo(fullName);

                SongRecord songRecord = new SongRecord()
                {
                    Album    = album,
                    Artist   = artist,
                    Catalog  = DataGetSet.GetCatalogId(catalog),
                    FileName = file,
                    Genre    = DataGetSet.GetGenreId(genre),
                    Media    = DataGetSet.GetMediaId(media),
                    Path     = path,
                    Titel    = title,
                    MD5      = Helpers.MD5($"{path}\\{file}"),
                    FileDate = File.GetLastWriteTime(fullName),
                    FileSize = Convert.ToInt32(fi.Length),
                };
                songRecords.Add(songRecord);
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
                Debug.Print($"{fullName}");
            }
        }