Skip to content

Commit

Permalink
added option to save errors
Browse files Browse the repository at this point in the history
  • Loading branch information
xnetcat committed Sep 1, 2023
1 parent 0a692c7 commit 920442e
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 7 deletions.
7 changes: 6 additions & 1 deletion spotdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ def search(self, query: List[str]) -> List[Song]:
- query can be a list of song titles, urls, uris
"""

return parse_query(query, self.downloader.settings["threads"], self.downloader.settings["ytm_data"], self.downloader.settings["playlist_numbering"])
return parse_query(
query,
self.downloader.settings["threads"],
self.downloader.settings["ytm_data"],
self.downloader.settings["playlist_numbering"],
)

def get_download_urls(self, songs: List[Song]) -> List[Optional[str]]:
"""
Expand Down
6 changes: 5 additions & 1 deletion spotdl/console/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ def download(
"""

# Parse the query
songs = get_simple_songs(query, use_ytm_data=downloader.settings["ytm_data"], playlist_numbering=downloader.settings["playlist_numbering"])
songs = get_simple_songs(
query,
use_ytm_data=downloader.settings["ytm_data"],
playlist_numbering=downloader.settings["playlist_numbering"],
)

# Download the songs
downloader.download_multiple_songs(songs)
7 changes: 6 additions & 1 deletion spotdl/console/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ def save(
raise DownloaderError("Save file is not specified")

# Parse the query
songs = parse_query(query, downloader.settings["threads"], downloader.settings["ytm_data"], downloader.settings["playlist_numbering"])
songs = parse_query(
query,
downloader.settings["threads"],
downloader.settings["ytm_data"],
downloader.settings["playlist_numbering"],
)
save_data = [song.json for song in songs]

def process_song(song: Song):
Expand Down
14 changes: 12 additions & 2 deletions spotdl/console/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ def sync(
)

# Parse the query
songs_list = parse_query(query, downloader.settings["threads"], downloader.settings["ytm_data"], downloader.settings["playlist_numbering"])
songs_list = parse_query(
query,
downloader.settings["threads"],
downloader.settings["ytm_data"],
downloader.settings["playlist_numbering"],
)

# Create sync file
with open(save_path, "w", encoding="utf-8") as save_file:
Expand Down Expand Up @@ -91,7 +96,12 @@ def sync(
raise ValueError("Sync file is not a valid sync file.")

# Parse the query
songs_playlist = parse_query(sync_data["query"], downloader.settings["threads"], downloader.settings["ytm_data"], downloader.settings["playlist_numbering"])
songs_playlist = parse_query(
sync_data["query"],
downloader.settings["threads"],
downloader.settings["ytm_data"],
downloader.settings["playlist_numbering"],
)

# Get the names and URLs of previously downloaded songs from the sync file
old_files = []
Expand Down
7 changes: 6 additions & 1 deletion spotdl/console/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def url(
"""

# Parse the query
songs = parse_query(query, downloader.settings["threads"], downloader.settings["ytm_data"], downloader.settings["playlist_numbering"])
songs = parse_query(
query,
downloader.settings["threads"],
downloader.settings["ytm_data"],
downloader.settings["playlist_numbering"],
)

def process_song(song: Song):
try:
Expand Down
8 changes: 8 additions & 0 deletions spotdl/download/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ def download_multiple_songs(
for error in self.errors:
logger.error(error)

if self.settings["save_errors"]:
with open(
self.settings["save_errors"], "w", encoding="utf-8"
) as error_file:
error_file.write("\n".join(self.errors))

logger.info("Saved errors to %s", self.settings["save_errors"])

# Save archive
if self.settings["archive"]:
for result in results:
Expand Down
2 changes: 2 additions & 0 deletions spotdl/types/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class DownloaderOptions(TypedDict):
max_filename_length: Optional[int]
yt_dlp_args: Optional[str]
detect_formats: Optional[str]
save_errors: Optional[str]


class WebOptions(TypedDict):
Expand Down Expand Up @@ -153,6 +154,7 @@ class DownloaderOptionalOptions(TypedDict, total=False):
max_filename_length: Optional[int]
yt_dlp_args: Optional[str]
detect_formats: Optional[str]
save_errors: Optional[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 @@ -406,6 +406,13 @@ def parse_output_options(parser: _ArgumentGroup):
help="Print errors (wrong songs, failed downloads etc) on exit, useful for long playlist",
)

# Option to save errors to a file
parser.add_argument(
"--save-errors",
type=str,
help="Save errors (wrong songs, failed downloads etc) to a file",
)

# Option to use sponsor block
parser.add_argument(
"--sponsor-block",
Expand Down
1 change: 1 addition & 0 deletions spotdl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def modernize_settings(options: DownloaderOptions):
"max_filename_length": None,
"yt_dlp_args": None,
"detect_formats": None,
"save_errors": None,
}

WEB_OPTIONS: WebOptions = {
Expand Down
4 changes: 3 additions & 1 deletion spotdl/utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def parse_query(
- List of song objects
"""

songs: List[Song] = get_simple_songs(query, use_ytm_data=use_ytm_data, playlist_numbering=playlist_numbering)
songs: List[Song] = get_simple_songs(
query, use_ytm_data=use_ytm_data, playlist_numbering=playlist_numbering
)

results = []
with concurrent.futures.ThreadPoolExecutor(max_workers=threads) as executor:
Expand Down

0 comments on commit 920442e

Please sign in to comment.