From 7f1afb27f1b41ea3951fd895307bb112cc693115 Mon Sep 17 00:00:00 2001 From: Gilbert Paquin Date: Fri, 23 Sep 2022 16:35:55 -0400 Subject: [PATCH 1/2] Random delay and long wait if for any reason the random delay too short Fix issue #986 --- TIDALDL-PY/tidal_dl/tidal.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/TIDALDL-PY/tidal_dl/tidal.py b/TIDALDL-PY/tidal_dl/tidal.py index 105e4ae..ec56b22 100644 --- a/TIDALDL-PY/tidal_dl/tidal.py +++ b/TIDALDL-PY/tidal_dl/tidal.py @@ -9,6 +9,8 @@ @Desc : tidal api ''' import json +import random +import time import aigpy import base64 import requests @@ -35,6 +37,21 @@ class TidalAPI(object): for index in range(0, 3): try: respond = requests.get(urlpre + path, headers=header, params=params) + if respond.url.find("playbackinfopostpaywall") != -1: + # random sleep between 0.5 and 5 seconds and print it + sleep_time = random.randint(500, 5000) / 1000 + print(f"Sleeping for {sleep_time} seconds, to mimic human behaviour and prevent too many requests error") + time.sleep(sleep_time) + + if respond.status_code == 429: + print('Too many requests, waiting for 20 seconds...') + # Loop countdown 20 seconds and print the remaining time + for i in range(20, 0, -1): + time.sleep(1) + print(i, end=' ') + print('') + continue + result = json.loads(respond.text) if 'status' not in result: return result From 0c83717469e332c27b67522cda08c5ba81acf2c2 Mon Sep 17 00:00:00 2001 From: Gilbert Paquin Date: Fri, 23 Sep 2022 16:37:04 -0400 Subject: [PATCH 2/2] Only take streamReady track This is when a track is still in the playlist and no longer on tidal, you can't play the song anymore through tidal Fix Issue #970 --- TIDALDL-PY/tidal_dl/tidal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TIDALDL-PY/tidal_dl/tidal.py b/TIDALDL-PY/tidal_dl/tidal.py index ec56b22..5f38c7d 100644 --- a/TIDALDL-PY/tidal_dl/tidal.py +++ b/TIDALDL-PY/tidal_dl/tidal.py @@ -269,7 +269,7 @@ class TidalAPI(object): tracks = [] videos = [] for item in data: - if item['type'] == 'track': + if item['type'] == 'track' and item['item']['streamReady']: tracks.append(aigpy.model.dictToModel(item['item'], Track())) else: videos.append(aigpy.model.dictToModel(item['item'], Video()))