1
0
Fork 0
mirror of synced 2024-05-20 20:42:27 +12:00

Have the playlist handle searching for songs

This commit is contained in:
Phxntxm 2017-04-22 22:06:45 -05:00
parent 7e1ca280de
commit c821adf87a
2 changed files with 12 additions and 36 deletions

View file

@ -218,35 +218,7 @@ class Music:
async def add_entry(self, song, ctx):
requester = ctx.message.author
state = self.voice_states[ctx.message.guild.id]
try:
entry, _ = await state.songs.add_entry(song, requester)
except WrongEntryTypeError:
info = await self.downloader.extract_info(self.bot.loop, song, download=False, process=True)
try:
songs = info.get('entries', [])[:3]
if len(songs) > 1:
# TODO: Figures out why youtube_dl is only returning one result here
fmt = "Founds multiple possibilities, which one do you want to add?\n\n"
for i, entry in enumerate(songs):
title = entry['title']
fmt += "**{})** {}".format(i + 1, title)
await ctx.send(fmt)
def check(m):
if m.channel != ctx.message.channel and m.author != ctx.message.author:
return False
return m.content.strip() in ['1', '2', '3']
msg = await self.bot.wait_for('message', check=check, timeout=60)
song = songs[int(msg.content) - 1]['webpage_url']
else:
song = songs[0]['webpage_url']
except IndexError:
return None
entry, _ = await state.songs.add_entry(song, requester)
if entry.get('is_live', False):
raise LiveStreamError("I cannot download a live stream!!")
entry, _ = await state.songs.add_entry(song, requester)
return entry
@commands.command(pass_context=True)

View file

@ -20,7 +20,6 @@ class Playlist(EventEmitter):
self.loop = bot.loop
self.downloader = bot.downloader
self.entries = deque()
self.max_songs = 10
def __iter__(self):
return iter(self.entries)
@ -31,10 +30,6 @@ class Playlist(EventEmitter):
def clear(self):
self.entries.clear()
@property
def full(self):
return self.count >= self.max_songs
@property
def count(self):
if self.entries:
@ -62,7 +57,14 @@ class Playlist(EventEmitter):
# TODO: Sort out what happens next when this happens
if info.get('_type', None) == 'playlist':
raise WrongEntryTypeError("This is a playlist.", True, info.get('webpage_url', None) or info.get('url', None))
if info.get('extractor') == 'youtube:search':
if len(info['entries']) == 0:
raise ExtractionError('Could not extract information from %s' % song_url)
else:
info = info['entries'][0]
song_url = info['']
else:
raise WrongEntryTypeError("This is a playlist.", True, info.get('webpage_url', None) or info.get('url', None))
if info['extractor'] in ['generic', 'Dropbox']:
try:
@ -84,6 +86,9 @@ class Playlist(EventEmitter):
elif not content_type.startswith(('audio/', 'video/')):
print("[Warning] Questionable content type \"%s\" for url %s" % (content_type, song_url))
if info.get('is_live', False):
raise LiveStreamError("Cannot download from a livestream")
entry = URLPlaylistEntry(
self,
song_url,
@ -277,4 +282,3 @@ class Playlist(EventEmitter):
def count_for_user(self, user):
return sum(1 for e in self.entries if e.meta.get('author', None) == user)