Rework flat chapter option (#201)

* Capitalize chapter type in get_content_metadata function

The get_content_metadata function in audible_cli's models.py file has been updated to capitalize the chapter type parameter. This ensures any case variations in the parameter will pass the assert condition, improving the handling of chapter types and method consistency.

* Update chapter type handling in cmd_download.py

Updated the cmd_download.py file to add a "config" choice to the chapter type and move the declaration of chapter_type to a more appropriate location. Also, the logging message has been updated to include the selected chapter type. This enhances traceability and ensures chapter type is handled consistently.

Flat chapters can be enabled by default in the config file. In the APP or profile section must be a setting `chapter_type = "flat"`.

* Update README with new `chapter_type` option

Updated README.md to include a new `chapter_type` field in both the APP and profile sections. This new field allows users to specify a chapter type for the `download` command with the `--chapter-type` option. If not provided, it defaults to "tree". This change aims to increase customizability for users.

* Update CHANGELOG to include new config file option

The CHANGELOG has been updated to reflect the addition of the ability to set a default chapter type in the config file. This allows the user to specify whether chapters should be downloaded as `flat` or `tree` type without having to state it each time a download command is given.

* Update audible-cli version

Version number has been updated from "0.3.2b2" to "0.3.2b3" in the _version.py file. This indicates a new build of the code that may include minor enhancements or bug fixes.
This commit is contained in:
mkb79 2024-04-01 13:20:06 +02:00 committed by GitHub
parent 7f01949413
commit 8dc8739f66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 8 deletions

View file

@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- The `--chapter-type` option is added to the download command. Chapter can now be
downloaded as `flat` or `tree` type. `tree` is the default.
downloaded as `flat` or `tree` type. `tree` is the default. A default chapter type
can be set in the config file.
### Changed

View file

@ -154,7 +154,11 @@ The APP section supports the following options:
- primary_profile: The profile to use, if no other is specified
- filename_mode: When using the `download` command, a filename mode can be
specified here. If not present, "ascii" will be used as default. To override
these option, you can provide a mode with the `filename-mode` option of the
these option, you can provide a mode with the `--filename-mode` option of the
download command.
- chapter_type: When using the `download` command, a chapter type can be specified
here. If not present, "tree" will be used as default. To override
these option, you can provide a type with the `--chapter-type` option of the
download command.
#### Profile section
@ -162,6 +166,7 @@ The APP section supports the following options:
- auth_file: The auth file for this profile
- country_code: The marketplace for this profile
- filename_mode: See APP section above. Will override the option in APP section.
- chapter_type: See APP section above. Will override the option in APP section.
## Getting started

View file

@ -1,7 +1,7 @@
__title__ = "audible-cli"
__description__ = "Command line interface (cli) for the audible package."
__url__ = "https://github.com/mkb79/audible-cli"
__version__ = "0.3.2b2"
__version__ = "0.3.2b3"
__author__ = "mkb79"
__author_email__ = "mkb79@hackitall.de"
__license__ = "AGPL"

View file

@ -226,7 +226,7 @@ async def download_chapters(
metadata = json.dumps(metadata, indent=4)
async with aiofiles.open(file, "w") as f:
await f.write(metadata)
logger.info(f"Chapter file saved to {file}.")
logger.info(f"Chapter file saved in style '{chapter_type.upper()}' to {file}.")
counter.count_chapter()
@ -291,6 +291,7 @@ async def _add_audioparts_to_queue(
get_pdf=None,
get_annotation=None,
get_chapters=None,
chapter_type=None,
get_aax=get_aax,
get_aaxc=get_aaxc,
client=client,
@ -688,12 +689,12 @@ def display_counter():
@click.option(
"--chapter",
is_flag=True,
help="saves chapter metadata as JSON file"
help="Saves chapter metadata as JSON file."
)
@click.option(
"--chapter-type",
default="Tree",
type=click.Choice(["Flat", "Tree"], case_sensitive=False),
default="config",
type=click.Choice(["Flat", "Tree", "config"], case_sensitive=False),
help="The chapter type."
)
@click.option(
@ -788,7 +789,6 @@ async def cli(session, api_client, **params):
cover_sizes = list(set(params.get("cover_size")))
overwrite_existing = params.get("overwrite")
ignore_errors = params.get("ignore_errors")
chapter_type = params.get("chapter_type")
no_confirm = params.get("no_confirm")
resolve_podcats = params.get("resolve_podcasts")
ignore_podcasts = params.get("ignore_podcasts")
@ -812,6 +812,11 @@ async def cli(session, api_client, **params):
f"Selected end date: {end_date.strftime('%Y-%m-%dT%H:%M:%S.%fZ')}"
)
chapter_type = params.get("chapter_type")
if chapter_type == "config":
chapter_type = session.config.get_profile_option(
session.selected_profile, "chapter_type") or "Tree"
filename_mode = params.get("filename_mode")
if filename_mode == "config":
filename_mode = session.config.get_profile_option(

View file

@ -394,6 +394,7 @@ class LibraryItem(BaseItem):
async def get_content_metadata(
self, quality: str = "high", chapter_type: str = "Tree", **request_kwargs
):
chapter_type = chapter_type.capitalize()
assert quality in ("best", "high", "normal",)
assert chapter_type in ("Flat", "Tree")