Wraecca / YoutubeSourceParserKit

YouTube link parser for swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

YoutubeSourceParserKit

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

YouTube Video Link Parser for Swift

##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)
      }
    })
  }
}

About

YouTube link parser for swift

License:MIT License


Languages

Language:Swift 94.2%Language:Ruby 5.8%