GithubHelp home page GithubHelp logo

YouTube API public? about xcdyoutubekit HOT 3 CLOSED

0xced avatar 0xced commented on September 16, 2024
YouTube API public?

from xcdyoutubekit.

Comments (3)

getaaron avatar getaaron commented on September 16, 2024 2

What I also tried is to write a web service based on youtube-dl that takes a video identifier and returns a HTTP 302 redirect to the video mp4 URL. […] it only works if your server is in the same region as the client

Here's a middle-ground solution: create a web service that provides enough data so this control could react to minor API changes without requiring app updates.

For example, these strings are hardcoded into the class: @"https://www.youtube.com/get_video_info?video_id=%@%@&ps=default&eurl=&gl=US&hl=%@", @"url_encoded_fmt_stream_map", @"thumbnail_url", @"iurlmaxres", @"embedded", @"detailpage", @"vevo", and @"&el=". (This list isn't exhaustive.) YouTube could break most clients using this unauthorized endpoint by simply renaming some of these strings. Allowing them to be obtained remotely would make the class less brittle.

An even more robust solution would be for the client to GET the get_video_info endpoint, attempt to find the correct URL, and upon failure, POST self.connectionData to a web service, which might have updated logic for parsing out the correct URL. This would circumvent the region issue. Also, this would work well combined with the first solution, which could protect against moving the get_video_info endpoint.

Of course, there are also some downsides:

  • there are negative performance implications with both of these approaches
  • this logic could add significant complexity to this simple class
  • these approaches would violate "tell, don't ask" if implemented in the same class

That said, they could be used to make this class more flexible.

from xcdyoutubekit.

MosheBerman avatar MosheBerman commented on September 16, 2024

@steipete, I looked through the code and it appears that @0xced is using an unsupported YouTube endpoint to access the video streaming URL. YouTube has an endpoint called get_video_info that can be used like so:
https://www.youtube.com/get_video_info?video_id=793iPAXJYHQ&ps=default&eurl=&gl=US&hl=en It returns a URL encoded string which contains, among other things, a URL to the video's stream.

This Stack Overflow answer says that the endpoint in question isn't officially supported.

Here are the key points:

The method - (void) startVideoInfoRequest (Line 101) initializes the video metadata download from YouTube endpoint.

The function DictionaryWithQueryStream (line 17) converts the query string into a dictionary.

On line 157, the URL connection's delegate handles the completion of the info request.

On line 183, the URL is removed from the newly created dictionary and used.

I googled a bit, and found that the youtube.com/get_video_info endpoint is not officially supported, but seems the be the way to get a direct stream URL.

So in short, no it's nonstandard.

from xcdyoutubekit.

0xced avatar 0xced commented on September 16, 2024

Indeed this API is not documented and might break. As I wrote in the README, the only official way of playing a YouTube video on iOS is with a UIWebView and the iframe player API. I really wanted to use a supported API so I tried PBYouTubeVideoViewController. Unfortunately the user experience — especially for a full-screen video — is terrible. The component itself is pretty good but it doesn’t have any control over the the video player and thus can’t fix these annoyances:

  • You get embedded style controls even if you want to present in full screen
  • You can’t use presentMoviePlayerViewControllerAnimated:
  • Loading is slow
  • You get the YouTube style activity indicator
  • Rotating the video is not smooth
  • I once managed to somehow get the YouTube desktop style video controls (red progress bar etc.)

What I also tried is to write a web service based on youtube-dl that takes a video identifier and returns a HTTP 302 redirect to the video mp4 URL. Since you have control over your server, you could quickly react if the get_video_info URL stops working. But unfortunately it only works if your server is in the same region as the client else you might get a HTTP 403 error when trying to access the video mp4 URL. 😞

So, we are left with an unsupported API but a much better user experience…

from xcdyoutubekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.