Add more trace log to TagLib Wrapper

This commit is contained in:
Deluan 2023-12-23 14:10:38 -05:00
parent 15e1394fa3
commit 03119e5ccf
1 changed files with 13 additions and 1 deletions

View File

@ -11,6 +11,7 @@ package taglib
*/
import "C"
import (
"encoding/json"
"fmt"
"os"
"runtime/debug"
@ -39,6 +40,7 @@ func Read(filename string) (tags map[string][]string, err error) {
id, m := newMap()
defer deleteMap(id)
log.Trace("TagLib: reading tags", "filename", filename, "map_id", id)
res := C.taglib_read(fp, C.ulong(id))
switch res {
case C.TAGLIB_ERR_PARSE:
@ -56,7 +58,13 @@ func Read(filename string) (tags map[string][]string, err error) {
case C.TAGLIB_ERR_AUDIO_PROPS:
return nil, fmt.Errorf("can't get audio properties from file")
}
log.Trace("TagLib: read tags", "tags", m, "filename", filename, "id", id)
if log.CurrentLevel() >= log.LevelDebug {
j, _ := json.Marshal(m)
log.Trace("TagLib: read tags", "tags", string(j), "filename", filename, "id", id)
} else {
log.Trace("TagLib: read tags", "tags", m, "filename", filename, "id", id)
}
return m, nil
}
@ -107,6 +115,10 @@ func do_put_map(id C.ulong, key string, val *C.char) {
m[key] = append(m[key], v)
}
/*
As I'm working on the new scanner, I see that the `properties` from TagLib is ill-suited to extract multi-valued ID3 frames. I'll have to change the way we do it for ID3, probably by sending the raw frames to Go and mapping there, instead of relying on the auto-mapped `properties`. I think this would reduce our reliance on C++, while also giving us more flexibility, including parsing the USLT / SYLT frames in Go
*/
//export go_map_put_int
func go_map_put_int(id C.ulong, key *C.char, val C.int) {
valStr := strconv.Itoa(int(val))