ytdl-org / youtube-dl

Command-line program to download videos from YouTube.com and other video sites
http://ytdl-org.github.io/youtube-dl/
The Unlicense
132.15k stars 10.03k forks source link

Bug using youtube-dl for discord bot #32259

Closed evtvoort closed 1 year ago

evtvoort commented 1 year ago

ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output. 2023-06-01 15:52:32 ERROR discord.ext.commands.bot Ignoring exception in command play Traceback (most recent call last): File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper return func(self, *args, **kwargs) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 836, in __extract_info ie_result = ie.extract(url) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/extractor/common.py", line 534, in extract ie_result = self._real_extract(url) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py", line 1794, in _real_extract 'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None, File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/extractor/common.py", line 1012, in _search_regex raise RegexNotFoundError('Unable to extract %s' % _name) youtube_dl.utils.RegexNotFoundError: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 229, in wrapped ret = await coro(*args, kwargs) File "main.py", line 128, in play result = ydl.extract_info(video_url, download=False) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 808, in extract_info return self.extract_info(url, ie, download, extra_info, process) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper return func(self, *args, **kwargs) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 847, in extract_info return self.process_ie_result(ie_result, download, extra_info) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 933, in process_ie_result return self.__process_playlist(ie_result, download) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 1067, in process_playlist entry_result = self.process_iterable_entry(entry, download, extra) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 815, in wrapper return func(self, *args, kwargs) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 1076, in __process_iterable_entry return self.process_ie_result( File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 885, in process_ie_result return self.extract_info(ie_result['url'], File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 808, in extract_info return self.__extract_info(url, ie, download, extra_info, process) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 824, in wrapper self.report_error(compat_str(e), e.format_traceback()) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 628, in report_error self.trouble(error_message, tb) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/youtube_dl/YoutubeDL.py", line 598, in trouble raise DownloadError(message, exc_info) youtube_dl.utils.DownloadError: ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/discord/ext/commands/bot.py", line 1350, in invoke await ctx.command.invoke(ctx) File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 1023, in invoke await injected(*ctx.args, **ctx.kwargs) # type: ignore File "/home/runner/Discord-bot/venv/lib/python3.10/site-packages/discord/ext/commands/core.py", line 238, in wrapped raise CommandInvokeError(exc) from exc discord.ext.commands.errors.CommandInvokeError: Command raised an exception: DownloadError: ERROR: Unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see https://yt-dl.org/update on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.

My code: import discord from discord.ext import commands import requests as r import os import asyncio import youtube_dl

BANNED_WORDS = [ "neuken","seks","neger","kut","slet","hoer","lul","pijpen","masturberen","orgasme", "vibrator","verkrachten","teef","kech","prostituee","penis","pijper","kanker","balzak", "vagina", "neuker", "teelbal", ]

intents = discord.Intents.all() intents.members = True intents.voice_states = True

Instantieer bot

client = commands.Bot(command_prefix='!', intents=intents)

@client.event async def on_ready(): print (f"Logged in as {client.user}") await client.change_presence(activity=discord.Game(name="mezelf aan het programmeren"))

Commmands

@client.command() async def commands(context): res = "De commands die momenteel werken zijn !commands, !hoi, !kat en !daggoe." await context.message.reply(res)

@client.command() async def hoi(context): await context.message.reply("Hallo")

@client.command() async def kat(context): req = r.get("https://api.thecatapi.com/v1/images/search") res = req.json() await context.message.reply(res[0]["url"])

@client.command() async def daggoe(context): req = r.get("https://api.thedogapi.com/v1/images/search") res = req.json() await context.message.reply(res[0]["url"])

Moderatie

@client.event async def on_member_join(member): guild = member.guild if guild.system_channel is not None: res = f"Welkom {member.mention} in de {guild.name} server!" await guild.system_channel.send(res)

@client.event async def on_message(message): if message.author.id == client.user.id: return

for word in BANNED_WORDS: if word in message.content.lower(): await message.delete() await message.channel.send(f"{message.author.mention} je bericht is verwijderd, omdat het een verboden woord bevat.")

await client.process_commands(message)

@client.command() async def kick(ctx, member: discord.Member, *, reason=None): if ctx.author.guild_permissions.kick_members: await member.kick(reason=reason) await ctx.send(f"{member.mention} has been kicked.") else: await ctx.send("You don't have permission to kick members.")

@client.command() async def ban(ctx, member: discord.Member, *, reason=None): if ctx.author.guild_permissions.ban_members: await member.ban(reason=reason) await ctx.send(f'{member.mention} has been banned.') else: await ctx.send("You don't have permission to ban members.")

@client.command() async def clear(ctx, amount=5): if ctx.author.guild_permissions.manage_messages: await ctx.channel.purge(limit=amount+1) await ctx.send(f'{amount} messages have been cleared.') else: await ctx.send("You don't have permission to manage messages.")

Muziek

@client.command() async def join(ctx): kanaal = ctx.author.voice.channel voice_client = ctx.voice_client

if voice_client and voice_client.is_connected():
    await voice_client.move_to(kanaal)
else:
    await kanaal.connect()

@client.command() async def leave(ctx): voice_client = ctx.voice_client

if voice_client and voice_client.is_connected():
    await voice_client.disconnect()

@client.command() async def play(ctx, *, query): ydl = youtube_dl.YoutubeDL()

options = { 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '192', }], }

video_url = 'ytsearch:' + query

with ydl: result = ydl.extract_info(video_url, download=False)

if 'entries' in result:
    video = result['entries'][0]
else:
    video = result

video_title = video['title'] video_uploader = video['uploader']

await ctx.send(f'Gevonden video: {video_title}') await ctx.send(f'Geüpload door: {video_uploader}')

@client.command() async def pause(ctx): voice_client = ctx.voice_client

if voice_client and voice_client.is_playing():
    voice_client.pause()
    await ctx.send('Afspelen gepauzeerd.')

@client.command() async def resume(ctx): voice_client = ctx.voice_client

if voice_client and voice_client.is_paused():
    voice_client.resume()
    await ctx.send('Afspelen hervat.')

@client.command() async def stop(ctx): voice_client = ctx.voice_client

if voice_client and (voice_client.is_playing() or voice_client.is_paused()):
    voice_client.stop()
    await ctx.send('Afspelen gestopt.')

@client.command() async def volume(ctx, vol): voice_client = ctx.voice_client

if voice_client:
    try:
        volume = int(vol)
        if 0 <= volume <= 100:
            voice_client.source.volume = volume / 100
            await ctx.send(f'Volume ingesteld op {volume}%')
        else:
            await ctx.send('Volume moet tussen 0 en 100 zijn.')
    except ValueError:
        await ctx.send('Ongeldige volume-waarde.')

Run ik de bot

client.run(os.getenv("TOKEN"))

dirkf commented 1 year ago

30839 !

nicolaasjan commented 1 year ago

Unable to extract uploader id

Already reported: #31530

TL;DR See Description. Use one of the suggested methods as linked from there.

If you have a Python installation, use pip to install from the git master of this repo: #31530 (comment).

evtvoort commented 1 year ago

Unable to extract uploader id

Already reported: #31530

TL;DR See Description. Use one of the suggested methods as linked from there.

If you have a Python installation, use pip to install from the git master of this repo: #31530 (comment).

That didn't work for me

dirkf commented 1 year ago

That didn't work for me

Probably helpful to explain what happened with a log of the installation.

  1. See #30839 regarding support for programs that encapsulate yt-dl: reproduce the problem with the yt-dl program itself.

  2. Maybe s/t like this will work, on the machine where the directory /home/runner/Discord-bot/venv/lib/python3.10/site-packages/ is located (see https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/):

    # activate venv named Discord-bot: 
    source /home/runner/Discord-bot/bin/activate
    python3.10 -m pip install --upgrade --force-reinstall 'https://github.com/ytdl-org/youtube-dl/archive/refs/heads/master.tar.gz'

    Verify with:

    python3.10 -m  youtube_dl -v

    The output should include a line like this, which is different with the release code

    [debug] Python 3.10.x (CPython ...) - ... - OpenSSL ...