JonasG
JonasG

Reputation: 9324

Get YouTube Audio URL on iOS

I am using this javascript code to get a downloadable video URL from the mobile youtube website.

[webView stringByEvaluatingJavaScriptFromString:@"function getURL() {var player = document.getElementById('player'); var video = player.getElementsByTagName('video')[0]; return video.getAttribute('src');} getURL();"];

Output URL: http://o-o.preferred.seabone-mil1.v22.nonxt2.c.youtube.com/videoplayback?el=results&begin=0&yms=5682703339584930992&itag=18&ip=87.0.0.0&app=youtube_mobile&signature=B8CD6B60D2609F5F137B885806F8FAECAA88492F.333D3F19876A77CECB264059A3852BD021401296&sparams=id%2Cexpire%2Cip%2Cipbits%2Citag%2Csource%2Cratebypass%2Ccp&len=254000&ratebypass=yes&source=youtube&expire=1323579819&sver=3&key=yt1&ipbits=8&cp=U0hRSFVSV19GU0NOMV9NTEFJOmV5Qk5wc3hWaUxG&id=b8e73777013e0b7e&ps=blazer

I would like to do the same with just the audio of the video. But i haven't succeeded yet. Can anyone help me?

Upvotes: 0

Views: 1405

Answers (2)

JonasG
JonasG

Reputation: 9324

I solved it! I use the youtube-mp3.org api which works really good. there are some questions about it on SO with good answers!

Upvotes: 1

Damien
Damien

Reputation: 2421

It's going to be difficult to extract the audio only portions from an existing video from within iOS. I'm sure there are libs out there that can help, but I think it's going to be an involved topic.

Perhaps you can take a look at Display YouTube Videos Without Exiting Your Application. It describes ways to play youtube videos from within your iOS application. Now if you do something similar but set the view to be hidden, you would be able to "listen" to the youtube videos's audio without showing the video itself on the screen.

I don't know what the end-goal is for you're application, but perhaps my suggestion will be food-for-thought.

Upvotes: 0

Related Questions