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(''+id_link+''+added_link+''+title+'') + }) + + } else { + setTimeout(renderTable, 30); // try again in 30 milliseconds + } + }; + + renderTable(); + +}); diff --git a/ircradio/templates/base.html b/ircradio/templates/base.html index a4b8b90..4dd653e 100644 --- a/ircradio/templates/base.html +++ b/ircradio/templates/base.html @@ -29,7 +29,43 @@ IRC!Radio ala Scoob! + + + + + + + + + + + + + + + + + diff --git a/ircradio/templates/index.html b/ircradio/templates/index.html index 7b90635..561c96a 100644 --- a/ircradio/templates/index.html +++ b/ircradio/templates/index.html @@ -4,17 +4,28 @@
-
+
-

+

IRC!Radio ala Scoob!

-

+

Thanks, dsc_! -
+

Enjoy the music :)

+
+ +

+ +

Now playing:

+
+ +
Previous:
+
Nothing here yet
+
+

Command list:

@@ -35,29 +46,52 @@
+
-
-

Library - (by user) +
+ +

View User Library +

-
-
+ +
-
-
-
+

+
+ +
+
+

Quick Search + (general) +

+
+ +
+
+
+ + + + + +
+
+
+ +
+

IRC

{{ settings.irc_host }}:{{ settings.irc_port }}
 {{ settings.irc_channels | join(" ") }}
@@ -65,4 +99,7 @@
     
+ + + {% endblock %} diff --git a/ircradio/youtube.py b/ircradio/youtube.py index 77f4b6a..60b9d04 100644 --- a/ircradio/youtube.py +++ b/ircradio/youtube.py @@ -36,7 +36,9 @@ class YouTube: try: proc = await asyncio.create_subprocess_exec( - *["youtube-dl", + *[ + #"/home/radio/ircradio/venv/bin/youtube-dl", + "youtube-dl", "--add-metadata", "--write-all-thumbnails", "--write-info-json", diff --git a/requirements.txt b/requirements.txt index 1b39095..b58bb7e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,6 @@ aiofiles aiohttp bottom tinytag -peewee python-dateutil mutagen -peewee \ No newline at end of file +peewee