Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement AUDIO header #951

Merged
merged 5 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/base/UFiles.pas
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ function SaveSong(const Song: TSong; const Tracks: array of TLines; const Name:
if Song.Year <> 0 then SongFile.WriteLine('#YEAR:' + IntToStr(Song.Year));
if Song.Creator <> '' then SongFile.WriteLine('#CREATOR:' + EncodeToken(Song.Creator));

SongFile.WriteLine('#MP3:' + EncodeToken(Song.Mp3.ToUTF8));
if Song.FormatVersion.MinVersion(1,1,0) then
SongFile.WriteLine('#AUDIO:' + EncodeToken(Song.Mp3.ToUTF8));
if Song.FormatVersion.MaxVersion(2,0,0) then
barbeque-squared marked this conversation as resolved.
Show resolved Hide resolved
SongFile.WriteLine('#MP3:' + EncodeToken(Song.Mp3.ToUTF8));

if Song.Cover.IsSet then SongFile.WriteLine('#COVER:' + EncodeToken(Song.Cover.ToUTF8));
if Song.Background.IsSet then SongFile.WriteLine('#BACKGROUND:' + EncodeToken(Song.Background.ToUTF8));
if Song.Video.IsSet then SongFile.WriteLine('#VIDEO:' + EncodeToken(Song.Video.ToUTF8));
Expand Down
55 changes: 46 additions & 9 deletions src/base/USong.pas
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,28 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean)
end;
end;

{**
* Updates the Audio file of the song (MP3 field) to a file witn given filename.
barbeque-squared marked this conversation as resolved.
Show resolved Hide resolved
* Updates the Done flags to identify that the audio resource is set.
* If no file with the given name exists, an error is logged.
*}
procedure CheckAndSetAudioFile(const filename: string);
var
filePath: IPath;
begin
filePath := DecodeFilename(filename);
if (Self.Path.Append(filePath).IsFile) then
begin
self.Mp3 := filePath;
//Add Audio Flag to Done
Done := Done or 4;
end
else
begin
Log.LogError('Can''t find audio file in song: ' + DecodeStringUTF8(FullFileName, Encoding));
end;
end;

begin
Result := true;
Done := 0;
Expand Down Expand Up @@ -1061,20 +1083,35 @@ function TSong.ReadTXTHeader(SongFile: TTextFileStream; ReadCustomTags: Boolean)
Done := Done or 2;
end;

//MP3 File
if (TagMap.TryGetData('MP3', Value)) then
// Audio File
// The new AUDIO header was introduced in format 1.1.0 and replaces MP3 (deprecated)
TheNailDev marked this conversation as resolved.
Show resolved Hide resolved
// For older format versions the audio file is found in the MP3 header
if self.FormatVersion.MinVersion(1,1,0) then
begin
RemoveTagsFromTagMap('MP3');
EncFile := DecodeFilename(Value);
if (Self.Path.Append(EncFile).IsFile) then
if TagMap.TryGetData('AUDIO', Value) then
begin
self.Mp3 := EncFile;
//Add Mp3 Flag to Done
Done := Done or 4;
RemoveTagsFromTagMap('AUDIO');
// If AUDIO is present MP3 should be ignored
if TagMap.IndexOf('MP3') > -1 then
begin
Log.LogInfo('The AUDIO header overwrites the MP3 header in file ' + FullFileName, 'TSong.ReadTXTHeader');
barbeque-squared marked this conversation as resolved.
Show resolved Hide resolved
RemoveTagsFromTagMap('MP3', false);
end;
CheckAndSetAudioFile(Value);
end
else
begin
Log.LogError('Can''t find audio file in song: ' + DecodeStringUTF8(FullFileName, Encoding));
Result := false;
Log.LogError('Missing AUDIO header (mandatory for format >= 1.1.0) ' + FullFileName);
Exit;
end;
end
else
begin
if TagMap.TryGetData('MP3', Value) then
begin
RemoveTagsFromTagMap('MP3');
CheckAndSetAudioFile(Value);
end;
end;

Expand Down
Loading