Skip to content

Commit

Permalink
Encodings complete, updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
BillisC committed Aug 16, 2021
1 parent 2644a4e commit 9d6e10a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ For a full list of genres see this: https://en.wikipedia.org/wiki/ID3#standard (
- ```processTags()``` is the main function that must be called before all else. Returns false if file / tag doesn't exist or if there is compression detected in the header flags.
- ```set("Frame's name", "Frame's value")``` sets the specified tag with the value you provide. Parameters have to be strings. Returns false when file / tag / frame doesn't exist.
- ```get("Frame's name")``` Prints the content of the specified tag. Parameter has to be a string. Returns false when file / tag / frame doesn't exist.
- ```getImage(imageSize)``` Returns a pointer to image's raw data. Parameter is an int that's gonna hold the image size once the function finishes. Returns nullptr when file / tag / frame doesn't exist.
- ```getImage(imageSize)``` Returns a char pointer to image's raw data. Parameter is an int that's gonna hold the image size once the function finishes. Returns nullptr when file / tag / frame doesn't exist.
- ```remove("Frame's name")``` removes the specified tag. Parameter has to be a string. Returns false when file / tag / frame doesn't exist.
- ```removeAll()``` removes the whole ID3 tag. Returns false when file / tag doesn't exist.

Expand All @@ -63,6 +63,8 @@ The frame names for ID3v2.4 can be found there: https://id3.org/id3v2.4.0-frames
int ID3v2::_DefaultVersion = 4;
```
If a wrong version value is inserted then the default will stay at v2.3.
- **Important:** If you want to set the picture frame (**"PIC"** / **"APIC"**) then in the content parameter you have to provide the image's path. Also in the `getImage(imageSize)` function it's recommended that you initialize the int with the value `0`;
- The only allowed frames that can be read / set on v2 (for now) are all the Text Information Frames (excluding **"TXXX"** and **"TXX"**), the **"APIC"** / **"PIC"** image frame (through `getImage(imageSize)`), the **"COMM"** / **"COM"** comment frame and all the URL Link Frames (excluding **"WXXX"** and **"WXX"**).
- This library won't support unsynchronization because it's no longer needed.
- **Important:** If you want to set the picture frame (**"PIC"** / **"APIC"**) then in the content parameter you have to provide the image's path. Also in the `getImage(imageSize)` function it's recommended that you initialize the int with the value `0`;
- **Important:** The only allowed frames that can be read / set on v2 (for now) are all the Text Information Frames (excluding **"TXXX"** and **"TXX"**), the **"APIC"** / **"PIC"** image frame (through `getImage(imageSize)`), the **"COMM"** / **"COM"** comment frame and all the URL Link Frames (excluding **"WXXX"** and **"WXX"**).
- The `set("Frame's name", "Frame's value")` function only uses **ISO-8859-1** encoding which means that only **Afrikaans, Basque, Catalan, Danish, Dutch, English, Faeroese, Finnish, French, Galician, German, Icelandic, Irish, Italian, Norwegian, Portuguese, Spanish and Swedish** are supported for writing. However it can read **ISO-8859-1**, **UTF-16** and **UTF-8** so the `get("Frame's name")` function should print the tags correctly no matter the language.
- This library is recommended to be used only with windows due to the usage of `wchar_t`.
- This library won't support unsynchronization as it's no longer needed.
12 changes: 8 additions & 4 deletions examples/exampleV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ int main(){
std::unique_ptr<ID3v1> id1 = std::make_unique<ID3v1>(path);

if(id1->processTags()){
std::cout << "\nTitle: " << id1->get("TITLE");
std::cout << "\nArtist: " << id1->get("ARTIST");
std::cout << "\nAlbum: " << id1->get("ALBUM");
std::cout << "\nYear: " << id1->get("YEAR");
std::cout << "\nTitle: ";
id1->get("TITLE");
std::cout << "\nArtist: ";
id1->get("ARTIST");
std::cout << "\nAlbum: ";
id1->get("ALBUM");
std::cout << "\nYear: ";
id1->get("YEAR");

if(!id1->set("TITLE", "New Title")) std::cout << "\nSet failed";
if(!id1->remove("TITLE")) std::cout << "\nRemove failed";
Expand Down
8 changes: 4 additions & 4 deletions examples/exampleV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ int main(){

delete[] imgCh;
}
//if(!id2->set("COMM", "New Comment")) std::cout << "\nSet failed";
//if(!id2->remove("TIT2")) std::cout << "\nRemove failed";
//if(!id2->removeAll()) std::cout << "\nRemove failed";
if(!id2->set("COMM", "New Comment")) std::cout << "\nSet failed";
if(!id2->remove("TIT2")) std::cout << "\nRemove failed";
if(!id2->removeAll()) std::cout << "\nRemove failed";
}
}
else {
std::cout << "\nNo ID3 tags detected";
// Automatically creates ID3 tag with the specified frame
//if(!id2->set("TIT2", "New Title")) std::cout << "\nSet failed";
if(!id2->set("TIT2", "New Title")) std::cout << "\nSet failed";
}

return 0;
Expand Down
12 changes: 7 additions & 5 deletions include/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,14 @@ inline std::string ch2str(const char ch[], const unsigned int max){
return str;
}

inline std::wstring UTF16_Reader(const wchar_t wch[], const unsigned int &max){
std::wstring wstr;
inline std::wstring UTF16_Decoder(const wchar_t wch[], const unsigned int &max){
if(max < 2) return L"Invalid encoding";

wchar_t BOM = wch[0];
if(BOM != 0xFFFE && BOM != 0xFEFF) return L"";

for(int i = 1; i < max; i++){
if(BOM != 0xFFFE && BOM != 0xFEFF) return L"Invalid encoding";

std::wstring wstr;
for(unsigned int i = 1; i < max; i++){
if(wch[i] == L'\0') break;

if(BOM == 0xFFFE){
Expand Down
2 changes: 1 addition & 1 deletion include/v2/ID3v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ID3v2{

// Write
void writeFile(const char *bufferTagHeader, const char *bufferFrames, const uint32_t &bufferFramesSize, const char *bufferNewFrame, const uint32_t &bufferNewFrameSize, const char *bufferSongData, const uint32_t &bufferSongDataSize, const int addPadding);

char *bufferSong(uint32_t &bufferSongSize);
char *newTagHeader(const short int &version, const uint32_t &newTagSize);
char *bufferFrame(const std::unique_ptr<ID3v2_3_4_FrameHeader> &frHeader);
Expand Down
5 changes: 3 additions & 2 deletions src/v2/ID3v2_Return.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ void ID3v2::readTIF(const unsigned int &cPos, const uint32_t &frSize){
for(int i = 0; i < (frSize-1) / 2; i++){
ptrSongFile.read(reinterpret_cast<char *>(&wch[i]), 2);
}
std::wcout << UTF16_Reader(wch, (frSize-1) / 2);
std::wcout << UTF16_Decoder(wch, (frSize - 1) / 2);
}
else{
char frameContent[frSize - 1];
ptrSongFile.read(reinterpret_cast<char *>(frameContent), frSize - 1);

std::cout << ch2str(frameContent, frSize - 1);
}
}
Expand Down Expand Up @@ -69,7 +70,7 @@ void ID3v2::readCOM(const unsigned int &cPos, const uint32_t &frSize){
for(int i = 0; i < contentSize / 2; i++){
ptrSongFile.read(reinterpret_cast<char *>(&wch[i]), 2);
}
std::wcout << UTF16_Reader(wch, contentSize / 2);
std::wcout << UTF16_Decoder(wch, contentSize / 2);
}
else{
// Short description
Expand Down

0 comments on commit 9d6e10a

Please sign in to comment.