如何在2023年使用youtube_explode_dart包下载URL?

huangapple go评论68阅读模式
英文:

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&lt;String&gt; 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) =&gt; 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&lt;String&gt; 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();


}

huangapple
  • 本文由 发表于 2023年7月27日 22:02:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780547.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定