我不想一次又一次地从 YouTube 视频下载音频,而是想流式传输音频并直接访问缓冲区中的原始音频字节。换句话说,我想将原始音频字节存储在 RAM 中,并在我的 python 脚本中使用它们,而不需要在系统上完全下载和保存音频文件,以减少内存写入周期。youtube-dl 库或 pafy 库中是否有任何解决方法可以执行相同的操作?
使用youtube-dl
,您可以轻松下载正在进行的直播。
$ youtube-dl --hls-use-mpegts <URL>
Run Code Online (Sandbox Code Playgroud)
但是,如果目标直播流尚未启动,则该命令在打印如下消息后立即退出
[youtube] I1gi2ABCDEf: Downloading webpage
ERROR: This live event will begin in a few moments.
Run Code Online (Sandbox Code Playgroud)
是否可以等到youtube-dl
直播开始后再录制?
我当前的解决方法是这样的:
[youtube] I1gi2ABCDEf: Downloading webpage
ERROR: This live event will begin in a few moments.
Run Code Online (Sandbox Code Playgroud)
或这个:
#pseudo code
while (true) {
start = time()
execute youtube-dl
end = time()
if (end - start > 10seconds) { #if recording succeeded
break
}
sleep(some seconds)
}
Run Code Online (Sandbox Code Playgroud)
现在将两者结合起来可以完美地工作(实际上第二个应该足够了,但我也使用第一个作为后备),但如果有一种更优雅的方式,那就太好了。
I'm using python embedded youtube_dl
and I'd like to download video content directly into a temporary file. I attempted to create a NamedTemporaryFile
and have youtube_dl
write into it, but I always get a prompt that the file was already downloaded (the temporary file has that name and it thinks the download already happened).
I also attempted to have youtube_dl
stream downloaded data to stdout
and redirect stdout
to the temporary file but I can't get the python embedded version …
我正在尝试创建一个 Github Actions 来保存一个列表,其中包含播放列表中所有 YouTube 视频的名称。它在最新的 ubuntu 版本上运行,我正在安装最新的 youtube-dl 版本。
sudo curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl
sudo chmod a+rx /usr/local/bin/youtube-dl
sudo youtube-dl --update
Run Code Online (Sandbox Code Playgroud)
该脚本在某些播放列表上运行良好,但在其他播放列表上我收到此错误消息:
ERROR: No video formats found
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的 youtube-dl 命令。它在我的计算机(Windows)上的任何播放列表上都能完美运行。
youtube-dl --skip-download --get-title --get-id --no-warnings --verbose --no-mark-watched --ignore-errors --no-warnings --geo-bypass --no-progress https://www.youtube.com/playlist?list=${{ secrets.PLAYLIST_ID }} > playlist.txt
Run Code Online (Sandbox Code Playgroud)
我尝试使用详细参数,这是结果
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--skip-download', '--get-title', '--get-id', '--no-warnings', '--verbose', '--no-mark-watched', '--ignore-errors', '--no-warnings', '--geo-bypass', '--no-progress', 'https://www.youtube.com/playlist?list=***']
[debug] Encodings: locale UTF-8, fs …
Run Code Online (Sandbox Code Playgroud) 有没有人可以使用 youtube-dl 和 ffplay 在终端上播放任何音乐 我知道 ffplay 可以使用 shell 播放音频
$ audio stram | ffplay -i -
由于 youtube-dl 的下载速度存在瓶颈,我尝试使用 yt-dlp 而不是 youtube-dl,但我无法让它工作。
我的 mpv.conf 文件如下所示:
script-opts=ytdl_hook-ytdl_path=/usr/local/bin/yt-dlp
当尝试让 mpv 运行时,我收到此警告:
[ytdl_hook] script-opts: unknown key ytdl_path, ignoring
有谁知道问题是什么?我已经阅读了 mpv 文档,它说这应该可行。
mpv 版本是0.27.2
我编写了一个 python 脚本来下载 YouTube URL 列表,并且我想按我要下载的主题更改输出文件夹。
例如,当我下载播放列表时,我希望将此播放列表中的视频下载到当前播放列表命名的文件夹中。但如果它是一个频道,则其中的视频应放入名为 bt it's uploader 的文件夹中。
我如何知道我正在下载的 URL 是播放列表还是频道?由于选项是在下载开始之前传递的,因此我找不到方法来执行此操作。
这是我的代码:
import sys
import yt_dlp
URLS = [
'playlist_url',
'channel_url',
]
dl_ops = {
'outtmpl': 'd:/YouTube/%(uploader)s/%(title)s.%(ext)s'
}
retry_count = 0
def download_video(urls):
try:
with yt_dlp.YoutubeDL(dl_ops) as ydl:
ydl.download(urls)
except KeyboardInterrupt:
print('Interruptted by user')
sys.exit()
except Exception as e:
print(e)
global retry_count
if retry_count == 50:
print('Retry count exceeded')
sys.exit()
retry_count += 1
download_video(urls)
if __name__ == '__main__':
download_video(URLS)
Run Code Online (Sandbox Code Playgroud) 这是我使用 Python 的代码(简化版本):
import yt_dlp
YDL_OPTIONS = {
'format': 'bestaudio*',
'noplaylist': True,
}
with yt_dlp.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
Run Code Online (Sandbox Code Playgroud)
当网址定向到播放列表时(例如https://www.youtube.com/playlist?list=PLlrATfBNZ98dudnM48yfGUldqGD0S4FFb),就会出现问题
这是输出:
import yt_dlp
YDL_OPTIONS = {
'format': 'bestaudio*',
'noplaylist': True,
}
with yt_dlp.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,“noplaylist”选项在这种情况下不起作用。
是否有选项或功能ydl
仅提取整个播放列表中的一个视频信息,例如第一个视频信息?
我需要使用youtube-dl从频道下载新视频,但请记住下次不下载它们,只下载尚未下载的视频.我怎么能这样做?
我使用只能从youtube视频中提取音频youtube-dl
。 下载后,我想将元数据(即艺术家名称和歌曲标题)写入mp3文件。我尝试通过以下代码来实现此目的:
@echo off
set dl=https://www.youtube.com/watch?v=2Y6Nne8RvaA
youtube-dl --metadata-from-title "%(artist)s - %(title)s" --extract-audio --audio-format mp3 -o "%%(title)s.%%(ext)s" --add-metadata %dl%
pause
Run Code Online (Sandbox Code Playgroud)
此代码的输出是:
[youtube] 2Y6Nne8RvaA: Downloading webpage
[youtube] 2Y6Nne8RvaA: Downloading video info webpage
[youtube] 2Y6Nne8RvaA: Extracting video information
[download] Destination: Kungs vs Cookin' on 3 Burners - This Girl.webm
[download] 100% of 3.33MiB in 00:02
[fromtitle] Could not interpret title of video as "(title)s"
[ffmpeg] Adding metadata to 'Kungs vs Cookin' on 3 Burners - This Girl.webm'
[ffmpeg] Destination: Kungs …
Run Code Online (Sandbox Code Playgroud)