Latest 0.2.0
Homepage https://github.com/devandsev/YoutubeDirectLinkExtractor
License MIT
Platforms ios 8.0, osx 10.9
Frameworks Foundation, AVFoundation
Authors

Build Status

YoutubeDirectLinkExtractor allows you to obtain the direct link to a YouTube video, which you can easily use with AVPlayer.
It uses type safety and optionals to guarantee that you won’t crash while extracting the link no matter what. There are popular alternatives, which use more straightforward and risky approach, though: YoutubeSourceParserKit, HCYoutubeParser.

Installation

CocoaPods

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
    pod 'YoutubeDirectLinkExtractor'
end

Replace YOUR_TARGET_NAME and then, in the Podfile directory, type:

$ pod install

Carthage

Add this to Cartfile

github "devandsev/YoutubeDirectLinkExtractor"

In the Cartfile directory, type:

$ carthage update

Usage examples

Any force unwrapping used here is just for keeping examples short, don’t use it in real projects.

Basic usage:

let y = YoutubeDirectLinkExtractor()
y.extractInfo(for: .urlString("https://www.youtube.com/watch?v=HsQvAnCGxzY"), success: { info in
    print(info.highestQualityPlayableLink)
}) { error in
    print(error)
}

Extract lowest quality video link from id:

let y = YoutubeDirectLinkExtractor()
y.extractInfo(for: .id("HsQvAnCGxzY"), success: { info in
    print(info.lowestQualityPlayableLink)
}) { error in
    print(error)
}

Use extracted video link with AVPlayer:

let y = YoutubeDirectLinkExtractor()
y.extractInfo(for: .urlString("https://www.youtube.com/watch?v=HsQvAnCGxzY"), success: { info in
    let player = AVPlayer(url: URL(string: info.highestQualityPlayableLink!)!)
    let playerViewController = AVPlayerViewController()
    playerViewController.player = player

    self.present(playerViewController, animated: true) {
        playerViewController.player!.play()
    }
}) { error in
    print(error)
}

License

This project is licensed under the MIT License – see the LICENSE file for details.

Latest podspec

{
    "name": "YoutubeDirectLinkExtractor",
    "version": "0.2.0",
    "summary": "Get the direct link to a YouTube video for AVPlayer",
    "description": "YoutubeDirectLinkExtractor allows you to obtain the direct link to a YouTube video, which you can easily use with AVPlayer.",
    "homepage": "https://github.com/devandsev/YoutubeDirectLinkExtractor",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Andrey Sevrikov": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9"
    },
    "source": {
        "git": "https://github.com/devandsev/YoutubeDirectLinkExtractor.git",
        "tag": "0.2.0"
    },
    "source_files": "Sources/**/*",
    "frameworks": [
        "Foundation",
        "AVFoundation"
    ],
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This