diff --git a/app/jobs/zip_download_job.rb b/app/jobs/zip_download_job.rb index 85d9f3e1..009dc823 100644 --- a/app/jobs/zip_download_job.rb +++ b/app/jobs/zip_download_job.rb @@ -46,7 +46,7 @@ def download_all_tracks(album, format, dir) end def track_filename(track, format) - Zaru.sanitize!("#{track.position.to_s.rjust(2, '0')} - #{track.title}.#{extension(format)}") + Zaru.sanitize!("#{track.number} - #{track.title}.#{extension(format)}") end def extension(format) diff --git a/app/models/track.rb b/app/models/track.rb index 33aafce9..ab3a9e09 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -29,6 +29,7 @@ def preview_duration def metadata { track_title: title, + track_number: number, album_title: album.title, artist_name: artist.name } @@ -43,4 +44,8 @@ def transcode def metadata_or_original_changed? title_previously_changed? || attachment_changes['original'].present? end + + def number + position.to_s.rjust(2, '0') + end end diff --git a/app/models/transcode_command.rb b/app/models/transcode_command.rb index 6fdce6ce..ea419f8b 100644 --- a/app/models/transcode_command.rb +++ b/app/models/transcode_command.rb @@ -3,6 +3,7 @@ class TranscodeCommand METADATA_KEYS_VS_ID3V23_TAGS = { track_title: 'TIT2', + track_number: 'TRCK', album_title: 'TALB', artist_name: 'TPE1' }.freeze diff --git a/test/models/track_test.rb b/test/models/track_test.rb index 0b5d127d..170b2a18 100644 --- a/test/models/track_test.rb +++ b/test/models/track_test.rb @@ -90,7 +90,14 @@ class TrackTest < ActiveSupport::TestCase metadata = track.metadata assert_equal track.title, metadata[:track_title] + assert_equal track.number, metadata[:track_number] assert_equal track.album.title, metadata[:album_title] assert_equal track.album.artist.name, metadata[:artist_name] end + + test '#number' do + album = create(:album_with_tracks) + + assert_equal %w[01 02], album.tracks.map(&:number) + end end diff --git a/test/models/transcode_command_test.rb b/test/models/transcode_command_test.rb index cd566b91..8faaf519 100644 --- a/test/models/transcode_command_test.rb +++ b/test/models/transcode_command_test.rb @@ -43,11 +43,17 @@ class TranscodeCommandTest < ActiveSupport::TestCase end test 'adds metadata using ID3v2.3 format' do - metadata = { track_title: 'track-title', album_title: 'album-title', artist_name: 'artist-name' } + metadata = { + track_title: 'track-title', + track_number: 'track-number', + album_title: 'album-title', + artist_name: 'artist-name' + } command_string = TranscodeCommand.new(@input, @output, :mp3v0, metadata).generate assert_contains_pair(command_string, ['-write_id3v2', '1']) assert_contains_pair(command_string, ['-id3v2_version', '3']) assert_contains_pair(command_string, ['-metadata', 'TIT2="track-title"']) + assert_contains_pair(command_string, ['-metadata', 'TRCK="track-number"']) assert_contains_pair(command_string, ['-metadata', 'TALB="album-title"']) assert_contains_pair(command_string, ['-metadata', 'TPE1="artist-name"']) end