skip to Main Content

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;

}

2

Answers


  1. 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)
    
    Login or Signup to reply.
  2. 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();
    
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search