<commit_before># youtube-parser
[![Build Status](https://travis-ci.org/toygard/youtube-parser.svg?branch=master)](https://travis-ci.org/toygard/youtube-parser) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/isair/JSONHelper?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

YouTube link parser for swift

##Introduction

__Requires iOS 7 or later and Xcode 6.1+__

##Installation

###[Cocoapods](https://github.com/CocoaPods/CocoaPods)

To install via CocoaPods add this line to your `Podfile`.

```
use_frameworks!

pod "youtube-parser"
```

Then, run the following command:

```$ pod install```

##Usage

```swift
import youtube_parser
```

```swift
let testURL = NSURL(string: "https://www.youtube.com/watch?v=ngElkyQ6Rhs")!
Youtube.h264videosWithYoutubeURL(testURL, completion: { (videoInfo, error) -> Void in
    if let
        videoURLString = videoInfo?["url"] as? String,
        videoTitle = videoInfo?["title"] as? String {
            println("\(videoTitle)")
            println("\(videoURLString)")
        }
})
```

```
videoInfo output: 
```
```json
{
    "title": "[Video Title]",
    "isStream": 0,
    "quality": "hd720",
    "itag": 22,
    "fallback_host": "tc.v20.cache2.googlevideo.com",
    "url": "http://[Source URL]"
}
```<commit_msg>Add MPMoviePlayerController Usage<commit_after># youtube-parser
[![Build Status](https://travis-ci.org/toygard/youtube-parser.svg?branch=master)](https://travis-ci.org/toygard/youtube-parser) [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/isair/JSONHelper?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

YouTube link parser for swift

##Introduction

__Requires iOS 7 or later and Xcode 6.1+__

##Installation

###[Cocoapods](https://github.com/CocoaPods/CocoaPods)

To install via CocoaPods add this line to your `Podfile`.

```
use_frameworks!

pod "youtube-parser"
```

Then, run the following command:

```$ pod install```

##Usage

```swift
import youtube_parser
```

```swift
let testURL = NSURL(string: "https://www.youtube.com/watch?v=ngElkyQ6Rhs")!
Youtube.h264videosWithYoutubeURL(testURL, completion: { (videoInfo, error) -> Void in
    if let
        videoURLString = videoInfo?["url"] as? String,
        videoTitle = videoInfo?["title"] as? String {
            println("\(videoTitle)")
            println("\(videoURLString)")
        }
})
```

```
videoInfo output: 
```
```json
{
    "title": "[Video Title]",
    "isStream": 0,
    "quality": "hd720",
    "itag": 22,
    "fallback_host": "tc.v20.cache2.googlevideo.com",
    "url": "http://[Source URL]"
}
```

##MPMoviePlayerController Usage
```swift
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=ngElkyQ6Rhs")!
    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)
      }
    })
  }
}
```
{'fraction_non_alphanumeric': 0.1612339930151339, 'fraction_numerical': 0.011641443538998836, 'mean_word_length': 4.191842900302115, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 13, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3119809', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1189, 'n_words': 223}