TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2015 |
SPMSupports SPM | ✗ |
Maintained by Toygar Dundaralp.
YouTube Video Link Parser for Swift
Requires iOS 8 or later and Xcode 7.0+
Swift support uses dynamic frameworks and is therefore only supported on iOS > 8.
To install via CocoaPods add this line to your Podfile
.
use_frameworks!
and
pod "youtube-parser"
Then, run the following command:
$ pod install
import youtube_parser
let testURL = NSURL(string: "https://www.youtube.com/watch?v=swZJwZeMesk")!
Youtube.h264videosWithYoutubeURL(testURL) { (videoInfo, error) -> Void in
if let videoURLString = videoInfo?["url"] as? String,
videoTitle = videoInfo?["title"] as? String {
print("\(videoTitle)")
print("\(videoURLString)")
}
}
videoInfo output:
{
"title": "[Video Title]",
"isStream": 0,
"quality": "hd720",
"itag": 22,
"fallback_host": "tc.v20.cache2.googlevideo.com",
"url": "http://[Source URL]"
}
import UIKit
import youtube_parser
import MediaPlayer
class ViewController: UIViewController {
let moviePlayer = MPMoviePlayerController()
override func viewDidLoad() {
super.viewDidLoad()
moviePlayer.view.frame = view.frame
view.addSubview(moviePlayer.view)
moviePlayer.fullscreen = true
let youtubeURL = NSURL(string: "https://www.youtube.com/watch?v=swZJwZeMesk")!
playVideoWithYoutubeURL(youtubeURL)
}
func playVideoWithYoutubeURL(url: NSURL) {
Youtube.h264videosWithYoutubeURL(url, completion: { (videoInfo, error) -> Void in
if let
videoURLString = videoInfo?["url"] as? String,
videoTitle = videoInfo?["title"] as? String {
self.moviePlayer.contentURL = NSURL(string: videoURLString)
}
})
}
}