70

I have a veary powerfull 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 dosn't wanna work with any video. I tried updataing youtube_dl but it still dosn'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 settup 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)

Aproximately 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)
nikita goncharov
  • 708
  • 1
  • 2
  • 13

9 Answers9

79

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).

innisfree
  • 2,044
  • 1
  • 14
  • 24
56

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 (If installed via PIP): ~/.local/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)

Ricky Levi
  • 7,298
  • 1
  • 57
  • 65
  • 3
    this solved it for me while I'm waiting for homebrew to pick up the update from master – Holgzn Mar 02 '23 at 10:57
  • How did you realized that this could save the run? Some tip do share? – Daniel Bandeira Mar 03 '23 at 19:16
  • 5
    @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 ... – Ricky Levi Mar 06 '23 at 12:38
  • 1
    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. – Éric Mar 15 '23 at 17:49
  • 1
    @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. – user17911 Mar 17 '23 at 23:03
  • 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/extractor` – Matthias Jun 05 '23 at 10:39
18

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.

boez
  • 331
  • 1
  • 8
  • 1
    I notice the use of "youtube-dl" and "youtube_dl", are these typos or interchangeable or distinctly separate entities ? – Dee Mar 07 '23 at 01:03
  • 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. – Gwyneth Llewelyn Mar 13 '23 at 19:59
  • np and yes you are right. – boez Mar 15 '23 at 20:56
  • 1
    @Dee underscores and hyphens are interchangeable for `pip`. Python packages are supposed to use hyphens instead of underscores [(source)](https://peps.python.org/pep-0008/#package-and-module-names). But because of the confusion, both will work. Pypi shows "youtube_dl" but `pip list` shows "youtube-dl" regardless of how you installed it. – wisbucky Jun 08 '23 at 00:55
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.

dogukanarkan
  • 341
  • 2
  • 8
7

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"
Roman M
  • 450
  • 1
  • 5
  • 12
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 :)

DaveL17
  • 1,673
  • 7
  • 24
  • 38
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.

0
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"
Mohan Radhakrishnan
  • 3,002
  • 5
  • 28
  • 42
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

hulius
  • 189
  • 1
  • 8