英文:
How to download URL using youtube_explode_dart package in 2023?
问题
我想使用URL从YouTube下载视频,只下载音频。我正在使用youtube_explode_dart
来实现这个目的,但是代码方法已经迁移,尽管我查看了包的文档,但仍然无法弄清楚如何只下载音频。
我的代码:
Future<String> getDownloadUrl(String videoId) async {
var youtube = YoutubeExplode();
var video = await youtube.videos.get(videoId);
return youtube.streamsClient.getAudioOnly().first.url;
}
英文:
I want to download videos using audioOnly
from youtube using URL, I am using youtube_explode_dart
for this purpose, but the code method has migrated now, I cant figure out despite checking documentation of package, that how to download audio only.
my code:
Future<String> getDownloadUrl(String videoId) async {
var youtube = YoutubeExplode();
var video = await youtube.videos.get(videoId);
return youtube.streamsClient.getAudioOnly().first.url;
}
答案1
得分: 0
正如官方文档所述,它提到了audioOnly属性仅可用于此目的。> 最高比特率的纯音频流。您可以再次查看官方文档以获取更多信息。
https://pub.dev/packages/youtube_explode_dart
// 获取最高质量的混流
var streamInfo = streamManifest.muxed.withHigestVideoQuality();
// ...或最高比特率的纯音频流
var streamInfo = streamManifest.audioOnly.withHigestBitrate()
// ...或最高质量的MP4纯视频流
var streamInfo.videoOnly.where((e) => e.container == Container)
英文:
As in the official documentation, it's mentioned that audioOnly properties just we can use for this purpose only. > highest bitrate audio-only stream. You can check out the official document once again for more info.
https://pub.dev/packages/youtube_explode_dart
// Get highest quality muxed stream
var streamInfo = streamManifest.muxed.withHigestVideoQuality();
// ...or highest bitrate audio-only stream
var streamInfo = streamManifest.audioOnly.withHigestBitrate()
// ...or highest quality MP4 video-only stream
var streamInfo.videoOnly.where((e) => e.container == Container)
答案2
得分: 0
你正在做正确的事情,但是使用了旧的方法,更新你的代码如下所述,并查看最新的youtube_explode_dart
包的文档以更好地理解。
Future<String> getDownloadUrl(String videoId) async {
var youtube = YoutubeExplode();
var video = await youtube.videos.get(videoId);
// 获取视频的流清单
var streamManifest = await youtube.videos.streamsClient.getManifest(videoId);
// 从清单中获取仅包含音频的流
var audioOnlyStreams = streamManifest.audioOnly;
// 获取最高质量的音频流
var audioStream = audioOnlyStreams.withHighestBitrate();
// 返回音频流的URL
return audioStream.url.toString();
}
注意:这是你提供的代码的翻译版本,用于参考和更新你的代码。
英文:
You are doing it right but with old methods, update your code to the following mentioned, also check latest youtube_explode_dart
package's documentation to understand better.
Future<String> getDownloadUrl(String videoId) async {
var youtube = YoutubeExplode();
var video = await youtube.videos.get(videoId);
// Get the stream manifest for the video
var streamManifest = await youtube.videos.streamsClient.getManifest(videoId);
// Get the audio-only streams from the manifest
var audioOnlyStreams = streamManifest.audioOnly;
// Get the highest quality audio-only stream
var audioStream = audioOnlyStreams.withHighestBitrate();
// Return the URL of the audio stream
return audioStream.url.toString();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论