diff --git a/.gitignore b/.gitignore index 74ebd4d..e868eaf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ data/music/*.webp data/music/*.ogg* __pycache__ settings.py +data/* +!data/agents.txt +venv/ ircradio/static/favicons/ ircradio/favicon.ico ircradio/site.manifest diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..c0be3a9 Binary files /dev/null and b/favicon.ico differ diff --git a/ircradio.pid b/ircradio.pid new file mode 100644 index 0000000..02fa967 --- /dev/null +++ b/ircradio.pid @@ -0,0 +1 @@ +1797 \ No newline at end of file diff --git a/ircradio/routes.py b/ircradio/routes.py index 0a4fd09..a156c67 100644 --- a/ircradio/routes.py +++ b/ircradio/routes.py @@ -1,9 +1,13 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright (c) 2021, dsc@xmr.pm +import asyncio from datetime import datetime from typing import Tuple, Optional -from quart import request, render_template, abort, jsonify +from quart import request, render_template, abort, jsonify, Response, websocket + +import time +import json import settings from ircradio.factory import app @@ -108,3 +112,27 @@ async def user_library(): by_karma = [] return await render_template("library.html", name=name, by_date=by_date, by_karma=by_karma) + + +@app.websocket("/ws") +async def np(): + last_song = "" + while True: + + """get current song from history""" + history = Radio.history() + val = "" + if not history: + val = f"Nothing is playing?!" + else: + song = history[0] + val = song.title + + if val != last_song: + data = json.dumps({"now_playing": val}) + await websocket.send(f"{data}") + + last_song = val + + await asyncio.sleep(5) + diff --git a/ircradio/site.webmanifest b/ircradio/site.webmanifest new file mode 100644 index 0000000..cb59a1d --- /dev/null +++ b/ircradio/site.webmanifest @@ -0,0 +1,19 @@ +{ + "name": "IRC!Radio ala Scoob!", + "short_name": "IRC!Radio ala Scoob!", + "icons": [ + { + "src": "/favicons/android-chrome-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/favicons/android-chrome-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ], + "theme_color": "#ffffff", + "background_color": "#ffffff", + "display": "standalone" +} diff --git a/ircradio/static/search.js b/ircradio/static/search.js new file mode 100644 index 0000000..a298594 --- /dev/null +++ b/ircradio/static/search.js @@ -0,0 +1,79 @@ +// tracks input in 'search' field (id=general) +let input_so_far = ""; + +// cached song list and cached queries +var queries = []; +var songs = new Map([]); + +// track async fetch and processing +var returned = false; + +$("#general").keyup( function() { + + input_so_far = document.getElementsByName("general")[0].value; + + if (input_so_far.length < 3) { + $("#table tr").remove(); + return + }; + + if (!queries.includes(input_so_far.toLowerCase() ) ) { + queries.push(input_so_far.toLowerCase() ); + returned = false; + + const sanitized_input = encodeURIComponent( input_so_far ); + const url = 'https://' + document.domain + ':' + location.port + '/search?name=' + sanitized_input + '&limit=15&offset=0' + + const LoadData = async () => { + try { + const res = await fetch(url); + console.log("Status code 200 or similar: " + res.ok); + const data = await res.json(); + return data; + } catch(err) { + console.error(err) + } + }; + + LoadData().then(newSongsJson => { + newSongsJson.forEach( (new_song) => { + let already_have = false; + songs.forEach( (_v, key) => { + if (new_song.id == key) { already_have = true; return; }; + }) + if (!already_have) { songs.set(new_song.utube_id, new_song) } + }) + }).then( () => { returned = true } ); + + }; + + function renderTable () { + + if (returned) { + + $("#table tr").remove(); + + var filtered = new Map( + [...songs] + .filter(([k, v]) => + ( v.title.toLowerCase().includes( input_so_far.toLowerCase() ) ) || + ( v.added_by.toLowerCase().includes( input_so_far.toLowerCase() ) ) ) + ); + + filtered.forEach( (song) => { + let added = song.added_by; + let added_link = '' + added + ''; + let title = song.title; + let id = song.utube_id; + let id_link = '' + id + ''; + $('#table tbody').append('
Enjoy the music :)
++ +
{{ settings.irc_host }}:{{ settings.irc_port }} {{ settings.irc_channels | join(" ") }} @@ -65,4 +99,7 @@