Skip to content

Commit

Permalink
Use TORY/DATE tags for release year
Browse files Browse the repository at this point in the history
Our best understanding is that the MP3 ID3 tag TORY[1] should be used to
store the *year* (i.e. as a 4-digit number) the music was
released. The convention for FLAC tags seems to have even less
consensus/real-world usage, so for simplicity in the code, we've
decided to use the four digit year in the DATE tag.

[1] https://community.mp3tag.de/t/how-do-i-add-the-tag-for-when-my-music-was-released/55319

Co-authored-by: James Mead <[email protected]>
  • Loading branch information
chrislo and floehopper committed Oct 3, 2024
1 parent e255eeb commit 633df3f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/models/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def metadata
artist_name: artist.name
}

data[:release_date] = album.released_on if album.released_on
data[:release_year] = album.released_on.year if album.released_on
data
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/transcode_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class TranscodeCommand
track_number: 'TRCK',
album_title: 'TALB',
artist_name: 'TPE1',
release_date: 'DATE'
release_year: 'TORY'
}.freeze

METADATA_KEYS_VS_FLAC_TAGS = {
track_title: 'TITLE',
track_number: 'TRACKNUMBER',
album_title: 'ALBUM',
artist_name: 'ARTIST',
release_date: 'DATE'
release_year: 'DATE'
}.freeze

def initialize(input, output, format, metadata = {}, image = nil)
Expand Down
8 changes: 4 additions & 4 deletions test/jobs/transcode_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TranscodeJobTest < ActiveJob::TestCase
end

test 'it adds metadata to the generated MP3 file' do
album = create(:album, released_on: Time.zone.today)
album = create(:album, released_on: Date.parse('2024-10-03'))
track = create(:track, album:)
TranscodeJob.perform_now(track)

Expand All @@ -66,12 +66,12 @@ class TranscodeJobTest < ActiveJob::TestCase
assert_equal '01', metadata['format']['tags']['track']
assert_equal album.title, metadata['format']['tags']['album']
assert_equal album.artist.name, metadata['format']['tags']['artist']
assert_equal album.released_on.to_s, metadata['format']['tags']['date']
assert_equal '2024', metadata['format']['tags']['TORY']
end
end

test 'it adds metadata to the generated flac file' do
album = create(:album, released_on: Time.zone.today)
album = create(:album, released_on: Date.parse('2024-10-03'))
track = create(:track, album:)
TranscodeJob.perform_now(track, format: :flac)

Expand All @@ -84,7 +84,7 @@ class TranscodeJobTest < ActiveJob::TestCase
assert_equal '01', metadata['format']['tags']['track']
assert_equal album.title, metadata['format']['tags']['ALBUM']
assert_equal album.artist.name, metadata['format']['tags']['ARTIST']
assert_equal album.released_on.to_s, metadata['format']['tags']['DATE']
assert_equal '2024', metadata['format']['tags']['DATE']
end
end
end
2 changes: 1 addition & 1 deletion test/models/track_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class TrackTest < ActiveSupport::TestCase

metadata = track.metadata

assert_equal track.album.released_on, metadata[:release_date]
assert_equal track.album.released_on.year, metadata[:release_year]
end

test '#number' do
Expand Down
8 changes: 4 additions & 4 deletions test/models/transcode_command_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class TranscodeCommandTest < ActiveSupport::TestCase
track_number: 'track-number',
album_title: 'album-title',
artist_name: 'artist-name',
release_date: 'release-date'
release_year: 'release-year'
}
command_string = TranscodeCommand.new(@input, @output, :mp3v0, metadata).generate
assert_contains_pair(command_string, ['-write_id3v2', '1'])
Expand All @@ -57,7 +57,7 @@ class TranscodeCommandTest < ActiveSupport::TestCase
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"'])
assert_contains_pair(command_string, ['-metadata', 'DATE="release-date"'])
assert_contains_pair(command_string, ['-metadata', 'TORY="release-year"'])
end

test 'adds metadata tags for FLAC format' do
Expand All @@ -66,14 +66,14 @@ class TranscodeCommandTest < ActiveSupport::TestCase
track_number: 'track-number',
album_title: 'album-title',
artist_name: 'artist-name',
release_date: 'release-date'
release_year: 'release-year'
}
command_string = TranscodeCommand.new(@input, @output, :flac, metadata).generate
assert_contains_pair(command_string, ['-metadata', 'TITLE="track-title"'])
assert_contains_pair(command_string, ['-metadata', 'TRACKNUMBER="track-number"'])
assert_contains_pair(command_string, ['-metadata', 'ALBUM="album-title"'])
assert_contains_pair(command_string, ['-metadata', 'ARTIST="artist-name"'])
assert_contains_pair(command_string, ['-metadata', 'DATE="release-date"'])
assert_contains_pair(command_string, ['-metadata', 'DATE="release-year"'])
end

test 'transcodes audio to mp3 using libmp3lame codec highest audio quality' do
Expand Down

1 comment on commit 633df3f

@floehopper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.