bool Strip_Tag(LPCSTR filename) { // TODO: // remove tag from file. // do whatever is need to remove the supported tag from filename // return true for successfull strip, false for failure MP4FileHandle file; file = MP4Modify(filename, 0, 0); if (file == MP4_INVALID_FILE_HANDLE) return false; MP4MetadataDelete(file); MP4Close(file); return true; }
bool Write_Tag(LPCSTR filename, void* tagHandle) { // TODO: // read metadata from tagHandle and set each field to supported tag // only TAGFIELD_* are supported (see QCDModTagEditor.h) // example of how to get value from tagHandle // use SetFieldA for ASCII or MultiBytes strings. // use SetFieldW for UNICODE strings // // szwValue = ModInitTag.GetFieldW(tagHandle, TAGFIELD_ORCHESTRA); // write tag to file MP4FileHandle file = MP4_INVALID_FILE_HANDLE; char dummy1[1024]; char temp[1024]; short dummy, dummy2; #ifdef DEBUG_OUTPUT in_mp4_DebugOutput("mp4_tag_write"); #endif /* save Metadata changes */ tag_delete(&tags); file = MP4Read(filename, 0); if (file != MP4_INVALID_FILE_HANDLE) { ReadMP4Tag(file, &tags); MP4Close(file); file = MP4Modify(filename, 0, 0); if (file != MP4_INVALID_FILE_HANDLE) { MP4MetadataDelete(file); MP4Close(file); } } file = MP4Modify(filename, 0, 0); if (file == MP4_INVALID_FILE_HANDLE) { tag_delete(&tags); //EndDialog(hwndDlg, wParam); return false; } uGetDlgItemText(tagHandle, TAGFIELD_TITLE, dummy1, 1024); tag_set_field(&tags, "title", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_COMPOSER, dummy1, 1024); tag_set_field(&tags, "writer", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_ARTIST, dummy1, 1024); tag_set_field(&tags, "artist", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_ALBUM, dummy1, 1024); tag_set_field(&tags, "album", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_COMMENT, dummy1, 1024); tag_set_field(&tags, "comment", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_GENRE, dummy1, 1024); tag_set_field(&tags, "genre", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_YEAR, dummy1, 1024); tag_set_field(&tags, "year", dummy1); dummy = 0; MP4GetMetadataTrack(file, (unsigned __int16*)&dummy, (unsigned __int16*)&dummy2); memcpy(dummy1, ModInitTag.GetFieldA(tagHandle, TAGFIELD_TRACK), sizeof(dummy1)); dummy = atoi(dummy1); wsprintf(temp, "%d/%d", dummy, dummy2); tag_set_field(&tags, "track", temp); //GetDlgItemText(hwndDlg, IDC_METADISK1, dummy1, 1024); //dummy = atoi(dummy1); //GetDlgItemText(hwndDlg, IDC_METADISK2, dummy1, 1024); //dummy2 = atoi(dummy1); //wsprintf(temp, "%d/%d", dummy, dummy2); //tag_set_field(&tags, "disc", temp); //GetDlgItemText(hwndDlg, IDC_METATEMPO, dummy1, 1024); //tag_set_field(&tags, "tempo", dummy1); //dummy3 = SendMessage(GetDlgItem(hwndDlg, IDC_METACOMPILATION), BM_GETCHECK, 0, 0); //tag_set_field(&tags, "compilation", (dummy3 ? "1" : "0")); uGetDlgItemText(tagHandle, TAGFIELD_ENCODER, dummy1, 1024); tag_set_field(&tags, "tool", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_CONDUCTOR, dummy1, 1024); tag_set_field(&tags, "CONDUCTOR", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_ORCHESTRA, dummy1, 1024); tag_set_field(&tags, "ORCHESTRA", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_YEARCOMPOSED, dummy1, 1024); tag_set_field(&tags, "YEARCOMPOSED", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_ORIGARTIST, dummy1, 1024); tag_set_field(&tags, "ORIGARTIST", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_LABEL, dummy1, 1024); tag_set_field(&tags, "LABEL", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_COPYRIGHT, dummy1, 1024); tag_set_field(&tags, "COPYRIGHT", dummy1); uGetDlgItemText(tagHandle, TAGFIELD_CDDBTAGID, dummy1, 1024); tag_set_field(&tags, "CDDBTAGID", dummy1); WriteMP4Tag(file, &tags); MP4Close(file); MP4Optimize(filename, NULL, 0); /* ! */ return true; }
bool MP4::File::save() { MP4Close(mp4file); MP4FileHandle handle = MP4Modify(name()); if(handle == MP4_INVALID_FILE_HANDLE) { mp4file = MP4Read(name()); return false; } #ifdef MP4V2_HAS_WRITE_BUG /* according to gtkpod we have to delete all meta data before modifying it, save the stuff we would not touch */ // need to fetch/rewrite this only if we aren't going to anyway uint8_t compilation = 0; bool has_compilation = mp4tag->compilation() == MP4::Tag::Undefined ? MP4GetMetadataCompilation(handle, &compilation) : false; char *tool = NULL; MP4GetMetadataTool(handle, &tool); MP4MetadataDelete(handle); #endif #define setmeta(val, tag) \ if(mp4tag->val().isNull()) { \ /*MP4DeleteMetadata##tag(handle);*/ \ MP4SetMetadata##tag(handle, ""); \ } else { \ MP4SetMetadata##tag(handle, mp4tag->val().toCString(true)); \ } setmeta(title, Name); setmeta(artist, Artist); setmeta(album, Album); setmeta(comment, Comment); setmeta(genre, Genre); char buf[100] = ""; if(mp4tag->year()) snprintf(buf, sizeof(buf), "%u", mp4tag->year()); MP4SetMetadataYear(handle, buf); u_int16_t t1, t2; MP4GetMetadataTrack(handle, &t1, &t2); MP4SetMetadataTrack(handle, mp4tag->track(), t2); if(mp4tag->bpm() != 0) MP4SetMetadataTempo(handle, mp4tag->bpm()); if(mp4tag->compilation() != MP4::Tag::Undefined) { MP4SetMetadataCompilation(handle, mp4tag->compilation()); } MP4SetMetadataCoverArt(handle, mp4tag->cover().size() ? const_cast<u_int8_t *>( reinterpret_cast<const u_int8_t *>( mp4tag->cover().data() ) ) : 0, mp4tag->cover().size()); #ifdef MP4V2_HAS_WRITE_BUG // set the saved data again if(has_compilation) MP4SetMetadataCompilation(handle, compilation); if(tool) { MP4SetMetadataTool(handle, tool); free(tool); } #endif MP4Close(handle); mp4file = MP4Read(name()); if(mp4file == MP4_INVALID_FILE_HANDLE) { fprintf(stderr, "reopen failed\n"); return false; } return true; }