mirror of
https://github.com/sanderfoobar/ircradio.git
synced 2024-11-29 07:19:23 +01:00
Merge pull request 'JSON API route' (#7) from json_api into master
Reviewed-on: https://git.wownero.com/dsc/ircradio/pulls/7
This commit is contained in:
commit
9a23d7e71f
@ -23,6 +23,7 @@ class Ban(pw.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
database = db
|
database = db
|
||||||
|
|
||||||
|
|
||||||
class Song(pw.Model):
|
class Song(pw.Model):
|
||||||
id = pw.AutoField()
|
id = pw.AutoField()
|
||||||
date_added = pw.DateTimeField(default=datetime.now)
|
date_added = pw.DateTimeField(default=datetime.now)
|
||||||
@ -34,6 +35,17 @@ class Song(pw.Model):
|
|||||||
karma = pw.IntegerField(default=5, index=True)
|
karma = pw.IntegerField(default=5, index=True)
|
||||||
banned = pw.BooleanField(default=False)
|
banned = pw.BooleanField(default=False)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def to_json(self):
|
||||||
|
return {
|
||||||
|
"title": self.title,
|
||||||
|
"utube_id": self.utube_id,
|
||||||
|
"added_by": self.added_by,
|
||||||
|
"duration": self.duration,
|
||||||
|
"karma": self.karma,
|
||||||
|
"banned": self.banned
|
||||||
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delete_song(utube_id: str) -> bool:
|
def delete_song(utube_id: str) -> bool:
|
||||||
from ircradio.factory import app
|
from ircradio.factory import app
|
||||||
|
@ -131,3 +131,12 @@ async def np():
|
|||||||
|
|
||||||
last_song = val
|
last_song = val
|
||||||
await asyncio.sleep(5)
|
await asyncio.sleep(5)
|
||||||
|
|
||||||
|
if settings.json_songs_route:
|
||||||
|
@app.route(settings.json_songs_route)
|
||||||
|
async def songs_json():
|
||||||
|
from ircradio.models import Song
|
||||||
|
data = []
|
||||||
|
for song in Song.select().filter(Song.banned == False):
|
||||||
|
data.append(song.to_json)
|
||||||
|
return jsonify(data)
|
@ -51,3 +51,4 @@ liquidsoap_iface = icecast2_mount.replace(".", "(dot)")
|
|||||||
liquidsoap_max_song_duration = 60 * 11 # seconds
|
liquidsoap_max_song_duration = 60 * 11 # seconds
|
||||||
|
|
||||||
re_youtube = r"[a-zA-Z0-9_-]{11}$"
|
re_youtube = r"[a-zA-Z0-9_-]{11}$"
|
||||||
|
json_songs_route = ""
|
Loading…
Reference in New Issue
Block a user