From bfcb4f8b6f9805347e7ed45181c7fe38fe90a444 Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 10 May 2021 11:25:52 +0100 Subject: 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 --- cmd/dlgbook/main.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'cmd') 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) -- cgit v1.2.1-24-ge1ad