Incorporate _search into request().

scoobybejesus 8 months ago
parent bbb9c7b0c6
commit f51b523cd9

@ -133,38 +133,28 @@ class Commands:
async def request(*args, target=None, nick=None, **kwargs):
"""request a song by title or YouTube id"""
from ircradio.models import Song
if not args:
await send_message(target=target, message="usage: !request <id>")
needle = " ".join(args)
try:
songs = Song.search(needle)
except Exception as ex:
return await send_message(target, f"{ex}")
if not songs:
return await send_message(target, "Not found!")
if len(songs) >= 2:
random.shuffle(songs)
await send_message(target, "Multiple found:")
for s in songs[:8]:
await send_message(target, f"{s.utube_id} | {s.title}")
return
song = songs[0]
await radio_default.queue_push(song.filepath)
msg = f"Added {song.title} to the queue"
return await send_message(target, msg)
return await Commands._search(*args, target=target, nick=nick, request_song=True, **kwargs)
@staticmethod
async def search(*args, target=None, nick=None, **kwargs):
from ircradio.models import Song
if not args:
return await send_message(target=target, message="usage: !search <id>")
return await Commands._search(*args, target=target, nick=nick, **kwargs)
@staticmethod
async def searchq(*args, target=None, nick=None, **kwargs):
from ircradio.models import Song
if not args:
return await send_message(target=target, message="usage: !searchq <id>")
return await Commands._search(*args, target=target, nick=nick, report_quality=True, **kwargs)
@staticmethod
@ -172,10 +162,9 @@ class Commands:
"""search for a title"""
from ircradio.models import Song
if not args:
return await send_message(target=target, message="usage: !search <id>")
request_song = kwargs.get('request_song')
report_quality = kwargs.get('report_quality')
needle = " ".join(args)
# https://git.wownero.com/dsc/ircradio/issues/1
@ -187,7 +176,10 @@ class Commands:
needle = a
needle_2nd = b
songs = Song.search(needle)
try:
songs = Song.search(needle)
except Exception as ex:
return await send_message(target, f"{ex}")
if not songs:
return await send_message(target, "No song(s) found!")
@ -195,6 +187,14 @@ class Commands:
songs = [s for s in songs if s.title and needle_2nd in s.title.lower()]
len_songs = len(songs)
if len_songs == 1 and request_song:
song = songs[0]
await radio_default.queue_push(song.filepath)
msg = f"Added {song.title} to the queue"
return await send_message(target, msg)
max_songs = 6
moar = len_songs > max_songs
if len_songs > 1:

Loading…
Cancel
Save