fix issue with pytube,
add limit to search result length
This commit is contained in:
parent
ccc13700d9
commit
50f993392b
13
src/embed.py
13
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
|
@ -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)))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user