diff --git a/bot.py b/bot.py index 365bc59..1aee56c 100644 --- a/bot.py +++ b/bot.py @@ -1064,11 +1064,15 @@ async def get_file(ctx, source, link): if source == "Spotify": dir_path = None item_type, item_id = spotify.parse_spotify_url(link) - if item_id: - coro = asyncio.to_thread(spotify.fetch_tracks, spotify_ctrl, item_type, link) - file_list = await coro - coro = asyncio.to_thread(spotify.get_item_name, spotify_ctrl, item_type, item_id) - directory_name = await coro + if item_type in ["album", "track", "playlist"] and item_id: + logger.info(item_type) + logger.info(item_id) + logger.info("Spotify link provided") + file_list = await asyncio.to_thread(spotify.fetch_tracks, spotify_ctrl, item_type, link) + logger.info(file_list) + directory_name = await asyncio.to_thread(spotify.get_item_name, spotify_ctrl, item_type, item_id) + logger.info(directory_name) + logger.info("Spotify scrape done") url_data = {"urls": []} url_dict = {} url_dict["save_path"] = Path( @@ -1078,6 +1082,7 @@ async def get_file(ctx, source, link): url_dict["songs"] = file_list url_data["urls"].append(url_dict.copy()) file_name_f = youtube_download.default_filename + logger.info("YT-DL") coro = asyncio.to_thread( youtube_download.download_songs, songs=url_data, @@ -1093,6 +1098,7 @@ async def get_file(ctx, source, link): proxy="", ) _ = await coro + logger.info("YT-DL done") dir_path = (url_dict["save_path"].resolve()).as_posix() if platform == "win32": dir_path = dir_path.replace("/", "\\") @@ -1829,9 +1835,8 @@ async def wyczysc_ulubione(ctx): """ async with ctx.typing(): coroutine = asyncio.to_thread( - requests.post, + requests.get, f"{FILE_SERVICE_ADDRESS}{CLEAR_PRIO}", - json={}, timeout=360, ) _ = await coroutine diff --git a/conjurer_musician/conjurer_musician.py b/conjurer_musician/conjurer_musician.py index b22a1f2..5244f5e 100644 --- a/conjurer_musician/conjurer_musician.py +++ b/conjurer_musician/conjurer_musician.py @@ -41,41 +41,6 @@ if platform in ("linux", "linux2"): music_file_list = [] priority_list = [] - -def create_playlist(): - """ - Reads a JSON file containing a playlist and writes the playlist items to a text file. - - The JSON file path is '/home/pi/Conjurer/playlist.json', - and the text file path is '/home/pi/Conjurer/all_playlist.playlist'. - - Raises: - JSONDecodeError: If the JSON file cannot be decoded. - - """ - with open("/home/pi/Conjurer/playlist.json", "r+", encoding="utf-8") as r_file: - with open( - "/home/pi/Conjurer/all_playlist.playlist", "w", encoding="utf-8" - ) as w_file: - try: - playlist = json.load(r_file) - for item in playlist: - w_file.write(item) - w_file.write("\n") - except json.JSONDecodeError: - pass - - with open("/home/pi/Conjurer/prio_playlist.json", "r+", encoding="utf-8") as r_file: - with open("/home/pi/Conjurer/hit.playlist", "w", encoding="utf-8") as w_file: - try: - playlist = json.load(r_file) - for item in playlist: - w_file.write(item) - w_file.write("\n") - except json.JSONDecodeError: - pass - - def rescan(): """ The `rescan` function logs a message, scans for mp3 files in a specified folder, @@ -95,18 +60,22 @@ def rescan(): temp_music_file = temp_music_file.replace("/", "\\") priority_list.append(temp_music_file) - with open("/home/pi/Conjurer/playlist.json", "r+", encoding="utf-8") as s_file: - database = music_file_list - # self.app.logger.info("DUMPING DATA") - s_file.truncate(0) - s_file.seek(0) - json.dump(database, s_file) - with open("/home/pi/Conjurer/prio_playlist.json", "r+", encoding="utf-8") as s_file: - # self.app.logger.info("DUMPING DATA") - s_file.truncate(0) - s_file.seek(0) - json.dump(priority_list, s_file) - create_playlist() + with open( + "/home/pi/Conjurer/all_playlist.playlist", "w", encoding="utf-8" + ) as w_file: + try: + for item in music_file_list: + w_file.write(item) + w_file.write("\n") + except json.JSONDecodeError: + pass + with open("/home/pi/Conjurer/hit.playlist", "w", encoding="utf-8") as w_file: + try: + for item in priority_list: + w_file.write(item) + w_file.write("\n") + except json.JSONDecodeError: + pass def thread_rescan(): @@ -313,10 +282,10 @@ def clear_pr_pls(): :return: A JSON response indicating the success of the operation. """ - with open( - "/home/pi/Conjurer/priority_queue.playlist", "w", encoding="utf-8" - ) as s_file: - s_file.truncate(0) + app.logger.info("CLEARING PLAYLIST") + with open('/home/pi/Conjurer/priority_queue.playlist', 'w', encoding='utf-8') as cleared_pl: + cleared_pl.write('') + return_data = jsonify(isError=False, message="Success", statusCode=200, data=[]) return return_data, 200 diff --git a/settings.json b/settings.json index f423305..497a3c4 100644 --- a/settings.json +++ b/settings.json @@ -204,6 +204,13 @@ false, false ], + "same plusy\\b": [ + "Jak na cmentarzu Szefie. Jak na cmentarzu", + 15.0, + 0, + false, + false + ], "kld\\b": [ "KLD? Mieli tam burdel większy niż u Hammera. Ale o ile Hammer sprzątnął już nawet całkiem nieźle - to tam śmieci wyniosły się same. Uczcijmy ich minutą śmiechu.", 15.0, diff --git a/spotify_dl/spotify.py b/spotify_dl/spotify.py index a3511b5..7969a58 100644 --- a/spotify_dl/spotify.py +++ b/spotify_dl/spotify.py @@ -239,6 +239,8 @@ def get_item_name(sp, item_type, item_id): name = sp.album(album_id=item_id).get("name") elif item_type == "track": name = sp.track(track_id=item_id).get("name") + elif item_type == "artist_top_tracks": + name = sp.artist_top_tracks(artist_id=item_id).get("name") return sanitize(name)