youtubelength

package module
v0.0.0-...-5f3917c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 5, 2018 License: MIT Imports: 7 Imported by: 0

README

4d63.com/youtubelength

Build Status Codecov Go Report Card Go docs

Go package that gets the length of Youtube videos.

Usage

import "4d63.com/youtubelength"
length, err := youtubelength.Get(context.Background(), "G_OlRWGLdnw")

Usage (App Engine)

import (
	"net/http"

	"google.golang.org/appengine"
	"google.golang.org/appengine/urlfetch"

	"4d63.com/youtubelength"
)

func handler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	httpClient := urlfetch.Client(c)
	ytlClient := youtubelength.Client{HTTPClient:httpClient}
	length, err := ytlClient.Get(c, "G_OlRWGLdnw")
	...
}

Documentation

Overview

Package youtubelength get the length of Youtube videos.

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultClient = Client{}

DefaultClient is a default youtubelength.Client.

Functions

func Get

func Get(c context.Context, videoID string) (time.Duration, error)

Get gets the length of the video using the DefaultClient.

Example
package main

import (
	"context"
	"fmt"

	"4d63.com/youtubelength"
)

func main() {
	// https://www.youtube.com/watch?v=G_OlRWGLdnw
	length, err := youtubelength.Get(context.Background(), "G_OlRWGLdnw")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(length)
}
Output:

6m51s

Types

type Client

type Client struct {
	// HTTPClient is an optional http.Client that will be used to get the
	// length of the Youtube video. If it is not set a zero http.Client with a
	// timeout of 10s will be used.
	HTTPClient *http.Client
}

Client is the client that can get the length of a Youtube video.

func (*Client) Get

func (cl *Client) Get(c context.Context, videoID string) (time.Duration, error)

Get gets the length of the video.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL