Oscar Andersson
Oscar Andersson

Reputation: 23

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);

Upvotes: 2

Views: 1907

Answers (1)

marpme
marpme

Reputation: 2435

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

YoutubeExtractor-lib

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

Install-Package YoutubeExtractor

Greeting Kyon.

Upvotes: 1

Related Questions