summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--earthporn.go8
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)