From b6450973bdfbd6eee3f972cf57e2b4425faf3d24 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Sat, 24 May 2014 11:32:50 +0200 Subject: Limiting the size of the filename for saving earthporn images --- earthporn.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/earthporn.go b/earthporn.go index bfa3e81..8267bc8 100644 --- a/earthporn.go +++ b/earthporn.go @@ -128,11 +128,19 @@ func setSavepathCmd(params []string) error { return nil } +const maxTitleLenInFilename = 100 + func (p *EarthPorn) save() error { ext := extensions[p.mediatype] pp := strings.Split(p.Permalink, "/") threadid := pp[len(pp)-3] + title := strings.Replace(p.Title, "/", "-", -1) + tRunes := []rune(title) + if len(tRunes) > maxTitleLenInFilename { + title = string(tRunes[0:maxTitleLenInFilename]) + } + f, err := os.Create(path.Join(savepath, threadid+" - "+title+"."+ext)) if err != nil { return fmt.Errorf("Could not save earthporn: %s", err) -- cgit v1.2.3-70-g09d2