Skip to content

Commit

Permalink
check if track is a song when downloading playlists
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat committed Aug 25, 2023
1 parent 589f643 commit 8949b9a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
27 changes: 16 additions & 11 deletions spotdl/types/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Playlist module for retrieving playlist data from Spotify.
"""

import logging
from dataclasses import dataclass
from typing import Any, Dict, List, Tuple

Expand All @@ -10,6 +11,8 @@

__all__ = ["Playlist", "PlaylistError"]

logger = logging.getLogger(__name__)


class PlaylistError(Exception):
"""
Expand Down Expand Up @@ -82,20 +85,22 @@ def get_metadata(url: str) -> Tuple[Dict[str, Any], List[Song]]:

songs = []
for track in tracks:
if (
not isinstance(track, dict)
or track.get("track") is None
or track.get("track", {}).get("is_local")
):
if not isinstance(track, dict) or track.get("track") is None:
continue

track_meta = track["track"]

if track_meta.get("is_local") or track_meta.get("type") != "track":
logger.warning(
"Skipping track: %s local tracks and %s are not supported",
track_meta.get("id"),
track_meta.get("type"),
)

continue

track_meta = track.get("track", {})
track_id = track_meta.get("id")
if (
track_meta == {}
or track_id is None
or track_meta.get("duration_ms") == 0
):
if track_id is None or track_meta.get("duration_ms") == 0:
continue

album_meta = track_meta.get("album", {})
Expand Down
8 changes: 4 additions & 4 deletions spotdl/utils/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
from spotdl._version import __version__
from spotdl.download.downloader import Downloader
from spotdl.download.progress_handler import ProgressHandler, SongTracker
from spotdl.types.album import Album
from spotdl.types.artist import Artist
from spotdl.types.options import (
DownloaderOptionalOptions,
DownloaderOptions,
WebOptions,
)
from spotdl.types.song import Song
from spotdl.types.playlist import Playlist
from spotdl.types.album import Album
from spotdl.types.artist import Artist
from spotdl.types.song import Song
from spotdl.utils.arguments import create_parser
from spotdl.utils.config import (
DOWNLOADER_OPTIONS,
Expand Down Expand Up @@ -310,7 +310,7 @@ def songs_from_url(url: str) -> List[Song]:
### Returns
- returns a list with Song objects to be downloaded.
"""

if "playlist" in url:
playlist = Playlist.from_url(url)
return list(map(Song.from_url, playlist.urls))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,15 @@
"https://www.youtube.com/watch?v=unrdoZwLYbU",
"https://www.youtube.com/watch?v=B_HSa1dEL9s",
"https://www.youtube.com/watch?v=tp83QrhNguM",
"https://www.youtube.com/watch?v=oru1gyxUImI"
"https://www.youtube.com/watch?v=oru1gyxUImI",
],
),
(
# Fukaj x Mata - OWOCE 33
"https://open.spotify.com/track/4Dy9azWTLsDMUdUxrT1170",
[
"https://www.youtube.com/watch?v=KD5ncAFjRzY",
"https://www.youtube.com/watch?v=9DKKhnmgCIo"
"https://www.youtube.com/watch?v=9DKKhnmgCIo",
],
)
# (
Expand Down

0 comments on commit 8949b9a

Please sign in to comment.