Error: Unable to extract uploader id – Youtube, Discord.py
Question:
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)
Answers:
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.
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).
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
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)
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.
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 🙂
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.
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"
This fixed (for Ubuntu/Linux):
- install git (if not installed | check command: $ git –version)
sudo apt install git
- install pip (Python package manager, if not installed)
sudo apt install pip
- reinstall youtube-dl directly from git repository
sudo pip install --upgrade --force-reinstall "git+https://github.com/ytdl-org/youtube-dl.git"
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.
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)
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.
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).
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
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)
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.
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 🙂
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.
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"
This fixed (for Ubuntu/Linux):
- install git (if not installed | check command: $ git –version)
sudo apt install git
- install pip (Python package manager, if not installed)
sudo apt install pip
- reinstall youtube-dl directly from git repository
sudo pip install --upgrade --force-reinstall "git+https://github.com/ytdl-org/youtube-dl.git"
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.