mirror of
https://github.com/sanderfoobar/ircradio.git
synced 2025-01-11 04:22:35 +01:00
Merge pull request 'Factor out song retrieval and printing. Allow request() to benefit from '|' operator.' (#10) from scoobybejesus/ircradio:master into master
Reviewed-on: https://git.wownero.com/dsc/ircradio/pulls/10
This commit is contained in:
commit
60f3b6c53b
@ -136,35 +136,32 @@ class Commands:
|
|||||||
if not args:
|
if not args:
|
||||||
await send_message(target=target, message="usage: !request <id>")
|
await send_message(target=target, message="usage: !request <id>")
|
||||||
|
|
||||||
needle = " ".join(args)
|
songs = await Commands._return_song_results(*args, target=target, nick=nick, **kwargs)
|
||||||
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:
|
if songs and len(songs) == 1:
|
||||||
random.shuffle(songs)
|
song = songs[0]
|
||||||
await send_message(target, "Multiple found:")
|
await radio_default.queue_push(song.filepath)
|
||||||
for s in songs[:8]:
|
msg = f"Added {song.title} to the queue"
|
||||||
await send_message(target, f"{s.utube_id} | {s.title}")
|
|
||||||
return
|
|
||||||
|
|
||||||
song = songs[0]
|
return await send_message(target, msg)
|
||||||
await radio_default.queue_push(song.filepath)
|
|
||||||
msg = f"Added {song.title} to the queue"
|
|
||||||
|
|
||||||
return await send_message(target, msg)
|
if songs:
|
||||||
|
return await Commands._print_song_results(*args, target=target, nick=nick, songs=songs, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def search(*args, target=None, nick=None, **kwargs):
|
async def search(*args, target=None, nick=None, **kwargs):
|
||||||
from ircradio.models import Song
|
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)
|
return await Commands._search(*args, target=target, nick=nick, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def searchq(*args, target=None, nick=None, **kwargs):
|
async def searchq(*args, target=None, nick=None, **kwargs):
|
||||||
from ircradio.models import Song
|
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)
|
return await Commands._search(*args, target=target, nick=nick, report_quality=True, **kwargs)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -172,10 +169,17 @@ class Commands:
|
|||||||
"""search for a title"""
|
"""search for a title"""
|
||||||
from ircradio.models import Song
|
from ircradio.models import Song
|
||||||
|
|
||||||
if not args:
|
|
||||||
return await send_message(target=target, message="usage: !search <id>")
|
|
||||||
|
|
||||||
report_quality = kwargs.get('report_quality')
|
report_quality = kwargs.get('report_quality')
|
||||||
|
|
||||||
|
songs = await Commands._return_song_results(*args, target=target, nick=nick, **kwargs)
|
||||||
|
|
||||||
|
if songs:
|
||||||
|
return await Commands._print_song_results(*args, target=target, nick=nick, report_quality=report_quality, songs=songs, **kwargs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def _return_song_results(*args, target=None, nick=None, **kwargs) -> Optional[List['Song']]:
|
||||||
|
from ircradio.models import Song
|
||||||
|
|
||||||
needle = " ".join(args)
|
needle = " ".join(args)
|
||||||
|
|
||||||
# https://git.wownero.com/dsc/ircradio/issues/1
|
# https://git.wownero.com/dsc/ircradio/issues/1
|
||||||
@ -187,13 +191,25 @@ class Commands:
|
|||||||
needle = a
|
needle = a
|
||||||
needle_2nd = b
|
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:
|
if not songs:
|
||||||
return await send_message(target, "No song(s) found!")
|
return await send_message(target, "No song(s) found!")
|
||||||
|
|
||||||
if songs and needle_2nd:
|
if songs and needle_2nd:
|
||||||
songs = [s for s in songs if s.title and needle_2nd in s.title.lower()]
|
songs = [s for s in songs if s.title and needle_2nd in s.title.lower()]
|
||||||
|
|
||||||
|
if not songs:
|
||||||
|
return await send_message(target, "No song(s) found after '|'!")
|
||||||
|
|
||||||
|
return songs
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def _print_song_results(*args, target=None, nick=None, report_quality=None, songs=None, **kwargs):
|
||||||
|
from ircradio.models import Song
|
||||||
|
|
||||||
len_songs = len(songs)
|
len_songs = len(songs)
|
||||||
max_songs = 6
|
max_songs = 6
|
||||||
moar = len_songs > max_songs
|
moar = len_songs > max_songs
|
||||||
|
Loading…
Reference in New Issue
Block a user