Example #1
0
        public TrackFile MoveTrackFile(TrackFile trackFile, Artist artist)
        {
            var tracks      = _trackService.GetTracksByFileId(trackFile.Id);
            var album       = _albumService.GetAlbum(trackFile.AlbumId);
            var newFileName = _buildFileNames.BuildTrackFileName(tracks, artist, album, trackFile);
            var filePath    = _buildFileNames.BuildTrackFilePath(artist, album, newFileName, Path.GetExtension(trackFile.Path));

            EnsureTrackFolder(trackFile, artist, album, filePath);

            _logger.Debug("Renaming track file: {0} to {1}", trackFile, filePath);

            return(TransferFile(trackFile, artist, tracks, filePath, TransferMode.Move));
        }
Example #2
0
        private IEnumerable <RenameTrackFilePreview> GetPreviews(Artist artist, List <Track> tracks, List <TrackFile> files)
        {
            foreach (var f in files)
            {
                var file          = f;
                var tracksInFile  = tracks.Where(e => e.TrackFileId == file.Id).ToList();
                var trackFilePath = file.Path;

                if (!tracksInFile.Any())
                {
                    _logger.Warn("File ({0}) is not linked to any tracks", trackFilePath);
                    continue;
                }

                var album = _albumService.GetAlbum(tracksInFile.First().AlbumId);

                var newName = _filenameBuilder.BuildTrackFileName(tracksInFile, artist, album, file);
                var newPath = _filenameBuilder.BuildTrackFilePath(artist, album, newName, Path.GetExtension(trackFilePath));

                if (!trackFilePath.PathEquals(newPath, StringComparison.Ordinal))
                {
                    yield return(new RenameTrackFilePreview
                    {
                        ArtistId = artist.Id,
                        AlbumId = album.Id,
                        TrackNumbers = tracksInFile.Select(e => e.AbsoluteTrackNumber).ToList(),
                        TrackFileId = file.Id,
                        ExistingPath = artist.Path.GetRelativePath(file.Path),
                        NewPath = artist.Path.GetRelativePath(newPath)
                    });
                }
            }
        }
Example #3
0
 private string BuildTrackSample(List <Track> tracks, Artist artist, Album album, TrackFile trackFile, NamingConfig nameSpec)
 {
     try
     {
         return(_buildFileNames.BuildTrackFileName(tracks, artist, album, trackFile, nameSpec, _preferredWords));
     }
     catch (NamingFormatException)
     {
         return(string.Empty);
     }
 }