Skip to content

Commit

Permalink
Print a more helpful error message when a frame shall be set but no t…
Browse files Browse the repository at this point in the history
…ag exists and --create was not given as argument
  • Loading branch information
rstemmer committed Sep 16, 2022
1 parent 5ec99ca commit 64a3df5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2.1.3 - Print a more helpful error message when a frame shall be set but no tag exists and --create was not given as argument
2.1.2 - Memory leak in crc interface fixed
2.1.1 - Do not append padding bytes at the end of the file
2.1.0 - Partial support for extended header: remove (--rm-exthdr) and add checksum (--add-crc)
Expand Down
38 changes: 24 additions & 14 deletions id3v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,31 @@ int ID3V2_Open(ID3V2 **id3v2, const char *path, bool createtag)
if(id3->header.ID[0] != 'I' || id3->header.ID[1] != 'D' || id3->header.ID[2] != '3')
{
// in case this is a bare mp3 file, just create a new tag
if( (createtag && id3->header.ID[0] == 0xFF && id3->header.ID[1] == 0xFB) // *.mp3 (standard)
|| (createtag && id3->header.ID[0] == 0xFF && id3->header.ID[1] == 0xFA) // *.mp3 (found somewhere)
|| (createtag && id3->header.ID[0] == 0xFF && id3->header.ID[1] == 0xF3) // *.mp3 (found somewhere)
|| (createtag && id3->header.ID[0] == 0xFF && id3->header.ID[1] == 0xFD) ) // *.mp3 (found somewhere)
if( (id3->header.ID[0] == 0xFF && id3->header.ID[1] == 0xFB) // *.mp3 (standard)
|| (id3->header.ID[0] == 0xFF && id3->header.ID[1] == 0xFA) // *.mp3 (found somewhere)
|| (id3->header.ID[0] == 0xFF && id3->header.ID[1] == 0xF3) // *.mp3 (found somewhere)
|| (id3->header.ID[0] == 0xFF && id3->header.ID[1] == 0xFD) ) // *.mp3 (found somewhere)
{
id3->header.ID[0] = 'I';
id3->header.ID[1] = 'D';
id3->header.ID[2] = '3';
id3->header.version_major = 3; // \_ version 2.3.0
id3->header.version_minor = 0; // /
id3->header.flags = 0; // No flags
id3->header.origsize = 0; // No frames
id3->rawmp3 = true; // there was no ID3 Tag before
// Reverse previous attempts to read the ID3 header
fseek(id3->file, 0, SEEK_SET);
if(createtag)
{
id3->header.ID[0] = 'I';
id3->header.ID[1] = 'D';
id3->header.ID[2] = '3';
id3->header.version_major = 3; // \_ version 2.3.0
id3->header.version_minor = 0; // /
id3->header.flags = 0; // No flags
id3->header.origsize = 0; // No frames
id3->rawmp3 = true; // there was no ID3 Tag before
// Reverse previous attempts to read the ID3 header
fseek(id3->file, 0, SEEK_SET);
}
else
{
fprintf(stderr, "Give file does not have an ID3v2 Tag. Use --create if you want to create one.\n");
free(id3->path);
free(id3);
return ID3V2ERROR_NOTSUPPORTED;
}
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ CreateTestMP3
./id3edit --create --force240 --set-release 2018 --outfile $DST $SRC
CheckResult "9df4c22b8b82db833ff7ce99b148c86c"

PrintTest "Edit a frame without --create when no Tag exists \e[1;30m(Issue #25)"
CreateTestMP3
./id3edit --set-name "test" $SRC > /dev/null 2>&1 # An error message should be print
if [[ $? == 0 ]] ; then # And exit failure code should be returned
echo -e "\e[u\e[1;31m✘"
else
cp "$SRC" "$DST"
CheckResult "3064cf73aa8541e96201f8fab55293b2"
fi


PrintHeader "Creating and editing artwork"
CreateTestMP3
Expand Down

0 comments on commit 64a3df5

Please sign in to comment.