Skip to content

Commit

Permalink
Add export to album
Browse files Browse the repository at this point in the history
* Copy as much metadata as possible
* Only reencode newer source files
  • Loading branch information
john-kurkowski committed Nov 1, 2023
1 parent bd18f4a commit 508ec0c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# music

Miscellaneous tasks for publishing my music.
Tasks for publishing my music.

The code is idiosyncratic with my music project conventions and therefore
applicable mainly to me. However, the code may be a useful example for using
Expand Down
2 changes: 1 addition & 1 deletion src/music/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Miscellaneous tasks for publishing my music."""
"""Tasks for publishing my music."""
28 changes: 26 additions & 2 deletions src/music/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

"""CLI for this package."""

import shutil
import warnings
from pathlib import Path

Expand All @@ -28,7 +29,7 @@

@click.group()
def cli() -> None:
"""Miscellaneous tasks for publishing my music."""
"""Tasks for publishing my music."""


@cli.command()
Expand All @@ -46,11 +47,34 @@ def codegen(example_audio_file: Path) -> None:
_codegen(example_audio_file)


@cli.command()
@click.argument(
"dst_dir",
type=click.Path(dir_okay=True, file_okay=False, path_type=Path),
)
@click.argument(
"files",
nargs=-1,
required=True,
type=click.Path(dir_okay=False, exists=True, file_okay=True, path_type=Path),
)
def export(dst_dir: Path, files: list[Path]) -> None:
"""Export the given FILES to the given DST_DIR directory, in album order."""
dst_dir.mkdir(exist_ok=True)

for i, src in enumerate(files):
dst = dst_dir / f"{i+1:02d} - {src.with_suffix('.wav').name}"
if dst.exists() and src.stat().st_mtime < dst.stat().st_mtime:
continue

shutil.copy2(src, dst)


@cli.command()
@click.argument(
"project_dirs",
nargs=-1,
type=click.Path(exists=True, path_type=Path),
type=click.Path(dir_okay=True, exists=True, file_okay=False, path_type=Path),
)
@click.option(
"--include-main",
Expand Down

0 comments on commit 508ec0c

Please sign in to comment.