Code Monkey home page Code Monkey logo

hcvimeovideoextractor's Introduction

HCVimeoVideoExtractor

HCVimeoVideoExtractor is an easy to use Swift library for retrieving the Vimeo video details like title, thumbnail and mp4 URL which then can be used to play using AVPlayerView.


Requirements

HCVimeoVideoExtractor requires iOS 9.0 and Swift 3.2 and above


Installation

CocoaPods

HCVimeoVideoExtractor is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'HCVimeoVideoExtractor'

and run pod install


Swift Package Manager

For Swift Package Manager add the following package to your Package.swift file.

.package(url: "https://github.com/superm0/HCVimeoVideoExtractor.git", .upToNextMajor(from: "0.0.4")),

Usage

Use the block based methods in HCVimeoVideoExtractor class to retrieve the Vimeo video details. Both methods will call a completion handler with two parameters. The first parameter is a HCVimeoVideo object which represents a Vimeo video. The second parameter is an Error object describing the network connection or internal processing error.

import HCVimeoVideoExtractor

Retrieve the Vimeo video details using URL

let url = URL(string: "https://vimeo.com/[video_id]")!
HCVimeoVideoExtractor.fetchVideoURLFrom(url: url, completion: { ( video:HCVimeoVideo?, error:Error?) -> Void in                
    if let err = error {                    
        print("Error = \(err.localizedDescription)")                    
        return
    }
    
    guard let vid = video else {
        print("Invalid video object")
        return
    }
    
    print("Title = \(vid.title), url = \(vid.videoURL), thumbnail = \(vid.thumbnailURL)")
        
    if let videoURL = vid.videoURL[.Quality1080p] {
        let player = AVPlayer(url: videoURL)
        let playerController = AVPlayerViewController()
        playerController.player = player
        self.present(playerController, animated: true) {
            player.play()
        }
    }                            
})

Retrieve the Vimeo video details using video ID

HCVimeoVideoExtractor.fetchVideoURLFrom(id: "video_id", completion: { ( video:HCVimeoVideo?, error:Error?) -> Void in
    if let err = error {
        print("Error = \(err.localizedDescription)")
        return
    }
    
    guard let vid = video else {
        print("Invalid video object")
        return
    }
    
    print("Title = \(vid.title), url = \(vid.videoURL), thumbnail = \(vid.thumbnailURL)")
    
    if let videoURL = vid.videoURL[.quality1080p] {
        let player = AVPlayer(url: videoURL)
        let playerController = AVPlayerViewController()
        playerController.player = player
        self.present(playerController, animated: true) {
            player.play()
        }
    }
})

New Vimeo Videos

For new Vimeo videos, starting October 2022, the video URL can be retrieved through .quality1080p or .qualityUnknown.

Author

Mo Cariaga, [email protected]

License

HCVimeoVideoExtractor is available under the MIT license. See the LICENSE file for more info.

hcvimeovideoextractor's People

Contributors

gali8 avatar sairamkotha avatar superm0 avatar tristan-galang avatar

Forkers

plrohitkios

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.