Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5359

Beginners • Re: Issue with yt-dlp on raspberry pi

$
0
0
Hello I have been hosting my discord bot on the website replit.com however they no longer support free hosting so I have transferred the code to a raspberry pi 4. My code uses the yt-dlp library to download youtube audios. The code works perfectly on the website but does not work on the pi.

The issue is with the string encoding on the raspberry pi. I need to pass a string into the yt-dl extractor however when I pass in the string I get the error.

This is the code

Code:

@app_commands.command(name="downloadyoutubeaudio",description="Download youtube audio as an mp3 (Takes a few seconds)")@app_commands.describe(youtubevideo="The youtube url or search terms")async def youtubedownload(self, interaction: discord.Interaction,youtubevideo: str):await interaction.response.defer(ephemeral=False)loop2 = asyncio.get_event_loop()try:audiodata = await loop2.run_in_executor(None, lambda: ytdl.extract_info(youtubevideo, download=True))audiofilename = audiodata['title'] + '.mp3'await interaction.followup.send(file=discord.File('youtubemp3.mp3', filename=audiofilename))os.remove('youtubemp3.mp3')
The main issue is on this line
audiodata = await loop2.run_in_executor(
None, lambda: ytdl.extract_info(youtubevideo, download=True))
I get the error " a bytes-like object is required, not 'str' "
However when I encode the string I get the error
"cannot use a string pattern on a bytes-like object"

So even if I encode and decode the string I get an error and I am not sure why. I have posted this issue here as opposed to stack overflow because I know the issue is with my pi encoding settings and not the code itself.
The problem is in the code. The fact that it may only happen in a pi is because the version that got installed in the pi has some issue or a dependency that is incorrect. This is a common python thing.

Try asking in the yt-dlp GitHub repo.

Statistics: Posted by memjr — Mon Mar 25, 2024 1:07 am



Viewing all articles
Browse latest Browse all 5359

Trending Articles