summaryrefslogtreecommitdiff
path: root/cmd/dlgbook/main.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2021-05-10 11:25:52 +0100
committerNick White <git@njw.name>2021-05-10 11:25:52 +0100
commitbfcb4f8b6f9805347e7ed45181c7fe38fe90a444 (patch)
treec34da512eda37d34a850c0f53c7f82f3641994b1 /cmd/dlgbook/main.go
parent47576e7f390fa62efde85ed79662b42c5cceff5c (diff)
dlgbook: add google book id to the end of the directory name, and limit lengths of title and author to ensure it never meets ext4 size limits
Diffstat (limited to 'cmd/dlgbook/main.go')
-rw-r--r--cmd/dlgbook/main.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/cmd/dlgbook/main.go b/cmd/dlgbook/main.go
index 73c14ac..c771f1e 100644
--- a/cmd/dlgbook/main.go
+++ b/cmd/dlgbook/main.go
@@ -22,6 +22,8 @@ Google Books (unless given as arguments to dlgbook), and
saves them into a directory named YEAR_AUTHORSURNAME_Title
`
+const maxPartLength = 48
+
// formatAuthors formats a list of authors by just selecting
// the first one listed, and returning the uppercased final
// name.
@@ -39,6 +41,10 @@ func formatAuthors(authors []string) string {
s = strings.ToUpper(s)
+ if len(s) > maxPartLength {
+ s = s[:maxPartLength]
+ }
+
return s
}
@@ -54,7 +60,11 @@ func mapTitle(r rune) rune {
// formatTitle formats a title to our preferences, notably
// by stripping spaces and punctuation characters.
func formatTitle(title string) string {
- return strings.Map(mapTitle, title)
+ s := strings.Map(mapTitle, title)
+ if len(s) > maxPartLength {
+ s = s[:maxPartLength]
+ }
+ return s
}
// getMetadata queries Google Books for metadata we care about
@@ -132,7 +142,7 @@ func main() {
}
}
- dir := fmt.Sprintf("%s_%s_%s", *year, *author, *title)
+ dir := fmt.Sprintf("%s_%s_%s_%s", *year, *author, *title, bookid)
err := os.MkdirAll(dir, 0755)
if err != nil {
log.Fatalf("Couldn't create directory %s: %v", dir, err)