diff --git a/src/embed.py b/src/embed.py index c3c1fa9..fc80386 100644 --- a/src/embed.py +++ b/src/embed.py @@ -33,15 +33,20 @@ def get_success(message): emb = discord.Embed(title='music-bot', description=message,color=0x00FF00) return emb -def get_search_results(query, results): +def get_search_results(query, results, max_results = 10): desc = 'search for: {0}'.format(query) emb = discord.Embed(title='music-bot', description=desc,color=0x0000FF) + # need to limit number of results because of embedded message limit + num_results = min(max_results, len(results)) lst = "" - for i in range(0, min(10, len(results))): + for i in range(0, num_results): + # need to limit length of each search result because of embedded message limit title = results[i].title + title_trunc = title[0:70] author = results[i].author - lst += "{0}: {1} | {2}\n".format(str(i), author, title) + author_trunc = author[0:20] + lst += "{0}: {1} | {2}\n".format(str(i), author_trunc, title_trunc) if lst == "": lst = "no results" - emb.add_field(name="{0} results found: ".format(len(results)), value=lst) + emb.add_field(name="{0} results found: ".format(num_results), value=lst) return emb \ No newline at end of file diff --git a/src/musicbot.py b/src/musicbot.py index dedeaef..87c239e 100644 --- a/src/musicbot.py +++ b/src/musicbot.py @@ -4,10 +4,13 @@ from config import * import discord from discord.ext import commands from embed import * -from pytube import YouTube, Playlist, Search, exceptions +from pytube import Playlist, Search, exceptions import shutil from embed import get_search_results +from pytubefix import YouTube +from pytubefix.cli import on_progress + from music_queue import music_queue config_path = "config.json" @@ -147,12 +150,12 @@ async def play(ctx, *args): if 'list=' in url: pl = Playlist(url) for video in pl: - yt = YouTube(video) + yt = YouTube(video, on_progress_callback = on_progress) bot.queue.enqueue(yt) count += 1 await ctx.send(embed=get_success('added {0} tracks to queue'.format(len(pl)))) else: - yt = YouTube(url) + yt = YouTube(url, on_progress_callback = on_progress) bot.queue.enqueue(yt) await ctx.send(embed=get_success('added {0} to queue'.format(yt.title)))