我安装了ffmpeg,安装了youtube-dl,安装了所有要求,下载了重命名的歌曲,但是什么也没发生!
@client.command()
async def play(ctx, *url: str):
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
print("Removed old song file")
except PermissionError:
print("Trying to delete song file, but it's being played")
await ctx.send("ERROR: Music playing")
return
await ctx.send("Getting everything ready now")
voice = get(client.voice_clients, guild=ctx.guild)
ydl_opts = {
'format': 'bestaudio/best',
'quiet': True,
'outtmpl':"./song.mp3",
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
song_search = " ".join(url)
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
print("Downloading audio now\n")
ydl.download([f"ytsearch1:{song_search}"])
for file in os.listdir("./"):
if file.endswith(".mp3"):
name = file
print(f"Renamed File: {file}\n")
os.rename(file, "song.mp3")
voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: print(f"{name} has finished playing"))
voice.source = discord.PCMVolumeTransformer(voice.source)
voice.source.volume = 0.10
nname = name.rsplit("-", 2)
await ctx.send(f"Currently playing: {nname}")
print("playing\n")
答案 0 :(得分:0)
Heroku支持将ffmpeg作为您应用程序的构建包。只需在https://dashboard.heroku.com/apps/[app-name]/settings
上打开您的应用设置,然后向下滚动到Buildpacks,即可在其中添加https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
。
或者,您也可以运行CLI命令:
$ heroku buildpacks:add https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
https://elements.heroku.com/buildpacks/jonathanong/heroku-buildpack-ffmpeg-latest