示例#1
0
        public AudioTag GetTrackMetadata(TrackFile trackfile)
        {
            var track       = trackfile.Tracks.Value[0];
            var release     = track.AlbumRelease.Value;
            var album       = release.Album.Value;
            var albumartist = album.Artist.Value;
            var artist      = track.ArtistMetadata.Value;

            var    cover     = album.Images.FirstOrDefault(x => x.CoverType == MediaCoverTypes.Cover);
            string imageFile = null;
            long   imageSize = 0;

            if (cover != null)
            {
                imageFile = _mediaCoverService.GetCoverPath(album.Id, MediaCoverEntity.Album, cover.CoverType, cover.Extension, null);
                _logger.Trace($"Embedding: {imageFile}");
                var fileInfo = _diskProvider.GetFileInfo(imageFile);
                if (fileInfo.Exists)
                {
                    imageSize = fileInfo.Length;
                }
                else
                {
                    imageFile = null;
                }
            }

            return(new AudioTag
            {
                Title = track.Title,
                Performers = new[] { artist.Name },
                AlbumArtists = new[] { albumartist.Name },
                Track = (uint)track.AbsoluteTrackNumber,
                TrackCount = (uint)release.Tracks.Value.Count(x => x.MediumNumber == track.MediumNumber),
                Album = album.Title,
                Disc = (uint)track.MediumNumber,
                DiscCount = (uint)release.Media.Count,

                // We may have omitted media so index in the list isn't the same as medium number
                Media = release.Media.SingleOrDefault(x => x.Number == track.MediumNumber).Format,
                Date = release.ReleaseDate,
                Year = (uint)album.ReleaseDate?.Year,
                OriginalReleaseDate = album.ReleaseDate,
                OriginalYear = (uint)album.ReleaseDate?.Year,
                Publisher = release.Label.FirstOrDefault(),
                Genres = album.Genres.Any() ? album.Genres.ToArray() : artist.Genres.ToArray(),
                ImageFile = imageFile,
                ImageSize = imageSize,
                MusicBrainzReleaseCountry = IsoCountries.Find(release.Country.FirstOrDefault())?.TwoLetterCode,
                MusicBrainzReleaseStatus = release.Status.ToLower(),
                MusicBrainzReleaseType = album.AlbumType.ToLower(),
                MusicBrainzReleaseId = release.ForeignReleaseId,
                MusicBrainzArtistId = artist.ForeignArtistId,
                MusicBrainzReleaseArtistId = albumartist.ForeignArtistId,
                MusicBrainzReleaseGroupId = album.ForeignAlbumId,
                MusicBrainzTrackId = track.ForeignRecordingId,
                MusicBrainzReleaseTrackId = track.ForeignTrackId,
                MusicBrainzAlbumComment = album.Disambiguation,
            });
        }
示例#2
0
        private LocalTrack GivenLocalTrack(Track track, AlbumRelease release)
        {
            var fileInfo = Builder <ParsedTrackInfo>
                           .CreateNew()
                           .With(x => x.Title          = track.Title)
                           .With(x => x.CleanTitle     = track.Title.CleanTrackTitle())
                           .With(x => x.AlbumTitle     = release.Title)
                           .With(x => x.Disambiguation = release.Disambiguation)
                           .With(x => x.ReleaseMBId    = release.ForeignReleaseId)
                           .With(x => x.ArtistTitle    = track.ArtistMetadata.Value.Name)
                           .With(x => x.TrackNumbers   = new[] { track.AbsoluteTrackNumber })
                           .With(x => x.DiscCount      = release.Media.Count)
                           .With(x => x.DiscNumber     = track.MediumNumber)
                           .With(x => x.RecordingMBId  = track.ForeignRecordingId)
                           .With(x => x.Country        = IsoCountries.Find("US"))
                           .With(x => x.Label          = release.Label.First())
                           .With(x => x.Year           = (uint)(release.Album.Value.ReleaseDate?.Year ?? 0))
                           .Build();

            var localTrack = Builder <LocalTrack>
                             .CreateNew()
                             .With(x => x.FileTrackInfo = fileInfo)
                             .Build();

            return(localTrack);
        }
 private ParsedTrackInfo GivenParsedTrackInfo(Track track, AlbumRelease release)
 {
     return(Builder <ParsedTrackInfo>
            .CreateNew()
            .With(x => x.Title = track.Title)
            .With(x => x.AlbumTitle = release.Title)
            .With(x => x.Disambiguation = release.Disambiguation)
            .With(x => x.ReleaseMBId = release.ForeignReleaseId)
            .With(x => x.ArtistTitle = track.ArtistMetadata.Value.Name)
            .With(x => x.TrackNumbers = new[] { track.AbsoluteTrackNumber })
            .With(x => x.RecordingMBId = track.ForeignRecordingId)
            .With(x => x.Country = IsoCountries.Find("US"))
            .With(x => x.Label = release.Label.First())
            .With(x => x.Year = (uint)release.Album.Value.ReleaseDate.Value.Year)
            .Build());
 }
示例#4
0
        private readonly IsoCountries iso; // This one is for translating ISO countries.

        /// <summary>
        /// Constructs a new TerrorismController.
        /// </summary>
        /// <param name="database">Database to use</param>
        /// <param name="iso">Iso country converter</param>
        public TerrorismController(Database database, IsoCountries iso)
        {
            this.database = database.NewConnection();
            this.iso      = iso;
        }