Skip to content

Commit

Permalink
added id3 separator
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat committed Jan 21, 2023
1 parent 0b13e9b commit a4b54aa
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ def search_and_download(self, song: Song) -> Tuple[Song, Optional[Path]]:
Path(file_to_delete).unlink()

try:
embed_metadata(output_file, song)
embed_metadata(output_file, song, self.settings["id3_separator"])
except Exception as exception:
raise MetadataError(
"Failed to embed metadata to the song"
Expand Down
4 changes: 2 additions & 2 deletions spotdl/download/progress_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,8 @@ def notify_error(
if finish:
self.progress = 100

if logger.level == logging.DEBUG:
logger.error(message)
if logger.getEffectiveLevel() == logging.DEBUG:
logger.exception(message)
else:
logger.error("%s: %s", traceback.__class__.__name__, traceback)

Expand Down
2 changes: 2 additions & 0 deletions spotdl/types/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class DownloaderOptions(TypedDict):
log_level: str
simple_tui: bool
fetch_albums: bool
id3_separator: str


class WebOptions(TypedDict):
Expand Down Expand Up @@ -130,6 +131,7 @@ class DownloaderOptionalOptions(TypedDict, total=False):
log_level: str
simple_tui: bool
fetch_albums: bool
id3_separator: str


class WebOptionalOptions(TypedDict, total=False):
Expand Down
7 changes: 7 additions & 0 deletions spotdl/utils/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ def parse_output_options(parser: _ArgumentGroup):
help="Fetch all albums from songs in query",
)

# Option to change the id3 separator
parser.add_argument(
"--id3-separator",
type=str,
help="Change the separator used in the id3 tags. Only supported for mp3 files.",
)


def parse_web_options(parser: _ArgumentGroup):
"""
Expand Down
1 change: 1 addition & 0 deletions spotdl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def create_settings(
"log_level": "INFO",
"simple_tui": False,
"fetch_albums": False,
"id3_separator": "/",
}

WEB_OPTIONS: WebOptions = {
Expand Down
7 changes: 5 additions & 2 deletions spotdl/utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class MetadataError(Exception):
LRC_REGEX = re.compile(r"(\[\d{2}:\d{2}.\d{2,3}\])")


def embed_metadata(output_file: Path, song: Song):
def embed_metadata(output_file: Path, song: Song, id3_separator: str = "/"):
"""
Set ID3 tags for generic files (FLAC, OPUS, OGG)
Expand Down Expand Up @@ -195,7 +195,10 @@ def embed_metadata(output_file: Path, song: Song):

# Mp3 specific encoding
if encoding == "mp3":
audio_file.save()
if id3_separator != "/":
audio_file.save(v23_sep=id3_separator, v2_version=3)
else:
audio_file.save()

audio_file = ID3(str(output_file.resolve()))

Expand Down

0 comments on commit a4b54aa

Please sign in to comment.