Add more trace log to TagLib Wrapper

This commit is contained in:
Deluan 2023-12-23 14:10:38 -05:00 committed by Joe Stump
parent 7eefae4a7c
commit 309a8d39f4
No known key found for this signature in database
GPG Key ID: 29151C3EC48A0EB9

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))