Skip to content

Commit

Permalink
♻️ move sleep to downloadTrack
Browse files Browse the repository at this point in the history
  • Loading branch information
oskvr37 committed Aug 1, 2024
1 parent 29591f2 commit 87a52ef
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions tiddl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ def main():
config["token"], config["user"]["user_id"], config["user"]["country_code"]
)

def downloadTrack(track_id: str | int, file_name: str):
def downloadTrack(track_id: str | int, file_name: str, sleep=False):
if sleep:
sleep_time = randint(10, 30) / 10 + 1
logger.info(f"sleeping for {sleep_time}s")
time.sleep(sleep_time)

stream = api.getTrackStream(track_id, track_quality)
quality = TRACK_QUALITY[stream["audioQuality"]]

Expand Down Expand Up @@ -172,10 +177,7 @@ def downloadAlbum(album_id: str | int):
for item in album["items"]:
track = item["item"]
track_id = str(track["id"])
downloadTrack(track_id, track["title"])
sleep_time = randint(10, 30) / 10 + 1
logger.info(f"sleeping for {sleep_time}s")
time.sleep(sleep_time)
downloadTrack(track_id, track["title"], sleep=True)

match input_type:
case "track":
Expand All @@ -195,7 +197,7 @@ def downloadAlbum(album_id: str | int):
# TODO: add option to limit and set offset of playlist ✨
playlist = api.getPlaylistItems(input_id)
for item in playlist["items"]:
downloadTrack(item["item"]["id"], item["item"]["title"])
downloadTrack(item["item"]["id"], item["item"]["title"], sleep=True)

case _:
logger.warning(f"invalid input: `{input_type}`")
Expand Down

0 comments on commit 87a52ef

Please sign in to comment.