diff options
-rw-r--r-- | src/pool-import/main.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/pool-import/main.go b/src/pool-import/main.go index 7de3b55..85dd811 100644 --- a/src/pool-import/main.go +++ b/src/pool-import/main.go @@ -28,8 +28,10 @@ import ( "os" "os/signal" "sort" + "strings" "syscall" "time" + "unicode" "code.helsinki.at/rhrd-go/rddb" "code.helsinki.at/rhrd-go/rhimport" @@ -46,6 +48,16 @@ func Done(res rhimport.Result, userdata interface{}) bool { return true } +func stripControlCodes(in string) string { + isC0 := func(r rune) rune { + if uint32(r) <= unicode.MaxLatin1 && uint8(r) <= 0x1F { + return -1 + } + return r + } + return strings.Map(isC0, in) +} + func HandleCart(cart uint, cut uint, artist, album, title, dstgroup string, sessions *rhimport.SessionStore, conf *rhimport.Config, stdlog, dbglog *log.Logger, c <-chan os.Signal) int { filename := fmt.Sprintf("%06d_%03d.wav", cart, cut) @@ -58,9 +70,9 @@ func HandleCart(cart uint, cut uint, artist, album, title, dstgroup string, sess ctx.GroupName = dstgroup ctx.SourceUri = "local:///" + filename ctx.FetchConverter = "ffmpeg-bs1770" - ctx.ExtraMetaData["ARTIST"] = artist - ctx.ExtraMetaData["ALBUM"] = album - ctx.ExtraMetaData["TITLE"] = title + ctx.ExtraMetaData["ARTIST"] = stripControlCodes(artist) + ctx.ExtraMetaData["ALBUM"] = stripControlCodes(album) + ctx.ExtraMetaData["TITLE"] = stripControlCodes(title) _, s, code, errstring := sessions.New(ctx, "") if code != http.StatusOK { |