Oscar Andersson Oscar Andersson - 12 days ago 13x
C# Question

C# : Trying to download mp3 generated through youtube-to-mp3 api, but all I get is a 0 byte mp3 file

I'm using this (https://www.youtubeinmp3.com/api/) api to fetch links for downloading mp3 versions of youtube videos. The api doesn't give me access to a .mp3 file directly, but to a generated "webpage" that starts the download immediately.

Now my issue is, I'm using the BackgroundDownloader class to download the mp3, but I believe I'm downloading an empty HTML-page instead of the actual mp3 file.

Here's what my code looks like:

Uri source = new Uri(dlurl);

StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFile destinationFile = await folder.CreateFileAsync(
dltitle + ".mp3", CreationCollisionOption.GenerateUniqueName);

BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);

// Attach progress and completion handlers.
HandleDownloadAsync(download, true);


I'd recommend using this custom lib, which supports "direct" youtube video download with custom bitrates and also custom video/audio formats (incl. mp3).


You can easily install this by using the NUGET Package-Manager:

Install-Package YoutubeExtractor

Greeting Kyon.