Retrieve Video Stream from Youtube Link

CursedMagic

I am currently working on a project to retrieve mp3 files from the audio of YouTube videos.

I started my project with some basic parsing of youtube links and came up with a regex to extract the id.

    private static string GetYoutubeID(string url)
    {
        var match = youtubeRegex.Match(url);

        if(match.Success)
        {
            return match.Groups[0].Value ?? throw new ArgumentException("url");
        }
        else
        {
            throw new ArgumentException(url);
        }
    }

Then i am using the id in a request like so:

    public static string GetResponse(string id)
    {
        using (WebClient client = new WebClient())
        {
            return client.DownloadString($"http://youtube.com/get_video_info?video_id={id}");
        }
    }

So now this call returns a string with tags like "status" and "errorcode". There is also one particular tag named "url_encoded_fmt_stream_map". In it I can find the urls to download the videos in various qualities.
For Exampe:

https%3A%2F%2Fr2---sn-h0jeened.googlevideo.com%2Fvideoplayback...

But my query seemed to fail and the result delivered me an empty "url_encoded_fmt_stream_map"-tag with "status=fail" and the "errorcode=150" which is "video unavailable".

From my understanding the libraries out there to help downloading youtube videos have some similar problems.

So my question is, is my method reliable? If so, what am I doing wrong?

And if it is not reliable, how can i reliably retrieve a link to a video stream?

CursedMagic

I was able to fix my problem. After some more trying and searching I was able to change the request url to achieve a result.

For anyone interested:

https://www.youtube.com/get_video_info?video_id={id}

Can be changed to:

https://www.youtube.com/get_video_info?video_id={id}&el=detailpage

This returns a full answer for me and the error 150 does not occur anymore for me.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Retrieve video ID from YouTube link

Getting video id "Live Stream" from Youtube

Stream YouTube video from extracted url

Playing video from youtube link without UIWebView

Show one video in webview by link from YouTube

Stream a recoreded Video to youtube

How to retrieve youtube comments from a specific video using Eclipse

Retrieve array of video IDs from youtube playlist ID

php Youtube Get video id from live_stream

How to open a Youtube video link directly from android app?

Play first youtube embedded video from a list of link using jQuery

Extract just the audio link from a youtube video without converting

How can I get the link to YouTube Channel from Video Page?

Python: getting the youtube author image from the video link

Link of embed youtube video scraping

Get youtube video link in python

Youtube Video feeds link not working

Link to youtube video with start and stop

Retrieve what video resolutions(quality) a youtube video with youtube api?

Retrieve stream from Optional<Stream>

Stream audio from youtube

How to retrieve a youtube video keywords with php

How to retrieve details of single video from youtube using videoID through Data API v3.0 in Android?

Retrieve video ids from playlist id - youtube api v3

How do I retrieve individual video URLs from a playlist, using youtube-dl within a python script?

Retrieve YouTube live_stats concurrent viewers from channel instead of specific live event video

Google Apps Script: Retrieve most recent video ids from Youtube API v3 as array

FFmpeg: Looping an video/audio stream to YouTube Live

How to play Youtube live stream video in application?