From f2fb2232eed1f0644b328836ef1c60a32939b264 Mon Sep 17 00:00:00 2001 From: Michal Tuszowski Date: Sat, 20 Jul 2024 09:09:14 +0200 Subject: [PATCH] Audition --- bot.py | 37 ++++++++++++++++++++++++++ conjurer_musician/conjurer_musician.py | 31 +++++++++++++++++++++ conjurer_musician/radio_conjurer.liq | 4 +-- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index e8ba1dc..087c125 100644 --- a/bot.py +++ b/bot.py @@ -143,6 +143,8 @@ GET_MP3 = "/mp3" SEND_MP3 = "/update_mp3" GET_PLAYLIST = "/get_music" ADD_TO_PRIO_PLAYLIST = "/add_to_priority" +CREATE_PRIO_PLAYLIST = "/create_priority_playlist" + REQUEST_MUSIC = "/request_radio_file" CLEAR_PRIO = "/clear_pr_pls" LIBRARIAN_SERVICE_ADDRESS = "http://192.168.1.192:5001" @@ -1868,6 +1870,41 @@ async def request_radio(ctx): timeout=360, ) _ = await coroutine + +@client.hybrid_command( + name="stworz_audycje", + description="Dodaje do listy ulubionych w radiu", + guild=discord.Object(id=664789470779932693), +) +async def stworz_audycje(ctx): + """ + Generate a playlist in queue. First word in this command shall be int defining length of the playlist. + Rest of the line are search terms. + + :param ctx: ctx stands for "context" and is a parameter commonly used in Discord.py commands. It + represents the context in which the command was invoked, including information such as the message, + the channel, the server, and the user who invoked the command. This parameter is required in all + Discord.py commands + """ + async with ctx.typing(): + logger.info("Zaczynam szukać timestamp %s", datetime.now()) + + dlugosc_playlisty = ctx.message.content.split()[1] + word_list = ctx.message.content.split() + jrequest = { + "lista_slow": word_list, + "dlugosc_plejlisty": dlugosc_playlisty, + "UUID": str(uuid.uuid4()), + } + coroutine = asyncio.to_thread( + requests.post, + f"{FILE_SERVICE_ADDRESS}{CREATE_PRIO_PLAYLIST}", + json=jrequest, + timeout=360, + ) + _ = await coroutine + + @client.hybrid_command( name="wyczysc_ulubione", description="Czysci liste ulubionych w radiu", diff --git a/conjurer_musician/conjurer_musician.py b/conjurer_musician/conjurer_musician.py index 525f248..84897e7 100644 --- a/conjurer_musician/conjurer_musician.py +++ b/conjurer_musician/conjurer_musician.py @@ -369,6 +369,37 @@ def add_request(): ) return return_data +@app.route("/create_priority_playlist", methods=["POST"]) +def create_priority_playlist(): + """ + The function `create_priority_playlist` receives a POST request with a JSON payload, logs the received + item, adds it to a music file list, and returns a success message along with the updated record. + + :return: A tuple containing a JSON response and a status code. + The JSON response includes keys `isError`, + `message`, `statusCode`, and `data`, with values + indicating the success of the operation and the + data that was received and added to the `music_file_list`. + The status code returned is 200,indicating a successful response. + """ + record = json.loads(request.data) + app.logger.info(record) + app.logger.info(record["lista_slow"]) + app.logger.info(record["UUID"]) + app.logger.info(record["dlugosc_plejlisty"]) + return_data = wyszukaj( + record["lista_slow"], record["dlugosc_plejlisty"], app.logger, False + ) + with open( + "/home/pi/Conjurer/request.playlist", "a", encoding="utf-8" + ) as s_file: + for item in return_data: + s_file.write(item[1] + "\n") + return_data = ( + jsonify(isError=False, message="Success", statusCode=200, data={"status": "OK"}), + 200, + ) + return return_data @app.route("/add_to_priority", methods=["POST"]) diff --git a/conjurer_musician/radio_conjurer.liq b/conjurer_musician/radio_conjurer.liq index 8db78e4..f560f76 100644 --- a/conjurer_musician/radio_conjurer.liq +++ b/conjurer_musician/radio_conjurer.liq @@ -74,7 +74,7 @@ s = amplify(a, s) mic = buffer(input.pulseaudio()) # Microphone mic = gate(threshold=-30., range=-80., mic) -mic = blank.strip(max_blank=2., min_noise=.1, threshold=-20., mic) +mic = blank.strip(max_blank=10., min_noise=.1, threshold=-20., mic) s = add([s, mic]) #w = interactive.float("wetness", min=0., max=1., 1.) @@ -82,7 +82,7 @@ s = add([s, mic]) # Skip blank sections in the stream -s = blank.skip(max_blank=2., s) +s = blank.skip(max_blank=10., s) # Configure logging settings log_to_stdout = true