gifs

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

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

Go to latest
Published: Apr 13, 2017 License: MIT Imports: 9 Imported by: 0

README

gifs.com Golang Package

Build Status Coverage Status GoDoc Go Report Card

Golang is awesome, and so are gifs. Using gifs.com API you can create gifs from many many different sources. Gifs.com API is already easy, but this simplifies it even more. You'll be able to create basic gifs, and more complex functionality based on your application.

✅ Create gifs via URL (youtube, vimeo, remote mp4, etc)

✅ Upload mp4/image & Download gif

✅ Bulk Upload

✅ Trim gif (start/end in seconds)

Gifs.com allows you to send any instagram, twitter, facebook, vine, .gif, .mp4, .webm, giphy, imgur, gfycat, or streamable links. 👍

Install

go get -u github.com/hunterlong/gifs
import "github.com/hunterlong/gifs"

Simple Usage

Be 😎 and use API keys for added features and limits. gifs.com Authentication API does not require keys.

gifs.Authentication = "gifs00YOURkey2929"

Let's make a gif from a YouTube video.

input := &gifs.New{
  Source: "https://www.youtube.com/watch?v=dDmQ0byhus4",
}

response := input.Create()

fmt.Println("Gifs.com Gif URL: ",response.Files.Gif)

Advanced Usage

You can add all the gifs.com attributes and even tag the gif with a user. You can trim your gif by inserting start and end in seconds. There's even a 'safe' option.

input := &gifs.New{
  Source: "https://www.youtube.com/watch?v=dDmQ0byhus4",
  Title: "Cute Kitten Drinking From Sink",
  Tags: []string{"cute","kitten","drinking"},
  Attribution: &Attribution{
    Site: "twitter",
    User: "stronghold2d",
  },
  Trim: &Trim{
    Start: 10,
    End:   20,
  },
  Safe: true,
}

response, err := input.Create()
if err != nil {
    panic(err)
}

fmt.Println("Gif URL: ", response.Files.Gif)
fmt.Println("Jpg URL: ", response.Files.Jpg)
fmt.Println("Mp4 URL: ", response.Files.Mp4)
fmt.Println("Page URL: ", response.Page)
fmt.Println("oEmbed URL: ", response.Oembed)
fmt.Println("Embed URL: ", response.Embed)

Saving gif

You've seen the responses from gifs.com API, but now I'd like to download the gif and save it locally.

file := &gifs.New{
    Source: "https://www.youtube.com/watch?v=V6wrI6DEZFk",
}

response, _ := file.Create()

gifFile := response.SaveGif()

fmt.Println("Saved gif: ", gifFile)

Upload MP4

Oh whaaat. I have a mp4 file named 'video.mp4' in my current directory and I'd love to have it as a gif.

input := &gifs.New{
    File:  "video.mp4",
    Title: "Nice Video Title",
    Tags:  []string{"gifs", "are", "awesome"},
}

response, err := input.Upload()
if err != nil {
    panic(err)
}

fmt.Println("Gif URL: ", response.Files.Gif)

Bulk Upload

Now I've got the hang of it, I don't need to go one-by-one. Include an array of New files, and Upload! The response will give you an array for each uploaded file.

// work in progress!
files := []gifs.New{
    {
        File:  "video1.mp4",
        Title: "New Video",
    },
    {
        File:  "video2.mp4",
        Title: "New Video 2",
    },
    {
        File:  "video3.mp4",
        Title: "New Video 3",
    },
}

bulk := gifs.Bulk{
    New: files,
}

response, err := bulk.Upload()
if err != nil {
    panic(err)
}

for k, v := range response {
    fmt.Println("File #", k, " Uploaded. File Gif: ", v.Files.Gif)
}

fmt.Println("Uploaded", len(response), "Files")

License

Fun project 💥 How often do you see gifs on github!? Released MIT license with testing.

Documentation

Index

Constants

View Source
const ApiEndpoint string = "https://api.gifs.com"

Variables

View Source
var Authentication string

Functions

func DownloadFile

func DownloadFile(n string, rawURL string) string

func SendRequest

func SendRequest(input []byte, method string) ([]byte, error)

func UploadRequest

func UploadRequest(i *New, fileName string) ([]byte, error)

Types

type Attribution

type Attribution struct {
	Site string `json:"site,omitempty"`
	User string `json:"user,omitempty"`
	Url  string `json:"url,omitempty"`
}

type Bulk

type Bulk struct {
	New []New
}

func (*Bulk) Upload

func (i *Bulk) Upload() ([]ImportResponse, error)

type ImportResponse

type ImportResponse struct {
	Page  string `json:"page"`
	Files struct {
		Gif  string `json:"gif"`
		Jpg  string `json:"jpg"`
		Mp4  string `json:"mp4"`
		Webm string `json:"webm"`
	} `json:"files"`
	Oembed string `json:"oembed"`
	Embed  string `json:"embed"`
	Meta   struct {
		Duration string `json:"duration"`
		Height   string `json:"height"`
		Width    string `json:"width"`
	} `json:"meta"`
}

func (*ImportResponse) SaveGif

func (r *ImportResponse) SaveGif() string

type New

type New struct {
	Source      string       `json:"source,omitempty"`
	File        string       `json:"-"`
	Title       string       `json:"title,omitempty"`
	Tags        []string     `json:"tags,omitempty"`
	Attribution *Attribution `json:"attribution,omitempty"`
	Trim        *Trim        `json:"trim,omitempty"`
	Safe        bool         `json:"nsfw,omitempty"`
}

func (*New) Create

func (i *New) Create() (*ImportResponse, error)

func (*New) Upload

func (i *New) Upload() (*ImportResponse, error)

type Success

type Success struct {
	Response ImportResponse `json:"success"`
}

type Trim

type Trim struct {
	Start int `json:"start,omitempty"`
	End   int `json:"end,omitempty"`
}

Jump to

Keyboard shortcuts

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