feat: configurable OPDS download folder and filename format (#2571)
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
#include "OpdsFilename.h"
|
||||
|
||||
#include "StringUtils.h"
|
||||
|
||||
std::string opdsBookFilename(const std::string& author, const std::string& title, OpdsFilenameFormat format) {
|
||||
std::string base;
|
||||
switch (format) {
|
||||
case OpdsFilenameFormat::TitleAuthor:
|
||||
base = author.empty() ? title : title + " - " + author;
|
||||
break;
|
||||
case OpdsFilenameFormat::TitleOnly:
|
||||
base = title;
|
||||
break;
|
||||
case OpdsFilenameFormat::AuthorTitle:
|
||||
default:
|
||||
base = author.empty() ? title : author + " - " + title;
|
||||
break;
|
||||
}
|
||||
// sanitizeFilename caps at 100 bytes and never returns empty (falls back to
|
||||
// "book"); ".epub" is appended after so the extension is never truncated —
|
||||
// identical treatment to the previous inline construction.
|
||||
return StringUtils::sanitizeFilename(base) + ".epub";
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
// On-disk filename format for books downloaded from an OPDS server. Stored as a
|
||||
// uint8_t in CrossPointSettings; cast to this enum at the call sites. `Count` is
|
||||
// the number of selectable formats (used to cycle the setting in the UI).
|
||||
enum class OpdsFilenameFormat : uint8_t {
|
||||
AuthorTitle = 0, // "Author - Title.epub" (default; matches legacy behaviour)
|
||||
TitleAuthor = 1, // "Title - Author.epub"
|
||||
TitleOnly = 2, // "Title.epub"
|
||||
Count = 3,
|
||||
};
|
||||
|
||||
// Composes and sanitizes the on-disk filename (including the ".epub" extension)
|
||||
// for a downloaded OPDS book, according to `format`. When the author is empty,
|
||||
// every format collapses to just the sanitized title. Pure: no I/O, no globals.
|
||||
std::string opdsBookFilename(const std::string& author, const std::string& title, OpdsFilenameFormat format);
|
||||
Reference in New Issue
Block a user