From aca21335f9ec65f7d3a19a7a0546a897ab84a488 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 22 Sep 2016 19:00:12 +0200 Subject: strip C0 control characters from old DB 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 { -- cgit v0.10.2