Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Josef-Friedrich/audiorename
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef-Friedrich committed Jul 12, 2024
2 parents a608ee9 + 62343cb commit a821257
Show file tree
Hide file tree
Showing 25 changed files with 761 additions and 716 deletions.
32 changes: 16 additions & 16 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@
"**/docs/_build/": true,
"**/MANIFEST": true
},
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--capture=tee-sys",
"-vv",
"--rootdir",
"${workspaceFolder}/tests",
"-m",
"not (slow or gui)"
],
"python.analysis.typeCheckingMode": "strict",
"python.analysis.diagnosticSeverityOverrides": {
"reportPrivateImportUsage": "none",
"reportUnusedImport": "information",
"reportUnusedExpression": "information",
"reportImportCycles": "information"
},
"[python]": {
"editor.rulers": [
79,
Expand All @@ -37,4 +21,20 @@
],
"editor.defaultFormatter": "charliermarsh.ruff"
},
"python.analysis.diagnosticSeverityOverrides": {
"reportPrivateImportUsage": "none",
"reportUnusedImport": "information",
"reportUnusedExpression": "information",
"reportImportCycles": "information"
},
"python.defaultInterpreterPath": ".venv/bin/python",
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
"--capture=tee-sys",
"-vv",
"--rootdir",
"${workspaceFolder}/tests",
"-m",
"not (slow or gui)"
]
}
102 changes: 35 additions & 67 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,10 @@ Usage

::

usage: audiorenamer [-h] [--config CONFIG] [-v] [-t TARGET] [-a]
[-p BACKUP_FOLDER] [-B] [-d] [-C | -M | -n] [-A | -D] [-F]
[-m ALBUM_MIN] [-e EXTENSION]
[--genre-classical GENRE_CLASSICAL] [-s FIELD_SKIP] [-k]
[-S] [--no-soundtrack] [-f PATH_TEMPLATE]
[-c PATH_TEMPLATE] [--soundtrack PATH_TEMPLATE]
[--format-classical PATH_TEMPLATE] [-K | --no-color] [-b]
[-j] [-l] [-o] [-T] [-V] [-E] [-r]
usage: audiorenamer [-h] [--config CONFIG] [-v] [-t TARGET] [-a] [-p BACKUP_FOLDER] [-B] [-d] [-C | -M | -n] [-A | -D] [-F]
[-m ALBUM_MIN] [-e EXTENSION] [--genre-classical GENRE_CLASSICAL] [-s FIELD_SKIP] [-k] [-S] [--no-soundtrack]
[-f PATH_TEMPLATE] [-c PATH_TEMPLATE] [--soundtrack PATH_TEMPLATE] [--format-classical PATH_TEMPLATE]
[-K | --no-color] [-b] [-j] [-l] [-o] [-T] [-V] [-E] [-r]
source

Rename audio files from metadata tags.
Expand Down Expand Up @@ -689,11 +685,9 @@ Usage
[selection]:
The following arguments are intended to select the audio files.

source A folder containing audio files or a single audio
file. If you specify a folder, the program will search
for audio files in all subfolders. If you want to
rename the audio files in the current working
directory, then specify a dot (“.”).
source A folder containing audio files or a single audio file. If you specify a folder, the program will search
for audio files in all subfolders. If you want to rename the audio files in the current working directory,
then specify a dot (“.”).
-t TARGET, --target TARGET
Target directory
-a, --source-as-target
Expand All @@ -704,26 +698,20 @@ Usage

-p BACKUP_FOLDER, --backup-folder BACKUP_FOLDER
Folder to store the backup files in.
-B, --best-format Use the best format. This option only takes effect if
the target file already exists. `audiorename` now
checks the qualtity of the two audio files (source and
target). The tool first examines the format. For
example a FLAC file wins over a MP3 file. Then
`audiorename` checks the bitrate.
-B, --best-format Use the best format. This option only takes effect if the target file already exists. `audiorename` now
checks the qualtity of the two audio files (source and target). The tool first examines the format. For
example a FLAC file wins over a MP3 file. Then `audiorename` checks the bitrate.
-d, --dry-run Don’t rename or copy the audio files.

move action:
-C, --copy Copy files instead of rename / move.
-M, --move Move / rename a file. This is the default action. The
option can be omitted.
-n, --no-rename Don’t rename, move, copy or perform a dry run. Do
nothing.
-M, --move Move / rename a file. This is the default action. The option can be omitted.
-n, --no-rename Don’t rename, move, copy or perform a dry run. Do nothing.

cleaning action:
The cleaning actions are only executed if the target file already exists.

-A, --backup Backup the audio files instead of deleting them. The
backup directory can be specified with the --backup-
-A, --backup Backup the audio files instead of deleting them. The backup directory can be specified with the --backup-
folder option.
-D, --delete Delete the audio files instead of creating a backup.

Expand All @@ -741,67 +729,47 @@ Usage
Skip renaming if field is empty.

[template_settings]:
-k, --classical Use the default format for classical music. If you use
this option, both parameters (--default and
--compilation) have no effect. Classical music is
sorted by the lastname of the composer.
-S, --shell-friendly Rename audio files “shell friendly”, this means
without whitespaces, parentheses etc.
--no-soundtrack Do not use the path template for soundtracks. Use
instead the default path template.
-k, --classical Use the default format for classical music. If you use this option, both parameters (--default and
--compilation) have no effect. Classical music is sorted by the lastname of the composer.
-S, --shell-friendly Rename audio files “shell friendly”, this means without whitespaces, parentheses etc.
--no-soundtrack Do not use the path template for soundtracks. Use instead the default path template.

[path_templates]:
audiorename provides default path templates. You can specify your own path templates using the following options.

-f PATH_TEMPLATE, --default PATH_TEMPLATE, --format PATH_TEMPLATE
The default path template for audio files that are not
compilations or compilations. Use metadata fields and
functions to build the path template.
-c PATH_TEMPLATE, --compilation PATH_TEMPLATE
Path template for compilations. Use metadata fields
The default path template for audio files that are not compilations or compilations. Use metadata fields
and functions to build the path template.
-c PATH_TEMPLATE, --compilation PATH_TEMPLATE
Path template for compilations. Use metadata fields and functions to build the path template.
--soundtrack PATH_TEMPLATE
Path template for a soundtrack audio file. Use
metadata fields and functions to build the path
template.
Path template for a soundtrack audio file. Use metadata fields and functions to build the path template.
--format-classical PATH_TEMPLATE
Path template for classical audio file. Use metadata
fields and functions to build the path template.
Path template for classical audio file. Use metadata fields and functions to build the path template.

[cli_output]:
This group contains all options that affect the output on the command line interface (cli).

-K, --color Colorize the standard output of the program with ANSI
colors.
--no-color Don’t colorize the standard output of the program with
ANSI colors.
-b, --debug Print debug informations about the single metadata
fields.
-j, --job-info Display informations about the current job. This
informations are printted out before any actions on
the audio files are executed.
-K, --color Colorize the standard output of the program with ANSI colors.
--no-color Don’t colorize the standard output of the program with ANSI colors.
-b, --debug Print debug informations about the single metadata fields.
-j, --job-info Display informations about the current job. This informations are printted out before any actions on the
audio files are executed.
-l, --mb-track-listing
Print track listing for Musicbrainz website: Format:
track. title (duration), e. g.: 1. He, Zigeuner (1:31)
2. Hochgetürmte Rimaflut (1:21)
-o, --one-line Display the rename / copy action status on one line
instead of two.
Print track listing for Musicbrainz website: Format: track. title (duration), e. g.: 1. He, Zigeuner
(1:31) 2. Hochgetürmte Rimaflut (1:21)
-o, --one-line Display the rename / copy action status on one line instead of two.
-T, --stats Show statistics at the end of the execution.
-V, --verbose Make the command line output more verbose.

[metadata_actions]:
-E, --enrich-metadata
Fetch the tag fields “work” and “mb_workid” from
Musicbrainz and save this fields into the audio file.
The audio file must have the tag field “mb_trackid”.
The give audio file is not renamed.
Fetch the tag fields “work” and “mb_workid” from Musicbrainz and save this fields into the audio file. The
audio file must have the tag field “mb_trackid”. The give audio file is not renamed.
-r, --remap-classical
Remap some fields to fit better for classical music:
“composer” becomes “artist”, “work” becomes “album”,
from the “title” the work prefix is removed
(“Symphonie No. 9: I. Allegro” -> “I. Allegro”) and
“track” becomes the movement number. All overwritten
fields are safed in the “comments” field.
Remap some fields to fit better for classical music: “composer” becomes “artist”, “work” becomes “album”,
from the “title” the work prefix is removed (“Symphonie No. 9: I. Allegro” -> “I. Allegro”) and “track”
becomes the movement number. All overwritten fields are safed in the “comments” field.

Configuration files
===================
Expand Down
2 changes: 1 addition & 1 deletion audiorename/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
__version__: str = metadata.version("audiorename")


def execute(*argv: str):
def execute(*argv: str) -> None:
"""Main function
:param list argv: The command line arguments specified as a list: e. g
Expand Down
2 changes: 2 additions & 0 deletions audiorename/audiofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def meta(self) -> Optional[Meta]:
except Exception as e:
tb = traceback.TracebackException.from_exception(e)
print("".join(tb.stack.format()))
return None

@property
def abspath(self) -> str:
Expand Down Expand Up @@ -131,6 +132,7 @@ def find_target_path(target: str, extensions: List[str]) -> Optional[str]:
audio_file = target + "." + extension
if os.path.exists(audio_file):
return audio_file
return None


def detect_best_format(source: Meta, target: Meta, job: Job) -> DestinationType:
Expand Down
13 changes: 8 additions & 5 deletions audiorename/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ class Timer:

end: float = 0

def start(self):
def start(self) -> None:
self.begin = time.time()

def stop(self):
def stop(self) -> None:
self.end = time.time()

def result(self) -> str:
return "{:.1f}s".format(self.end - self.begin)


class Counter:
def __init__(self):
def __init__(self) -> None:
self._counters: typing.Dict[str, int] = {}

def reset(self):
def reset(self) -> None:
self._counters = {}

def count(self, counter: str):
def count(self, counter: str) -> None:
"""Add one to number identified by a string.
:param counter: A string to identify the counter
Expand Down Expand Up @@ -122,6 +122,7 @@ def __get_value_from_config(
return config.get(section, key)
except (configparser.NoOptionError, configparser.NoSectionError):
pass
return None


class SelectionConfig(Config):
Expand Down Expand Up @@ -235,6 +236,7 @@ def album_complete(self) -> bool:
def album_min(self) -> typing.Optional[int]:
if hasattr(self, "_album_min") and isinstance(self._album_min, int):
return self._album_min
return None

@property
def extension(self) -> typing.List[str]:
Expand All @@ -258,6 +260,7 @@ def genre_classical(self) -> typing.List[str]:
def field_skip(self) -> typing.Optional[str]:
if hasattr(self, "_field_skip") and isinstance(self._field_skip, str):
return self._field_skip
return None


class TemplateSettingsConfig(Config):
Expand Down
14 changes: 10 additions & 4 deletions audiorename/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,9 @@ def _normalize_performer(ar_performer: List[str]) -> PerformerRaw:
out: PerformerRaw = []
for value in ar_performer:
value = value[:-1]
value = value.split(" (")
if len(value) == 2:
out.append([value[1], value[0]])
performers: List[str] = value.split(" (")
if len(performers) == 2:
out.append([performers[1], performers[0]])
return out

@staticmethod
Expand Down Expand Up @@ -322,6 +322,7 @@ def ar_classical_album(self) -> Optional[str]:
"""
if self.work:
return re.sub(r":.*$", "", (str(self.work)))
return None

@property
def ar_combined_album(self) -> Optional[str]:
Expand All @@ -335,6 +336,7 @@ def ar_combined_album(self) -> Optional[str]:
"""
if self.album:
return re.sub(r" ?\([dD]is[ck].*\)$", "", str(self.album))
return None

@property
def ar_initial_album(self) -> Optional[str]:
Expand All @@ -349,6 +351,7 @@ def ar_initial_album(self) -> Optional[str]:
"""
if self.ar_combined_album:
return self._find_initials(self.ar_combined_album)
return None

@property
def ar_initial_artist(self) -> str:
Expand Down Expand Up @@ -483,7 +486,7 @@ def ar_combined_disctrack(self) -> Optional[str]:
"""

if not self.track:
return
return None

if self.disctotal and int(self.disctotal) > 99:
disk = str(self.disc).zfill(3)
Expand Down Expand Up @@ -642,6 +645,7 @@ def ar_classical_title(self) -> Optional[str]:
"""
if self.title:
return re.sub(r"^[^:]*: ?", "", self.title)
return None

@property
def ar_classical_track(self) -> Optional[str]:
Expand All @@ -657,6 +661,7 @@ def ar_classical_track(self) -> Optional[str]:
return str(self._roman_to_int(roman[0])).zfill(2)
elif self.ar_combined_disctrack:
return self.ar_combined_disctrack
return None

@property
def ar_combined_work_top(self) -> Optional[str]:
Expand All @@ -670,6 +675,7 @@ def ar_combined_work_top(self) -> Optional[str]:
return self.work_hierarchy.split(" -> ")[0]
elif self.ar_classical_album:
return self.ar_classical_album
return None

@property
def ar_combined_year(self):
Expand Down
1 change: 1 addition & 0 deletions audiorename/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def query(
)
else:
print("Received bad response from the MusicBrainz server.")
return None


def query_works_recursively(work_id: str, works: List[Work] = []) -> List[Work]:
Expand Down
3 changes: 3 additions & 0 deletions docs/requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sphinx>=7
sphinx_rtd_theme>=2
sphinx-argparse>=0
Loading

0 comments on commit a821257

Please sign in to comment.