Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions zotify/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
SKIP_PREVIOUSLY_DOWNLOADED = 'SKIP_PREVIOUSLY_DOWNLOADED'
DOWNLOAD_FORMAT = 'DOWNLOAD_FORMAT'
BULK_WAIT_TIME = 'BULK_WAIT_TIME'
PL_BULK_WAIT_TIME = 'PL_BULK_WAIT_TIME'
PL_BATCH = 'PL_BATCH'
OVERRIDE_AUTO_WAIT = 'OVERRIDE_AUTO_WAIT'
CHUNK_SIZE = 'CHUNK_SIZE'
SPLIT_ALBUM_DISCS = 'SPLIT_ALBUM_DISCS'
Expand Down Expand Up @@ -56,6 +58,8 @@
SKIP_PREVIOUSLY_DOWNLOADED: { 'default': 'False', 'type': bool, 'arg': '--skip-previously-downloaded' },
RETRY_ATTEMPTS: { 'default': '1', 'type': int, 'arg': '--retry-attempts' },
BULK_WAIT_TIME: { 'default': '1', 'type': int, 'arg': '--bulk-wait-time' },
PL_BULK_WAIT_TIME: { 'default': '1', 'type': int, 'arg': '--pl-bulk-wait-time' },
PL_BATCH: { 'default': '0', 'type': int, 'arg': '--pl-batch' },
OVERRIDE_AUTO_WAIT: { 'default': 'False', 'type': bool, 'arg': '--override-auto-wait' },
CHUNK_SIZE: { 'default': '20000', 'type': int, 'arg': '--chunk-size' },
DOWNLOAD_REAL_TIME: { 'default': 'False', 'type': bool, 'arg': '--download-real-time' },
Expand Down Expand Up @@ -200,6 +204,14 @@ def get_download_lyrics(cls) -> bool:
def get_bulk_wait_time(cls) -> int:
return cls.get(BULK_WAIT_TIME)

@classmethod
def get_pl_bulk_wait_time(cls) -> int:
return cls.get(PL_BULK_WAIT_TIME)

@classmethod
def get_pl_batch(cls) -> int:
return cls.get(PL_BATCH)

@classmethod
def get_language(cls) -> str:
return cls.get(LANGUAGE)
Expand Down
13 changes: 12 additions & 1 deletion zotify/playlist.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from zotify.const import ITEMS, ID, TRACK, NAME
from zotify.termoutput import Printer
from zotify.termoutput import Printer, PrintChannel
from zotify.track import download_track
from zotify.utils import split_input
from zotify.zotify import Zotify
import time

MY_PLAYLISTS_URL = 'https://api.spotify.com/v1/me/playlists'
PLAYLISTS_URL = 'https://api.spotify.com/v1/playlists'
Expand Down Expand Up @@ -52,10 +53,20 @@ def download_playlist(playlist):
playlist_songs = [song for song in get_playlist_songs(playlist[ID]) if song[TRACK] is not None and song[TRACK][ID]]
p_bar = Printer.progress(playlist_songs, unit='song', total=len(playlist_songs), unit_scale=True)
enum = 1
plimit = -1
pl_batch = Zotify.CONFIG.get_pl_batch()
for song in p_bar:
download_track('extplaylist', song[TRACK][ID], extra_keys={'playlist': playlist[NAME], 'playlist_num': str(enum).zfill(2)}, disable_progressbar=True)
p_bar.set_description(song[TRACK][NAME])
enum += 1
if pl_batch > 0:
plimit += 1
if plimit >= pl_batch:
if Zotify.CONFIG.get_pl_bulk_wait_time():
pl_wait_time = Zotify.CONFIG.get_pl_bulk_wait_time()
Printer.print(PrintChannel.PROGRESS_INFO, f'Pausing after {pl_batch} song queries in playlist. Waiting {pl_wait_time} seconds.')
time.sleep(pl_wait_time)
plimit = -1


def download_from_user_playlist():
Expand Down