diff options
author | Kevin Chabowski <kevin@kch42.de> | 2014-05-24 11:32:50 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2014-05-24 11:32:50 +0200 |
commit | b6450973bdfbd6eee3f972cf57e2b4425faf3d24 (patch) | |
tree | abd5db3433335dd42004566c16c16ee34eaadc5a | |
parent | c071a0b5dddbea30ed2a6222ef9d31ae6716542d (diff) | |
download | startpage-b6450973bdfbd6eee3f972cf57e2b4425faf3d24.tar.gz startpage-b6450973bdfbd6eee3f972cf57e2b4425faf3d24.tar.bz2 startpage-b6450973bdfbd6eee3f972cf57e2b4425faf3d24.zip |
Limiting the size of the filename for saving earthporn images
-rw-r--r-- | earthporn.go | 8 |
1 files changed, 8 insertions, 0 deletions
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) |