Skip to content

Commit

Permalink
v4.2.8
Browse files Browse the repository at this point in the history
Bug fixes:
- Always include filter when sending requests to piped by @xnetcat 
- Check status code when getting response from piped by @xnetcat 
- Use piped.video instead of main piped instance by @j3bx in #2172
- Fixed `RuntimeError: Directory 'C:\Users\myuser\.spotdl\web-ui\dist' does not exist` by @R0GUE-A5H in #2173
- Make sync command aware of file name changes by @xnetcat 

Documentation:
- Chore: update downloader.py by @Elto

Co-authored-by: kuba <xnetcat.dev@gmail.com>
Co-authored-by: Alan <96998756+j3bx@users.noreply.github.com>
Co-authored-by: Ikko Eltociear Ashimine <eltociear@gmail.com>
Co-authored-by: Ash <38578557+R0GUE-A5H@users.noreply.github.com>
  • Loading branch information
4 people authored Sep 6, 2024
2 parents 292b40a + ae86fcc commit 866dadd
Show file tree
Hide file tree
Showing 9 changed files with 636 additions and 520 deletions.
1,015 changes: 519 additions & 496 deletions poetry.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "spotdl"
version = "4.2.7"
version = "4.2.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 @@ -40,13 +40,13 @@ ytmusicapi = [
pytube = "^15.0.0"
yt-dlp = "^2024.8.6"
mutagen = "^1.47.0"
rich = "^13.7.1"
rich = "^13.8.0"
beautifulsoup4 = "^4.12.3"
requests = "^2.32.3"
rapidfuzz = "^3.9.6"
rapidfuzz = "^3.9.7"
python-slugify = {extras = ["unidecode"], version = "^8.0.4"}
uvicorn = "^0.23.2"
pydantic = "^2.8.2"
pydantic = "^2.9.0"
fastapi = "^0.103.0"
platformdirs = "^4.2.2"
pykakasi = "^2.3.0"
Expand All @@ -61,22 +61,22 @@ pytest-cov = "^5.0.0"
pytest-subprocess = "^1.5.2"
pytest-asyncio = "^0.21.1"
mypy = "^1.11.2"
pylint = "^3.2.6"
pylint = "^3.2.7"
black = "^24.8.0"
mdformat-gfm = "^0.3.5"
types-orjson = "^3.6.2"
types-python-slugify = "^8.0.2.20240310"
types-requests = "==2.31.0.6"
types-setuptools = "^73.0.0.20240822"
types-setuptools = "^74.1.0.20240906"
types-toml = "^0.10.8.7"
types-ujson = "^5.10.0.20240515"
pyinstaller = "^6.10.0"
mkdocs = "^1.6.0"
mkdocs = "^1.6.1"
isort = "^5.13.2"
dill = "^0.3.7"
mkdocs-material = "^9.5.33"
mkdocstrings = "^0.25.1"
mkdocstrings-python = "^1.10.8"
mkdocs-material = "^9.5.34"
mkdocstrings = "^0.26.0"
mkdocstrings-python = "^1.11.1"
pymdown-extensions = "^10.9"
mkdocs-gen-files = "^0.5.0"
mkdocs-literate-nav = "^0.6.0"
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.2.7"
__version__ = "4.2.8"
64 changes: 62 additions & 2 deletions spotdl/console/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import json
import logging
from typing import List
from typing import List, Tuple
from pathlib import Path

from spotdl.download.downloader import Downloader
from spotdl.types.song import Song
Expand Down Expand Up @@ -122,13 +123,72 @@ def sync(
downloader.settings["format"],
downloader.settings["restrict"],
)

old_files.append((file_name, entry["url"]))

new_urls = [song.url for song in songs_playlist]

# Delete all song files whose URL is no longer part of the latest playlist
if not downloader.settings["sync_without_deleting"]:
to_delete = [path for (path, url) in old_files if url not in new_urls]
# Rename songs that have "{list-length}", "{list-position}", "{list-name}",
# in the output path so that we don't have to download them again,
# and to avoid mangling the directory structure.
to_rename: List[Tuple[Path, Path]] = []
to_delete = []
for path, url in old_files:
if url not in new_urls:
to_delete.append(path)
else:
new_song = songs_playlist[new_urls.index(url)]

new_path = create_file_name(
Song.from_dict(new_song.json),
downloader.settings["output"],
downloader.settings["format"],
downloader.settings["restrict"],
)

if path != new_path:
to_rename.append((path, new_path))

# TODO: Downloading duplicate songs in the same playlist
# will trigger a re-download of the song. To fix this we have to copy the song
# to the new location without removing the old one.
for old_path, new_path in to_rename:
if old_path.exists():
logger.info("Renaming %s to %s", f"'{old_path}'", f"'{new_path}'")
if new_path.exists():
old_path.unlink()
continue

try:
old_path.rename(new_path)
except (PermissionError, OSError) as exc:
logger.debug(
"Could not rename temp file: %s, error: %s", old_path, exc
)
else:
logger.debug("%s does not exist.", old_path)

if downloader.settings["sync_remove_lrc"]:
lrc_file = old_path.with_suffix(".lrc")
new_lrc_file = new_path.with_suffix(".lrc")
if lrc_file.exists():
logger.debug(
"Renaming lrc %s to %s",
f"'{lrc_file}'",
f"'{new_lrc_file}'",
)
try:
lrc_file.rename(new_lrc_file)
except (PermissionError, OSError) as exc:
logger.debug(
"Could not rename lrc file: %s, error: %s",
lrc_file,
exc,
)
else:
logger.debug("%s does not exist.", lrc_file)

for file in to_delete:
if file.exists():
Expand Down
7 changes: 4 additions & 3 deletions spotdl/console/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ def web(web_settings: WebOptions, downloader_settings: DownloaderOptions):

# Download web app from GitHub if not already downloaded or force flag set
web_app_dir = get_web_ui_path()
if (
not os.path.exists(web_app_dir) or web_settings["force_update_gui"]
) and web_settings["web_gui_location"] is None:
dist_dir = web_app_dir / "dist"
if (not dist_dir.exists() or web_settings["force_update_gui"]) and web_settings[
"web_gui_location"
] is None:
if web_settings["web_gui_repo"] is None:
gui_repo = "https://github.com/spotdl/web-ui/tree/master/dist"
else:
Expand Down
6 changes: 4 additions & 2 deletions spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def search_and_download( # pylint: disable=R0911
logger.info("Skipping explicit song: %s", song.display_name)
return song, None

# Initalize the progress tracker
# Initialize the progress tracker
display_progress_tracker = self.progress_handler.get_new_tracker(song)

try:
Expand Down Expand Up @@ -501,7 +501,9 @@ def search_and_download( # pylint: disable=R0911
logger.debug(
"Found duplicate songs for %s at %s",
song.display_name,
dup_song_paths,
", ".join(
[f"'{str(dup_song_path)}'" for dup_song_path in dup_song_paths]
),
)

# If the file already exists and we don't want to overwrite it,
Expand Down
32 changes: 27 additions & 5 deletions spotdl/providers/audio/piped.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import requests
from yt_dlp import YoutubeDL

from spotdl.providers.audio.base import ISRC_REGEX, AudioProvider, YTDLLogger
from spotdl.providers.audio.base import (
ISRC_REGEX,
AudioProvider,
AudioProviderError,
YTDLLogger,
)
from spotdl.types.result import Result
from spotdl.utils.config import GlobalConfig, get_temp_path
from spotdl.utils.formatter import args_to_ytdlp_options
Expand Down Expand Up @@ -98,19 +103,29 @@ def get_results(self, search_term: str, **kwargs) -> List[Result]:
kwargs = {}

params = {"q": search_term, **kwargs}
if params.get("filter") is None:
params["filter"] = "music_videos"

response = self.session.get(
"https://pipedapi.kavin.rocks/search",
"https://piped.video/search",
params=params,
headers=HEADERS,
timeout=20,
)

if response.status_code != 200:
raise AudioProviderError(
f"Failed to get results for {search_term} from Piped: {response.text}"
)

search_results = response.json()

# Simplify results
results = []
for result in search_results["items"]:
if result["type"] != "stream":
continue

isrc_result = ISRC_REGEX.search(search_term)

results.append(
Expand Down Expand Up @@ -146,11 +161,18 @@ def get_download_metadata(self, url: str, download: bool = False) -> Dict:
"""

url_id = url.split("?v=")[1]
piped_data = requests.get(
f"https://pipedapi.kavin.rocks/streams/{url_id}",
piped_response = requests.get(
f"https://piped.video/streams/{url_id}",
timeout=10,
proxies=GlobalConfig.get_parameter("proxies"),
).json()
)

if piped_response.status_code != 200:
raise AudioProviderError(
f"Failed to get metadata for {url} from Piped: {piped_response.text}"
)

piped_data = piped_response.json()

yt_dlp_json = {
"title": piped_data["title"],
Expand Down
9 changes: 9 additions & 0 deletions tests/test_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,15 @@ def test_ytmusic_matching(monkeypatch, query, expected, capsys):
):
pytest.skip("YouTube Music search failed")

if result == None:
pytest.skip("No result has been found. Continue.")

assert result is not None and result.split("?v=")[1] in video_ids

except AssertionError:
pytest.skip(
"Either the Result is None or new ID has been returned. Please update it in links."
)

except AudioProviderError:
pytest.skip("YouTube Music search failed")
1 change: 0 additions & 1 deletion tests/types/test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def test_artist_from_string():
"""

artist = Artist.from_search_term("artist: gorillaz")

assert artist.name.lower().startswith("gor")
assert artist.url == "http://open.spotify.com/artist/3AA28KZvwAUcZuOKwyblJQ"
assert len(artist.urls) > 1

0 comments on commit 866dadd

Please sign in to comment.