コード例 #1
0
ファイル: IndexerUtils.cs プロジェクト: kbalint/Dopamine
        public static TrackInfo Path2TrackInfo(string path, string artworkPrefix)
        {
            var ti = new TrackInfo();

            try
            {
                var fmd = new FileMetadata(path);
                var fi  = new FileInformation(path);

                ti.Path        = path;
                ti.FileName    = fi.NameWithoutExtension;
                ti.MimeType    = fmd.MimeType;
                ti.FileSize    = fi.SizeInBytes;
                ti.BitRate     = fmd.BitRate;
                ti.SampleRate  = fmd.SampleRate;
                ti.TrackTitle  = MetadataUtils.SanitizeTag(fmd.Title.Value);
                ti.TrackNumber = MetadataUtils.SafeConvertToLong(fmd.TrackNumber.Value);
                ti.TrackCount  = MetadataUtils.SafeConvertToLong(fmd.TrackCount.Value);
                ti.DiscNumber  = MetadataUtils.SafeConvertToLong(fmd.DiscNumber.Value);
                ti.DiscCount   = MetadataUtils.SafeConvertToLong(fmd.DiscCount.Value);
                ti.Duration    = Convert.ToInt64(fmd.Duration.TotalMilliseconds);
                ti.Year        = MetadataUtils.SafeConvertToLong(fmd.Year.Value);

                ti.ArtistName = GetFirstArtist(fmd);

                ti.GenreName = GetFirstGenre(fmd);

                ti.AlbumTitle  = string.IsNullOrWhiteSpace(fmd.Album.Value) ? Defaults.UnknownAlbumString : MetadataUtils.SanitizeTag(fmd.Album.Value);
                ti.AlbumArtist = GetFirstAlbumArtist(fmd);

                var dummyAlbum = new Album
                {
                    AlbumTitle  = ti.AlbumTitle,
                    AlbumArtist = ti.AlbumArtist
                };

                IndexerUtils.UpdateAlbumYear(dummyAlbum, MetadataUtils.SafeConvertToLong(fmd.Year.Value));

                IndexerUtils.CacheArtwork(dummyAlbum, ti.Path);
            }
            catch (Exception ex)
            {
                LogClient.Instance.Logger.Error("Error while creating TrackInfo from file '{0}'. Exception: {1}", path, ex.Message);

                // Make sure the file can be opened by creating a TrackInfo with some default values
                ti = new TrackInfo();

                ti.Path     = path;
                ti.FileName = System.IO.Path.GetFileNameWithoutExtension(path);

                ti.ArtistName = Defaults.UnknownArtistString;

                ti.GenreName = Defaults.UnknownGenreString;

                ti.AlbumTitle  = Defaults.UnknownAlbumString;
                ti.AlbumArtist = Defaults.UnknownAlbumArtistString;
            }

            return(ti);
        }
コード例 #2
0
ファイル: IndexingService.cs プロジェクト: kbalint/Dopamine
        private async Task <long> AddArtworkAsync(bool quickArtworkIndexing = true)
        {
            long numberUpdated = 0;

            await Task.Run(() =>
            {
                using (SQLiteConnection conn = this.factory.GetConnection())
                {
                    conn.BeginTransaction();

                    foreach (Album alb in conn.Table <Album>())
                    {
                        try
                        {
                            // Only update artwork if QuickArtworkIndexing is enabled AND there
                            // is no ArtworkID set, OR when QuickArtworkIndexing is disabled.
                            if ((quickArtworkIndexing & string.IsNullOrEmpty(alb.ArtworkID)) | !quickArtworkIndexing)
                            {
                                Track trk = this.GetLastModifiedTrack(alb);

                                if (IndexerUtils.CacheArtwork(alb, trk.Path))
                                {
                                    conn.Update(alb);
                                    numberUpdated += 1;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogClient.Instance.Logger.Error("There was a problem while updating the cover art for Album {0}/{1}. Exception: {2}", alb.AlbumTitle, alb.AlbumArtist, ex.Message);
                        }

                        // Report progress if at least 1 album is added
                        if (numberUpdated > 0)
                        {
                            this.eventArgs.IndexingAction  = IndexingAction.UpdateArtwork;
                            this.eventArgs.ProgressPercent = 0;
                            this.IndexingStatusChanged(this.eventArgs);
                        }
                    }

                    conn.Commit();
                }
            });

            return(numberUpdated);
        }