Skip to content

Commit

Permalink
v4.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat authored Apr 23, 2023
2 parents cda3ea1 + 1173b62 commit 06901ad
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 71 deletions.
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "spotdl"
version = "4.1.7"
version = "4.1.8"
description = "Download your Spotify playlists and songs along with album art and metadata"
license = "MIT"
authors = ["spotDL Team <spotdladmins@googlegroups.com>"]
Expand Down Expand Up @@ -46,7 +46,7 @@ pydantic = "^1.10.7"
fastapi = "^0.95.1"
platformdirs = "^3.2.0"
pykakasi = "^2.2.1"
syncedlyrics = "0.4.0"
syncedlyrics = "^0.5.0"
typing-extensions = "^4.5.0"

[tool.poetry.dev-dependencies]
Expand All @@ -64,7 +64,7 @@ mdformat-gfm = "^0.3.5"
types-orjson = "^3.6.2"
types-python-slugify = "^8.0.0.2"
types-requests = "^2.28.11.17"
types-setuptools = "^67.6.0.8"
types-setuptools = "^67.7.0.0"
types-toml = "^0.10.8.6"
types-ujson = "^5.7.0.3"
pyinstaller = "^5.10.1"
Expand Down
2 changes: 1 addition & 1 deletion spotdl/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Version module for spotdl.
"""

__version__ = "4.1.7"
__version__ = "4.1.8"
25 changes: 15 additions & 10 deletions spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,20 @@ def search_and_download(self, song: Song) -> Tuple[Song, Optional[Path]]:
)

# Find song lyrics and add them to the song object
lyrics = self.search_lyrics(song)
if lyrics is None:
logger.debug(
"No lyrics found for %s, lyrics providers: %s",
song.display_name,
", ".join([lprovider.name for lprovider in self.lyrics_providers]),
)
else:
song.lyrics = lyrics
try:
lyrics = self.search_lyrics(song)
if lyrics is None:
logger.debug(
"No lyrics found for %s, lyrics providers: %s",
song.display_name,
", ".join(
[lprovider.name for lprovider in self.lyrics_providers]
),
)
else:
song.lyrics = lyrics
except Exception as exc:
logger.debug("Could not search for lyrics: %s", exc)

# If the file already exists and we want to overwrite the metadata,
# we can skip the download
Expand Down Expand Up @@ -695,7 +700,7 @@ def search_and_download(self, song: Song) -> Tuple[Song, Optional[Path]]:

# Initialize the modify chapters post processor
modify_chapters = ModifyChaptersPP(
audio_downloader.audio_handler,
downloader=audio_downloader.audio_handler,
remove_sponsor_segments=SPONSOR_BLOCK_CATEGORIES,
)

Expand Down
106 changes: 57 additions & 49 deletions spotdl/utils/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
and file names.
"""

import copy
import logging
import re
from functools import lru_cache
Expand Down Expand Up @@ -303,6 +304,8 @@ def create_file_name(
- the formatted string as a Path object
"""

temp_song = copy.deepcopy(song)

# If template does not contain any of the keys,
# append {artists} - {title}.{output-ext} to it
if not any(key in template for key in VARS) and template != "":
Expand Down Expand Up @@ -352,63 +355,68 @@ def create_file_name(

return file

# If the file name length is greater than ,
# and we are already using the short version of the template,
# fallback to default template
if short is True:
# Path template is already short, but we still can't create a file
# so we reduce it even further
if template == "{artist} - {title}.{output-ext}":
if len(song.name) > (length_limit * 0.80):
logger.warning(
"%s: File name is too long. Using only part of the song title.",
song.display_name,
)

name_parts = song.name.split(" ")
new_name = ""
for part in name_parts:
if len(new_name) + len(part) < (length_limit * 0.80):
new_name += part + " "
else:
break

song.name = new_name.strip()
else:
logger.warning(
"%s: File name is too long. Using only song title.",
song.display_name,
)

return create_file_name(
song=song,
template="{title}.{output-ext}",
file_extension=file_extension,
restrict=restrict,
short=short,
)
if short is False:
return create_file_name(
song,
template,
file_extension,
restrict=restrict,
short=True,
file_name_length=length_limit,
)

# This will probably never occur, but just in case
if template == "{title}.{output-ext}":
raise RecursionError(
f'"{song.display_name} is too long to be shortened. File a bug report on GitHub'
)
# Path template is already short, but we still can't create a file
# so we reduce it even further
long_artist = len(song.artist) > (length_limit * 0.50)
long_title = len(song.name) > (length_limit * 0.50)

path_separator = "/" if "/" in template else "\\"
name_template = template.rsplit(path_separator, 1)[1]

if long_artist:
logger.warning(
"%s: File name is too long. Using the default template.",
song.display_name,
"%s: File name is too long. Using only part of song artist.",
temp_song.display_name,
)

return create_file_name(
song=song,
template="{artist} - {title}.{output-ext}",
file_extension=file_extension,
restrict=restrict,
short=short,
short_artist = temp_song.artist.split(",")[0]
temp_song.artist = short_artist
if len(temp_song.artist) > (length_limit * 0.50):
temp_song.artist = temp_song.artist.split(" ")[0]

if long_title:
logger.warning(
"%s: File name is too long. Using only part of the song title.",
temp_song.display_name,
)

name_parts = temp_song.name.split(" ")

old_name = temp_song.name
temp_song.name = ""
for part in name_parts:
old_name = temp_song.name
temp_song.name += part + " "

formatted_name = format_query(
song=temp_song,
template=name_template,
santitize=True,
file_extension=file_extension,
short=True,
)

if len(formatted_name.strip()) > length_limit:
temp_song.name = old_name.strip()
break

return create_file_name(
song, template, file_extension, restrict=restrict, short=True
song=temp_song,
template=template,
file_extension=file_extension,
restrict=restrict,
short=short,
file_name_length=length_limit,
)


Expand Down
4 changes: 3 additions & 1 deletion spotdl/utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ def embed_lyrics(audio_file, song: Song, encoding: str):
time_tag = time_tag.replace("]", "")
time_tag = time_tag.replace(".", ":")
time_tag_vals = time_tag.split(":")
if len(time_tag_vals) != 3:
if len(time_tag_vals) != 3 or any(
not isinstance(tag, int) for tag in time_tag_vals
):
continue

minute, sec, millisecond = time_tag_vals
Expand Down
4 changes: 4 additions & 0 deletions spotdl/utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pathlib import Path
from typing import Dict, List, Optional

import requests
from ytmusicapi import YTMusic

from spotdl.types.album import Album
Expand Down Expand Up @@ -197,6 +198,9 @@ def get_simple_songs(
lists.append(spot_list)
elif "open.spotify.com" in request and "track" in request:
songs.append(Song.from_url(url=request))
elif "https://spotify.link/" in request:
resp = requests.head(request, allow_redirects=True, timeout=10)
songs.append(Song.from_url(url=resp.url))
elif "open.spotify.com" in request and "playlist" in request:
lists.append(Playlist.from_url(request, fetch_songs=False))
elif "open.spotify.com" in request and "album" in request:
Expand Down

0 comments on commit 06901ad

Please sign in to comment.