Skip to content

Commit

Permalink
Better Tag-version management
Browse files Browse the repository at this point in the history
  • Loading branch information
rstemmer committed Aug 15, 2018
1 parent 64c596f commit 0fef57f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2.0.3 - Tag version number changes are more obvious now. Only --force2?0 changes it at the beginning of execution.
2.0.2 - Fixed a possible bug: For ID3v2.4.0 tags all text frames store NULL-terminated strings
2.0.1 - Fixed a critical bug: The frame size en/decoding was not ID3v2.4.0 compatible
2.0.0 - Lots of new features and fixes:
Expand Down
21 changes: 10 additions & 11 deletions id3v2frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ int ID3V2_SetTextFrame(ID3V2 *id3v2, unsigned int ID, const char *utf8text, unsi
size_t textbufferlimit = textlength * 4; // 4 time the uft-8 encoded size is enough
unsigned char version = id3v2->header.version_major;

// Track and update version number
// Check version number
if(encoding == ID3V2TEXTENCODING_UTF16_BE || encoding == ID3V2TEXTENCODING_UTF8)
{
version = 4; // the used encoding is only allows in ID3v2.4.0
if(version == 3)
return ID3V2ERROR_UNSUPPORTEDENCODING;
}

// Allocate memory for encoded text
Expand Down Expand Up @@ -105,9 +106,6 @@ int ID3V2_SetTextFrame(ID3V2 *id3v2, unsigned int ID, const char *utf8text, unsi
return error;
}

// Update ID3 version
id3v2->header.version_major = version; // the used encoding is only allows in ID3v2.4.0

// done
free(rawtext);
free(framedata);
Expand Down Expand Up @@ -268,6 +266,13 @@ int ID3V2_SetPictureFrame(ID3V2 *id3v2, unsigned char pictype,
{
int error;

// Check if encoding is supported
if(encoding == ID3V2TEXTENCODING_UTF16_BE || encoding == ID3V2TEXTENCODING_UTF8)
{
if(id3v2->header.version_major == 3)
return ID3V2ERROR_UNSUPPORTEDENCODING;
}

// Encode description
char rawdescdata[ID3V2_MAXPICTUREDESCRIPTIONSIZE];
size_t rawdescsize;
Expand Down Expand Up @@ -356,12 +361,6 @@ int ID3V2_SetPictureFrame(ID3V2 *id3v2, unsigned char pictype,
return error;
}

// Update ID3 version
if(encoding == ID3V2TEXTENCODING_UTF16_BE || encoding == ID3V2TEXTENCODING_UTF8)
{
id3v2->header.version_major = 4; // the used encoding is only allows in ID3v2.4.0
}

// done
free(framedata);
return ID3V2ERROR_NOERROR;
Expand Down
19 changes: 10 additions & 9 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <printhex.h>
#include <stdbool.h>

#define VERSION "2.0.2"
#define VERSION "2.0.3"

int CopyArgument(char **dst, char *src);
int ProcessSetArgument(ID3V2 *id3v2, unsigned int ID, const char *argument, unsigned char encoding);
Expand Down Expand Up @@ -104,9 +104,10 @@ void PrintUsage()
printf("\n");

printf("\e[1;31m ³ \e[1;33mIt is up to you to make sure all frames are conform to that version of the standard!\e[0m\n");
printf("\e[1;30m ID3v2.3.0 only allows UTF-16+BOM or ISO8859-1 encoded text.\e[0m\n");
printf("\e[1;30m Some frame IDs are different! (use --get-framelist to check the new file)\e[0m\n");
printf("\e[1;33m There are many differences in the details of ID3v2.3.0 and ID3v2.4.0!\e[0m\n");
printf("\e[1;34m You better only use it in the following combination: \e[1;36m--clear --create --force240\e[1;34m.\e[0m\n");
printf("\e[1;30m ID3v2.3.0 only allows UTF-16+BOM or ISO8859-1 encoded text.\e[0m\n");
printf("\e[1;30m Some frame IDs are different! (use --get-frames to check the new file)\e[0m\n");
printf("\n");

// Some warnings
Expand Down Expand Up @@ -251,6 +252,10 @@ int main(int argc, char *argv[])
// Process program arguments
unsigned char encoding = ID3V2TEXTENCODING_UTF16_BOM; // default ID3v2.3.0 encoding

// Force ID3 version
if(force230) id3v2->header.version_major = 3; // ID3v2.3.0
if(force240) id3v2->header.version_major = 4; // ID3v2.4.0

if(codename) if(GetEncoding(codename, &encoding) != 0) goto exit;
if(getframelist) if(ShowFramelist(id3v2) != 0) goto exit;
if(dumpframe) if(DumpFrame(id3v2, dumpframe) != 0) goto exit;
Expand Down Expand Up @@ -291,11 +296,11 @@ int main(int argc, char *argv[])
if(ProcessSetArgument(id3v2, 'TPOS', newcdnr, encoding) != 0) goto exit;
if(ProcessSetArgument(id3v2, 'APIC', newartwork, encoding) != 0) goto exit;
// Version depending tags
if(id3v2->header.version_major == 3 || force230)
if(id3v2->header.version_major == 3)
{
if(ProcessSetArgument(id3v2, 'TYER', newrelease, encoding) != 0) goto exit;
}
else if(id3v2->header.version_major == 4 || force240)
else if(id3v2->header.version_major == 4)
{
if(ProcessSetArgument(id3v2, 'TDRC', newrelease, encoding) != 0) goto exit;
}
Expand All @@ -307,10 +312,6 @@ int main(int argc, char *argv[])
altpath = "/dev/null"; // if ID3V2_Close sees /dev/null, nothing will be stored
}

// Force ID3 version
if(force230) id3v2->header.version_major = 3; // ID3v2.3.0
if(force240) id3v2->header.version_major = 4; // ID3v2.4.0

error = ID3V2_Close(id3v2, altpath, striptag);
if(error)
{
Expand Down
20 changes: 9 additions & 11 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -155,32 +155,30 @@ PrintTest "Try replacing Text Frame with read-only flag"
CheckResult "bff0a4da32a384cd333fcb9f02c051bd"

PrintTest "Set UTF-16+BOM encoded Text Frame"
./id3edit --create --set-name "This is a test 😈" --outfile $DST $SRC
./id3edit --encoding UTF-16 --set-name "This is a test 😈" $DST
./id3edit --create --force230 --encoding UTF-16 --set-name "This is a test 😈" --outfile $DST $SRC
CheckResult "b094b92ff7873618aebcc819d8b36355"

PrintTest "Set UTF-16BE encoded Text Frame"
./id3edit --encoding UTF-16BE --set-name "This is a test 😈" $DST
./id3edit --create --force240 --encoding UTF-16BE --set-name "This is a test 😈" $DST
CheckResult "2b7c1017135093c1ff5254892f168fe3"

PrintTest "Set UTF-8 encoded Text Frame"
./id3edit --encoding UTF-8 --set-name "This is a test 😈" $DST
./id3edit --create --force240 --encoding UTF-8 --set-name "This is a test 😈" $DST
CheckResult "f0828dbcabae5e872e9a288679983c30"

PrintTest "Set ISO 8859-1 encoded Text Frame"
./id3edit --encoding ISO8859-1 --set-name "This is ä test" $DST
CheckResult "ea6b1c47b63774e7249b523f038afcad"
./id3edit --create --force230 --encoding ISO8859-1 --set-name "This is ä test" $DST
CheckResult "9e70607b0f04673ccd6bdb300c69dea9"

PrintTest "Set release year for ID3v2.3.0"
CreateTestMP3
./id3edit --create --force230 --set-name "Release Test" --outfile $DST $SRC
./id3edit --set-release 2018 $DST
CheckResult "a2b6e5f4f3bbc04e3fb063d3d59eb7d2"
./id3edit --create --force230 --set-release 2018 --outfile $DST $SRC
CheckResult "03b4980f51eec9d5f28f0007934c3f62"

PrintTest "Set release year for ID3v2.4.0"
CreateTestMP3
./id3edit --create --force240 --outfile $DST $SRC
./id3edit --set-release 2018 $DST
./id3edit --create --force240 --set-release 2018 --outfile $DST $SRC
#./id3edit --set-release 2018 $DST
CheckResult "1c46724c696900e093516b01574b0349"


Expand Down

0 comments on commit 0fef57f

Please sign in to comment.