英文:
Error: Unable to extract uploader id - Youtube, Discord.py
问题
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 an 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?
以下是您提供的代码部分,不需要翻译:
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))
if 'entries' in data:
# take the first item from a playlist
data = data['entries'][0]
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)
英文:
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)
答案1
得分: 86
这是一个已知问题,已在主版本中修复。要进行临时修复,可以执行以下命令:
python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz
这会安装主版本。然后,通过命令行运行以下命令:
yt-dlp URL
其中URL是您想要的视频的网址。可以使用yt-dlp --help
查看所有选项。应该能够正常运行而没有错误。
如果您将其用作模块,可以尝试导入yt_dlp
,这可能会修复您的问题(尽管可能会有破坏您代码的API更改,我不知道您使用的yt_dlp
版本是哪个)。
英文:
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).
答案2
得分: 59
我已经解决了它(v2021.12.17
),直到有新的更新,
通过编辑文件:your/path/to/site-packages/youtube_dl/extractor/youtube.py
示例(如果通过PIP安装):~/.local/lib/python3.10/site-packages/youtube_dl/extractor/youtube.py
行号(〜):1794 并添加选项 fatal=False
之前:
'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id') if owner_profile_url else None
之后:
'uploader_id': self._search_regex(r'/(?:channel|user)/([^/?&#]+)', owner_profile_url, 'uploader id', fatal=False) if owner_profile_url else None
这将它从关键错误(退出脚本)转换为警告(只是继续进行)
英文:
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
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)
答案3
得分: 19
首先卸载 youtube_dl,使用 pip uninstall youtube_dl
,然后从他们的 GitHub 安装 youtube_dl 的主分支,使用 pip install git+https://github.com/ytdl-org/youtube-dl.git@master#egg=youtube_dl
。为此,你需要 Git,可以在这里下载。我已经测试过,它实际上可以正常工作。
英文:
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.
答案4
得分: 9
他们已经意识到并修复了这个问题,你可以查看这个GitHub问题。
如果你想快速解决它,可以使用这个包。或者只需等待新版本发布,由你决定。
英文:
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.
答案5
得分: 9
这是适用于Ubuntu/Linux的修复方法:
- 安装git(如果未安装 | 检查命令:$ git --version)
sudo apt install git
- 安装pip(Python包管理器,如果未安装)
sudo apt install pip
- 直接从git仓库重新安装youtube-dl
sudo pip install --upgrade --force-reinstall "git+https://github.com/ytdl-org/youtube-dl.git"
英文:
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"
答案6
得分: 1
python3 -m pip install --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.tar.gz
如果已安装位置未添加到 *PATH*,请尝试指定位置。
python3 /Library/Frameworks/Python.framework/Versions/3.7/bin/yt-dlp --no-check-certificate "https://www.youtube.com/watch?v=QvkQ1B3FBqA"
英文:
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"
答案7
得分: 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
添加 extractor_retries
对我来说运行得很好
英文:
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
答案8
得分: 0
不要使用这个:
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'])
使用这个:
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)
上述代码肯定会运行。
英文:
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.
答案9
得分: 0
要使用Homebrew安装最新版本,请执行以下步骤:
brew uninstall youtube-dl
brew install --HEAD youtube-dl
这里重要的是--HEAD
,它会获取存储库中的最新版本。
参考:Homebrew手册页面
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论