From e096e749587e50da5c72bb0afa7da5bbd0e1c725 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Mon, 22 Oct 2012 21:43:35 +0200 Subject: [PATCH 7/7] himd_set_track_label implemented * himd_set_track_label can set the title/artist/album label of a track * Also added himd_modify_track_info which makes it a bit easier to modify track infos of already existing tracks. * Nice side-effect: himdcli can now set title/artist/album of tracks. --- himdcli/himdcli.c | 49 ++++++++++++++++++++++++++++++++++++++----------- libhimd/himd.h | 6 ++++++ libhimd/trackindex.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 11 deletions(-) diff --git a/himdcli/himdcli.c b/himdcli/himdcli.c index 19c514a..d3ea350 100644 --- a/himdcli/himdcli.c +++ b/himdcli/himdcli.c @@ -16,17 +16,20 @@ void usage(char * cmdname) { - printf("Usage: %s , where is either of:\n\n\ - strings - dumps all strings found in the tracklist file\n\ - tracks - lists all tracks on disc\n\ - tracks verbose - lists details of all tracks on disc\n\ - discid - reads the disc id of the inserted medium\n\ - holes - lists all holes on disc\n\ - mp3key - show the MP3 encryption key for track \n\ - dumptrack - dump track \n\ - dumpmp3 - dump MP3 track \n\ - dumpnonmp3 - dump non-MP3 track \n\ - writemp3 - write mp3 to disc\n", cmdname); + printf("Usage: %s , where is either of:\n\n" + " strings - dumps all strings found in the tracklist file\n" + " tracks - lists all tracks on disc\n" + " tracks verbose - lists details of all tracks on disc\n" + " discid - reads the disc id of the inserted medium\n" + " holes - lists all holes on disc\n" + " mp3key - show the MP3 encryption key for track \n" + " dumptrack - dump track \n" + " dumpmp3 - dump MP3 track \n" + " dumpnonmp3 - dump non-MP3 track \n" + " writemp3 - write mp3 to disc\n" + " settitle - Set <TRK>'s title to <TITLE>\n" + " setartist <TRK> <ARTIST> - Set <TRK>'s artist to <ARTIST>\n" + " setalbum <TRK> <ALBUM> - Set <TRK>'s album to <ALBUM>\n", cmdname); } static const char * hexdump(unsigned char * input, int len) @@ -723,6 +726,12 @@ void himd_writemp3(struct himd *h, const char *filepath) free(artist); free(album); free(title); } +void himd_relabel_track(struct himd * h, int idx, char * label, int label_type) +{ + himd_set_track_label(h, idx, label, label_type, NULL); + himd_write_tifdata(h, NULL); +} + int main(int argc, char ** argv) { int idx; @@ -783,6 +792,24 @@ int main(int argc, char ** argv) { himd_writemp3(&h, argv[3]); } + else if(strcmp(argv[2],"settitle") == 0 && argc > 4) + { + idx = 1; + sscanf(argv[3], "%d", &idx); + himd_relabel_track(&h, idx, argv[4], LABEL_TYPE_TITLE); + } + else if(strcmp(argv[2],"setartist") == 0 && argc > 4) + { + idx = 1; + sscanf(argv[3], "%d", &idx); + himd_relabel_track(&h, idx, argv[4], LABEL_TYPE_ARTIST); + } + else if(strcmp(argv[2],"setalbum") == 0 && argc > 4) + { + idx = 1; + sscanf(argv[3], "%d", &idx); + himd_relabel_track(&h, idx, argv[4], LABEL_TYPE_ALBUM); + } himd_close(&h); return 0; diff --git a/libhimd/himd.h b/libhimd/himd.h index 2d39aca..8f7e203 100644 --- a/libhimd/himd.h +++ b/libhimd/himd.h @@ -46,6 +46,10 @@ extern "C" { #define STRING_TYPE_ALBUM 10 #define STRING_TYPE_GROUP 12 /*reportedly disk/group name */ +#define LABEL_TYPE_TITLE 1 +#define LABEL_TYPE_ARTIST 2 +#define LABEL_TYPE_ALBUM 3 + #define HIMD_FIRST_TRACK 1 #define HIMD_LAST_TRACK 2047 @@ -163,6 +167,7 @@ void himd_close(struct himd * himd); char* himd_get_string_raw(struct himd * himd, unsigned int idx, int*type, int* length, struct himderrinfo * status); char* himd_get_string_utf8(struct himd * himd, unsigned int idx, int*type, struct himderrinfo * status); int himd_add_string(struct himd * himd, char *string, int type, struct himderrinfo * status); +gboolean himd_set_track_label(struct himd * himd, int trackindex, char *label, int label_type, struct himderrinfo * status); void himd_free(void * p); const unsigned char * himd_get_discid(struct himd * himd, struct himderrinfo * status); FILE * himd_open_file(struct himd * himd, const char * fileid, enum himd_rw_mode mode); @@ -177,6 +182,7 @@ int himd_track_blocks(struct himd * himd, const struct trackinfo * track, struct int himd_get_free_trackindex(struct himd * himd); int himd_add_track_info(struct himd * himd, struct trackinfo * track, struct himderrinfo * status); +void himd_modify_track_info(struct himd * himd, unsigned int idx, struct trackinfo * t); int himd_add_fragment_info(struct himd * himd, struct fraginfo * f, struct himderrinfo * status); #define himd_get_codec_name(track) sony_codecinfo_codecname(&(track)->codec_info) diff --git a/libhimd/trackindex.c b/libhimd/trackindex.c index 9f39eff..1d77221 100644 --- a/libhimd/trackindex.c +++ b/libhimd/trackindex.c @@ -273,6 +273,16 @@ int himd_add_track_info(struct himd * himd, struct trackinfo * t, struct himderr } +/* Warning: Only use this function, if you know that this index already references to a track. */ +void himd_modify_track_info(struct himd * himd, unsigned int idx, struct trackinfo * t) +{ + unsigned char * trackbuffer; + + trackbuffer = get_track(himd, idx); + settrack(t, trackbuffer); +} + + unsigned int himd_trackinfo_framesperblock(const struct trackinfo * track) { int framesize; @@ -579,3 +589,45 @@ int himd_add_string(struct himd * himd, char *string, int type, struct himderrin return idx_firstslot; } + +gboolean himd_set_track_label(struct himd * himd, int trackindex, char * label, int label_type, struct himderrinfo * status) +{ + struct trackinfo t; + int string_type; + int string_idx; + + g_return_val_if_fail(himd != NULL, FALSE); + g_return_val_if_fail(label != NULL, FALSE); + + if(himd_get_track_info(himd, trackindex, &t, status) < 0) + return FALSE; + + if(label_type == LABEL_TYPE_TITLE) + string_type = STRING_TYPE_TITLE; + else if(label_type == LABEL_TYPE_ARTIST) + string_type = STRING_TYPE_ARTIST; + else if(label_type == LABEL_TYPE_ALBUM) + string_type = STRING_TYPE_ALBUM; + else + return FALSE; + + if(strcmp(label, "") == 0) + string_idx = 0; + else + { + string_idx = himd_add_string(himd, label, string_type, status); + if(string_idx < 0) + return FALSE; + } + + if(label_type == LABEL_TYPE_TITLE) + t.title = string_idx; + else if(label_type == LABEL_TYPE_ARTIST) + t.artist = string_idx; + else if(label_type == LABEL_TYPE_ALBUM) + t.album = string_idx; + + himd_modify_track_info(himd, trackindex, &t); + + return TRUE; +} -- 1.7.12.4