youtube

package module
v0.0.0-...-e088d34 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2015 License: MIT Imports: 11 Imported by: 0

README

youtube-go

GoDoc

Small package for searching Youtube videos and getting information about them. It can read video formats and also does signature descrambling so the library can be easily used to download videos.

Full documentation can be found at: http://godoc.org/github.com/adrg/youtube-go

Installation

go get github.com/adrg/youtube-go
Usage
Get video information
package main

import (
	"fmt"

	youtube "github.com/adrg/youtube-go"
)

func main() {
	video, err := youtube.GetVideo("uFknAPhEcQM")
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Printf("Title: %s\n", video.Title)
	fmt.Printf("Id: %s\n", video.Id)
	fmt.Printf("Duration: %d\n", video.Duration)
	fmt.Printf("Description: %s\n", video.Description)
	fmt.Printf("View count: %d\n", video.ViewCount)
	fmt.Printf("Rating: %f\n", video.Rating)

	fmt.Println("Formats:")
	for _, f := range video.Formats {
		fmt.Printf("  * %d - %s %s ===\n", f.Itag, f.Type, f.Quality)
		fmt.Printf("    URL: %s\n", f.URL)
	}
}
Search for videos
package main

import (
	"fmt"

	youtube "github.com/adrg/youtube-go"
)

func main() {
	// The search parameters include the query, the page you want
	// to get results for and the maximum results allowed
	searchParams := &youtube.SearchParams{"amv", 1, 3}
	videos, err := youtube.Search(searchParams)
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, video := range videos {
		if err = video.ReadFormats(); err != nil {
			fmt.Println(err)
			// Handle error here
		}

		fmt.Printf("Title: %s\n", video.Title)
		fmt.Printf("Id: %s\n", video.Id)
		fmt.Printf("Duration: %d\n", video.Duration)
		fmt.Printf("Description: %s\n", video.Description)
		fmt.Printf("View count: %d\n", video.ViewCount)
		fmt.Printf("Rating: %f\n", video.Rating)

		fmt.Println("Formats:")
		for _, f := range video.Formats {
			fmt.Printf("  * %d - %s %s ===\n", f.Itag, f.Type, f.Quality)
			fmt.Printf("    URL: %s\n", f.URL)
		}

		fmt.Println()
	}
}

License

Copyright (c) 2015 Adrian-George Bostan.

This project is licensed under the MIT license. See LICENSE for more details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SearchParams

type SearchParams struct {
	Query      string
	Page       int
	MaxResults int
}

type Video

type Video struct {
	Id          string
	Title       string
	Duration    int
	Description string
	ViewCount   int64
	Rating      float64
	Formats     []*VideoFormat
}

func GetVideo

func GetVideo(id string) (*Video, error)
func Search(params *SearchParams) ([]*Video, error)

func (*Video) ReadFormats

func (v *Video) ReadFormats() error

type VideoFormat

type VideoFormat struct {
	Itag    int
	Type    string
	Quality string
	URL     string
}

Jump to

Keyboard shortcuts

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