Error: Unable to extract uploader id - Youtube, Discord.py
Asked Answered
S

9

85

I have a very powerful bot in discord (discord.py, PYTHON) and it can play music in voice channels. It gets the music from youtube (youtube_dl). It worked perfectly before but now it doesn't want to work with any video. I tried updating youtube_dl but it still doesn't work I searched everywhere but I still can't find a answer that might help me.

This is the Error: Error: Unable to extract uploader id

After and before the error log there is no more information. Can anyone help?

I will leave some of the code that I use for my bot... The youtube setup settings:

youtube_dl.utils.bug_reports_message = lambda: ''


ytdl_format_options = {
    'format': 'bestaudio/best',
    'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
    'restrictfilenames': True,
    'noplaylist': True,
    'nocheckcertificate': True,
    'ignoreerrors': False,
    'logtostderr': False,
    'quiet': True,
    'no_warnings': True,
    'default_search': 'auto',
    'source_address': '0.0.0.0',  # bind to ipv4 since ipv6 addresses cause issues sometimes
}

ffmpeg_options = {
    'options': '-vn',
}

ytdl = youtube_dl.YoutubeDL(ytdl_format_options)


class YTDLSource(discord.PCMVolumeTransformer):
    def __init__(self, source, *, data, volume=0.5):
        super().__init__(source, volume)

        self.data = data

        self.title = data.get('title')
        self.url = data.get('url')
        self.duration = data.get('duration')
        self.image = data.get("thumbnails")[0]["url"]
    @classmethod
    async def from_url(cls, url, *, loop=None, stream=False):
        loop = loop or asyncio.get_event_loop()
        data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
        #print(data)

        if 'entries' in data:
            # take first item from a playlist
            data = data['entries'][0]
        #print(data["thumbnails"][0]["url"])
        #print(data["duration"])
        filename = data['url'] if stream else ytdl.prepare_filename(data)
        return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)

Approximately the command to run the audio (from my bot):

sessionChanel = message.author.voice.channel
await sessionChannel.connect()
url = matched.group(1)
player = await YTDLSource.from_url(url, loop=client.loop, stream=True)
sessionChannel.guild.voice_client.play(player, after=lambda e: print(
                                       f'Player error: {e}') if e else None)
Studdingsail answered 18/2, 2023 at 19:19 Comment(3)
I'm still getting this error in July, with youtube-dl installed from pip.Vanquish
Youtube-dl for some reason has stopped updating their libraries. So use for now yt-dlp. Read the rest of the answers, maybe something can help youStuddingsail
Yes, using yt-dlp worked for me, thanks.Vanquish
E
101

This is a known issue, fixed in Master. For a temporary fix,

python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz

This installs tha master version. Run it through the command-line

yt-dlp URL

where URL is the URL of the video you want. See yt-dlp --help for all options. It should just work without errors.

If you're using it as a module,

import yt_dlp as youtube_dl

might fix your problems (though there could be API changes that break your code; I don't know which version of yt_dlp you were using etc).

Equestrian answered 20/2, 2023 at 2:31 Comment(4)
I installed it but the python code dosn't finds itStuddingsail
sudo snap install yt-dlpDedifferentiation
I am using master (6fece0a96b3cd8677f5c1185a57c6e21403fcb44), 2023-03-14, and the problem is not solved.Socinus
worked for me on a mac air, thank youDiscernible
M
68

I solved it temporarily (v2021.12.17) until there's a new update, by editing file: your/path/to/site-packages/youtube_dl/extractor/youtube.py

Example path:

  • If installed via PIP: ~/.local/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py
  • If installed via brew: /usr/local/Cellar/youtube-dl/2021.12.17/libexec/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py

Line number(~): 1794 and add the option fatal=False

enter image description here

Before:

'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None

After:

'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id', fatal=False) if owner_profile_url else None

This converts it from critical (which exits the script) to a warning (which simply continues)

Milliliter answered 1/3, 2023 at 10:10 Comment(7)
this solved it for me while I'm waiting for homebrew to pick up the update from masterTravelled
How did you realized that this could save the run? Some tip do share?Eldin
@DanielBandeira i just scanned the internet for a solution, read many posts and its comments, kept this post open that incase i'll find a solution that works i'll post the answer here as well ... once I found a comment that gave this solution - i shared it here for others ...Milliliter
Thanks. I think it's nice to mention that it's line 1794 of version 2021.12.17 (last one at this time). Just add the fatal=False option.Selda
@Ricky Levi Thanks for the solution! This solved the problem for me. I can confirm that I downloaded the latest available version n Github on March 18th 2023 and at line n° 1794 as you mentioned, by adding fatal=False, the issue was resolved.Shenika
Had to search for that path (installed via brew): /usr/local/Cellar/youtube-dl/2021.12.17/libexec/lib/python3.10/site-packages/youtube_dl/extractorCephalic
I found youtube.py with path with python -m site and then found the venv folder with site-packagesCotten
D
25

For everyone using youtube_dl and wondering how to solve this issue without using another library like ytdlp: First uninstall youtube_dl with pip uninstall youtube_dl then install the master branch of youtube_dl from their github with pip install git+https://github.com/ytdl-org/youtube-dl.git@master#egg=youtube_dl. You need git for this, download it here. Ive tested it and it works actually.

Edit:

Youtube_dl isn't maintained anymore, so I would recommend to use ytdlp, also see this link for differences between yt-dl and ytdlp in terms of the default behavior

Diverticulum answered 5/3, 2023 at 0:35 Comment(4)
I notice the use of "youtube-dl" and "youtube_dl", are these typos or interchangeable or distinctly separate entities ?Histiocyte
Aye, it works as advertised. I got a bit confused because Youtube-dl reports itself as the 'broken' 2021.12.17 version (!), but it is a much more recent one. The Youtube-dl repo maintainers really need to fix that on master! :-) Thanks for sharing your solution/fix.Abisha
np and yes you are right.Diverticulum
@Histiocyte underscores and hyphens are interchangeable for pip. Python packages are supposed to use hyphens instead of underscores (source). But because of the confusion, both will work. Pypi shows "youtube_dl" but pip list shows "youtube-dl" regardless of how you installed it.Solana
A
16

This fixed (for Ubuntu/Linux):

  1. install git (if not installed | check command: $ git --version)
sudo apt install git
  1. install pip (Python package manager, if not installed)
sudo apt install pip
  1. reinstall youtube-dl directly from git repository
sudo pip install --upgrade --force-reinstall "git+https://github.com/ytdl-org/youtube-dl.git"
Atalee answered 5/6, 2023 at 20:15 Comment(2)
worked for me on ubuntuUltramicrochemistry
Worked on windows as well with pip install --upgrade --force-reinstall "git+github.com/ytdl-org/youtube-dl.git"Thaddeus
L
9

They are aware of and fixed this problem, you can check this GitHub issue.

If you wanna fix it quickly, you can use this package. Or just wait for a new release, it's up to you.

Lignify answered 19/2, 2023 at 10:24 Comment(1)
Will I need to change my entire python code so it will work with yt-dlp?Studdingsail
P
1
python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz

If the installed location is not added to PATH try to specify the location.

python3 /Library/Frameworks/Python.framework/Versions/3.7/bin/yt-dlp --no-check-certificate "https://www.youtube.com/watch?v=QvkQ1B3FBqA"
Paulie answered 17/5, 2023 at 9:24 Comment(0)
K
0
    ytdl_format_options = {
    'format': 'bestaudio/best',
    'restrictfilenames': True,
    'noplaylist': True,
    'extractor_retries': 'auto',
    'nocheckcertificate': True,
    'ignoreerrors': False,
    'logtostderr': False,
    'quiet': True,
    'no_warnings': True,
    'default_search': 'auto',
    'source_address': '0.0.0.0' # bind to ipv4 since ipv6 addresses cause issues sometimes

add extractor_retries works perfect with me :)

Karlie answered 13/3, 2023 at 1:54 Comment(0)
E
0

Don't use this:

    ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s%(ext)s'})
    from __future__ import unicode_literals
    import youtube_dl
    ydl_opts = {
         'format': 'bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192'
        }],
        'postprocessor_args': [
            '-ar', '16000'
        ],
        'prefer_ffmpeg': True,
        'keepvideo': True
    }
    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download(['link'])

use this:
from pytube import YouTube
import os

yt = YouTube('link')

video = yt.streams.filter(only_audio=True).first()

out_file = video.download(output_path=".")

base, ext = os.path.splitext(out_file)
new_file = base + '.mp3'
os.rename(out_file, new_file)

Above code will definitely run.

Elburr answered 31/3, 2023 at 21:0 Comment(0)
P
0

To install the latest version with Homebrew:

brew uninstall youtube-dl
brew install --HEAD youtube-dl    

--HEAD is what matters here, it takes the latest version on the repository.

cf. the Homebrew man page

Putnem answered 4/8, 2023 at 18:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.