Skip to content

toygar-zzz/YoutubeSourceParserKit

 
 

Repository files navigation

YoutubeSourceParserKit

================== Build Status License Dependencies Ready StackOverflow CocoaPods Join the chat at https://gitter.im/mobileplayer/mobileplayer-ios

YouTube Video Link Parser for Swift. Heavily inspried from hellozimi's repo HCYoutubeParser

##Introduction

Requires iOS 8 or later and Xcode 7.0+
Swift support uses dynamic frameworks and is therefore only supported on iOS > 8.

##Installation

To install via CocoaPods add this line to your Podfile.

use_frameworks!

and

pod 'YoutubeSourceParserKit'

Then, run the following command:

$ pod install

##Usage

import YoutubeSourceParserKit
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]"
}

##MPMoviePlayerController Usage

alt tag

import UIKit
import YoutubeSourceParserKit
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)
      }
    })
  }
}

Warning: This repo is for educational purposes. This is not approved by the ToC of YouTube. Use at own risk.

About

YouTube link parser for swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 94.4%
  • Ruby 5.6%