Tyrrrz / YoutubeExplode

Abstraction layer over YouTube's internal API
MIT License
2.93k stars 491 forks source link

Audio files are downloaded as WebM, Mp3 does not work #738

Closed ReenigneArcher closed 1 year ago

ReenigneArcher commented 1 year ago

Version

v6.3.4

Platform

.NET 6.0 (Linux and macOS... maybe Windows)

Steps to reproduce

using YoutubeExplode;
using YoutubeExplode.Videos.Streams;

// ...

        private static void SaveMp3(string destination, string videoUrl)
        {
            Task.Run(async () =>
            {
                var youtube = new YoutubeClient();
                var streamManifest = await youtube.Videos.Streams.GetManifestAsync(videoUrl);

                // highest bitrate audio stream
                var streamInfo = streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate();

                // Download the stream to a file
                await youtube.Videos.Streams.DownloadAsync(streamInfo, destination);
            });
        }

// ...

Details

I am a super beginner with C#, so this could possibly be a problem with my code... although I have had this released for seven months so far, and this is a new issue that has not been reported before.

This issue is from Themerr-jellyfin (plugin for Jellyfin that adds theme songs to Movies). We use YoutubeExplode to get the audio from YouTube videos.

Anyway, a user is reporting that the downloaded audio files are corrupt and unplayable with standard media players (they at least tested in Quick Time). And Jellyfin throws an error when it tries to play as well, so the files are surely corrupted.

Original code: https://github.com/LizardByte/Themerr-jellyfin/blob/6e72a1708cf7248a7a91276cc56ebec5ba2db446/Jellyfin.Plugin.Themerr/ThemerrManager.cs#L37-L50

Original issue: https://github.com/LizardByte/Themerr-jellyfin/issues/97

I can provide further info if requested, just not sure what else you might need at this point.

P.S. They also tested my plugin with v6.3.3 of YoutubeExplode with the same results.

Checklist

ReenigneArcher commented 1 year ago

Some additional information. I don't think the file is actually corrupted, but I think it is downloading a WebM file instead of an mp3 as it used to.

This does not work to select an Mp3

var streamInfo = streamManifest
    .GetAudioOnlyStreams()
    .Where(s => s.Container == Container.Mp3)
    .GetWithHighestBitrate();

This does work.

var streamInfo = streamManifest
    .GetAudioOnlyStreams()
    .Where(s => s.Container == Container.Mp4)
    .GetWithHighestBitrate();

Anyway to get it an Mp3 container directly? I am checking the hex signature and it would be easier if it's an mp3 container. If not, it's not a huge deal and feel free to close this issue.

Tyrrrz commented 1 year ago

YouTube does not provide MP3 streams, only WEBM and MP4. Therefore, you need to convert those streams to MP3 yourself, for example using YoutubeExplode.Converter. This is not new, it has always been like that.

ReenigneArcher commented 1 year ago

Interesting, maybe be some changes to YouTube itself where the highest bitrate item is now a WebM stream instead of Mp4. Anyway, thanks for this library!