vlcctrl

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: MIT Imports: 8 Imported by: 3

README

logo

go-vlc-ctrl : Control VLC with Go

go.dev reference godoc reference go report card GitHub license release

A simple yet powerful module that allows you to control VLC instances over the VLC Web API.

Installation

Make sure you have Go installed and just open up a terminal window and run:

go get github.com/CedArctic/go-vlc-ctrl

Example

To run this example, enable the VLC Web Interface (View > Add Interface > Web) and make sure it has a password set to "password" (Preferences > All > Main interfaces > Lua > Lua HTTP > Password).

Alternatively you can launch VLC with a Web Interface from the command prompt / terminal (use macosx instead of qt if on macOS):

vlc --intf http --extraintf qt --http-password password
package main

import (
	"github.com/CedArctic/go-vlc-ctrl"
	"time"
)

func main(){
	// Declare a local VLC instance on port 8080 with password "password"
	myVLC, _ := vlcctrl.NewVLC("127.0.0.1", 8080, "password")

	// Add items to playlist. Note URIs are URL percent-encoded
	myVLC.Add("file:///C:/Users/Jose/Music/Back%%20In%%20Black.mp3")
	myVLC.Add("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

	// Play first item and wait for 10 seconds
	myVLC.Play()
	time.Sleep(10 * time.Second)
	
	// Skip to next item, toggle full screen and pause after 30s
	myVLC.Next()
	myVLC.ToggleFullscreen()
	time.Sleep(30 * time.Second)
	myVLC.Pause()
}

Documentation

You can find documentation of all functions on GoDoc or Go.dev.

The module fully covers the VLC Web API as documented here.

Contributing

Contributions to the project in any way are welcome

Resources

License

Copyright (c) 2020 CedArctic. This project is licensed under the MIT license.

Documentation

Overview

Package vlcctrl provides functions to control VLC instances through the web API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Equalizer added in v0.4.0

type Equalizer struct {
	Presets map[string]string `json:"presets"`
	Bands   map[string]string `json:"bands"`
	Preamp  int               `json:"preamp"`
}

Equalizer contains information related to the equalizer configuration. An Equalizer variable is included in Status

type File added in v0.5.0

type File struct {
	Type             string `json:"type"` // file or dir
	Path             string `json:"path"`
	Name             string `json:"name"`
	AccessTime       uint   `json:"access_time"`
	UID              uint   `json:"uid"`
	CreationTime     uint   `json:"creation_time"`
	GID              uint   `json:"gid"`
	ModificationTime uint   `json:"modification_time"`
	Mode             uint   `json:"mode"`
	URI              string `json:"uri"`
	Size             uint   `json:"size"`
}

File struct represents a single item in the browsed directory. Can be a file or a dir

func ParseBrowse added in v0.4.0

func ParseBrowse(browseResponse string) (files []File, err error)

ParseBrowse parses Browse() responses to []File

type Information added in v0.4.0

type Information struct {
	Chapter int `json:"chapter"`
	// TODO: Chapters definition might need to be changed
	Chapters []interface{} `json:"chapters"`
	Title    int           `json:"title"`
	// TODO: Category definition might need to be updated/modified
	Category map[string]struct {
		Filename      string `json:"filename"`
		Codec         string `json:"Codec"`
		Channels      string `json:"Channels"`
		BitsPerSample string `json:"Bits_per_sample"`
		Type          string `json:"Type"`
		SampleRate    string `json:"Sample_rate"`
	} `json:"category"`
	Titles []interface{} `json:"titles"`
}

Information contains information related to the item currently being played. It is also part of Status

type Node added in v0.4.0

type Node struct {
	Ro       string `json:"ro"`
	Type     string `json:"type"` // node or leaf
	Name     string `json:"name"`
	ID       string `json:"id"`
	Duration int    `json:"duration,omitempty"`
	URI      string `json:"uri,omitempty"`
	Current  string `json:"current,omitempty"`
	Children []Node `json:"children,omitempty"`
}

Node structure (node or leaf type) is the basic element of VLC's playlist tree representation. Leafs are playlist items. Nodes are playlists or folders inside playlists.

func ParsePlaylist added in v0.4.0

func ParsePlaylist(playlistResponse string) (playlist Node, err error)

ParsePlaylist parses Playlist() responses to Node

type Stats added in v0.4.0

type Stats struct {
	InputBitRate        float64 `json:"inputbitrate"`
	SentBytes           uint    `json:"sentbytes"`
	LosABuffers         uint    `json:"lostabuffers"`
	AveragedEMuxBitrate float64 `json:"averagedemuxbitrate"`
	ReadPackets         uint    `json:"readpackets"`
	DemuxReadPackets    uint    `json:"demuxreadpackets"`
	LostPictures        uint    `json:"lostpictures"`
	DisplayedPictures   uint    `json:"displayedpictures"`
	SentPackets         uint    `json:"sentpackets"`
	DemuxReadBytes      uint    `json:"demuxreadbytes"`
	DemuxBitRate        float64 `json:"demuxbitrate"`
	PlayedABuffers      uint    `json:"playedabuffers"`
	DemuxDiscontinuity  uint    `json:"demuxdiscontinuity"`
	DecodeAudio         uint    `json:"decodedaudio"`
	SendBitRate         float64 `json:"sendbitrate"`
	ReadBytes           uint    `json:"readbytes"`
	AverageInputBitRate float64 `json:"averageinputbitrate"`
	DemuxCorrupted      uint    `json:"demuxcorrupted"`
	DecodedVideo        uint    `json:"decodedvideo"`
}

Stats contains certain statistics of a VLC instance. A Stats variable is included in Status

type Status added in v0.4.0

type Status struct {
	// TODO: The Status structure is still a work in progress
	Fullscreen    bool              `json:"fullscreen"`
	Stats         Stats             `json:"stats"`
	AspectRatio   string            `json:"aspectratio"`
	AudioDelay    float64           `json:"audiodelay"`
	APIVersion    uint              `json:"apiversion"`
	CurrentPlID   uint              `json:"currentplid"`
	Time          uint              `json:"time"`
	Volume        uint              `json:"volume"`
	Length        uint              `json:"length"`
	Random        bool              `json:"random"`
	AudioFilters  map[string]string `json:"audiofilters"`
	Rate          float64           `json:"rate"`
	VideoEffects  VideoEffects      `json:"videoeffects"`
	State         string            `json:"state"`
	Loop          bool              `json:"loop"`
	Version       string            `json:"version"`
	Position      float64           `json:"position"`
	Information   Information       `json:"information"`
	Repeat        bool              `json:"repeat"`
	SubtitleDelay float64           `json:"subtitledelay"`
	Equalizer     Equalizer         `json:"equalizer"`
}

Status contains information related to the VLC instance status. Use parseStatus to parse the response from a status.go function.

func ParseStatus added in v0.4.0

func ParseStatus(statusResponse string) (status Status, err error)

ParseStatus parses GetStatus() responses to Status struct.

type VLC added in v0.3.0

type VLC struct {
	IP       string
	Port     int
	Password string
	BaseURL  string // combination of IP and Port
}

VLC struct represents an http interface enabled VLC instance. Build using NewVLC()

func NewVLC

func NewVLC(ip string, port int, password string) (VLC, error)

NewVLC builds and returns a VLC struct using the IP, Port and Password of the VLC instance

func (*VLC) Add added in v0.3.0

func (instance *VLC) Add(uri string) (err error)

Add adds a URI to the playlist

func (*VLC) AddStart added in v0.3.0

func (instance *VLC) AddStart(uri string, option ...string) (err error)

AddStart adds a URI to the playlist and starts playback. The option field is optional and can have the values: noaudio, novideo

func (*VLC) AddSubtitle added in v0.3.0

func (instance *VLC) AddSubtitle(uri string) (err error)

AddSubtitle adds a subtitle from URI to currently playing file

func (*VLC) Art added in v0.3.0

func (instance *VLC) Art(itemID ...int) (byteArr []byte, err error)

Art fetches cover art based on a playlist item's ID. If no ID is provided, Art returns the current item's cover art. Cover art is returned in the form of a byte array.

func (*VLC) AspectRatio added in v0.3.0

func (instance *VLC) AspectRatio(ratio string) (err error)

AspectRatio sets aspect ratio. Must be one of the following values. Any other value will reset aspect ratio to default. Valid aspect ratio values: 1:1 , 4:3 , 5:4 , 16:9 , 16:10 , 221:100 , 235:100 , 239:100

func (*VLC) AudioDelay added in v0.3.0

func (instance *VLC) AudioDelay(delay float64) (err error)

AudioDelay sets Audio Delay in seconds

func (*VLC) Browse added in v0.3.0

func (instance *VLC) Browse(uri string) (files []File, err error)

Browse returns a File array with the items of the provided directory URI

func (*VLC) Delete added in v0.3.0

func (instance *VLC) Delete(id int) (err error)

Delete deletes an item with given id from playlist

func (*VLC) EmptyPlaylist added in v0.3.0

func (instance *VLC) EmptyPlaylist() (err error)

EmptyPlaylist empties the playlist

func (*VLC) ForcePause added in v0.3.0

func (instance *VLC) ForcePause() (err error)

ForcePause pauses playback, does nothing if already paused

func (*VLC) GetStatus added in v0.4.0

func (instance *VLC) GetStatus() (status Status, err error)

GetStatus returns a Status object containing information of the instances' status

func (*VLC) Next added in v0.3.0

func (instance *VLC) Next() (err error)

Next skips to the next playlist item

func (*VLC) Pause added in v0.3.0

func (instance *VLC) Pause(itemID ...int) (err error)

Pause toggles pause: If current state was 'stop', play item with given id, if no id specified, play current item. If no current item, play the first item in the playlist.

func (*VLC) Play added in v0.3.0

func (instance *VLC) Play(itemID ...int) (err error)

Play playlist item with given id. If id is omitted, play last active item

func (*VLC) PlaybackRate added in v0.3.0

func (instance *VLC) PlaybackRate(rate float64) (err error)

PlaybackRate sets Playback Rate. Must be > 0

func (*VLC) Playlist added in v0.3.0

func (instance *VLC) Playlist() (playlist Node, err error)

Playlist returns a Node object that is the root node of VLC's Playlist tree Playlist tree structure: Level 0 - Root Node (Type="node"), Level 1 - Playlists (Type="node"), Level 2+: Playlist Items (Type="leaf") or Folder (Type="node")

func (*VLC) Preamp added in v0.3.0

func (instance *VLC) Preamp(gain int) (err error)

Preamp sets the preamp gain value, must be >=-20 and <=20

func (*VLC) Previous added in v0.3.0

func (instance *VLC) Previous() (err error)

Previous goes back to the previous playlist item

func (*VLC) RequestMaker added in v0.3.0

func (instance *VLC) RequestMaker(urlSegment string) (response string, err error)

RequestMaker make requests to VLC using a urlSegment provided by other functions

func (*VLC) Resume added in v0.3.0

func (instance *VLC) Resume() (err error)

Resume resumes playback if paused, else does nothing

func (*VLC) Seek added in v0.3.0

func (instance *VLC) Seek(val string) (err error)

Seek seeks to <val>

Allowed values are of the form:
  [+ or -][<int><H or h>:][<int><M or m or '>:][<int><nothing or S or s or ">]
  or [+ or -]<int>%
  (value between [ ] are optional, value between < > are mandatory)
examples:
  1000 -> seek to the 1000th second
  +1H:2M -> seek 1 hour and 2 minutes forward
  -10% -> seek 10% back

func (*VLC) SelectAudioTrack added in v0.3.0

func (instance *VLC) SelectAudioTrack(id int) (err error)

SelectAudioTrack selects the audio track (use the number from the stream)

func (*VLC) SelectChapter added in v0.3.0

func (instance *VLC) SelectChapter(id int) (err error)

SelectChapter selects the chapter using the chapter number

func (*VLC) SelectSubtitleTrack added in v0.3.0

func (instance *VLC) SelectSubtitleTrack(id int) (err error)

SelectSubtitleTrack selects the subtitle track (use the number from the stream)

func (*VLC) SelectTitle added in v0.3.0

func (instance *VLC) SelectTitle(id int) (err error)

SelectTitle selects the title using the title number

func (*VLC) SelectVideoTrack added in v0.3.0

func (instance *VLC) SelectVideoTrack(id int) (err error)

SelectVideoTrack selects the video track (use the number from the stream)

func (*VLC) SetEQ added in v0.3.0

func (instance *VLC) SetEQ(band int, gain int) (err error)

SetEQ sets the gain for a specific Equalizer band

func (*VLC) SetEQPreset added in v0.3.0

func (instance *VLC) SetEQPreset(id int) (err error)

SetEQPreset sets the equalizer preset as per the id specified

func (*VLC) Sort added in v0.3.0

func (instance *VLC) Sort(id int, val int) (err error)

Sort sorts playlist using sort mode <val> and order <id>. If id=0 then items will be sorted in normal order, if id=1 they will be sorted in reverse order. A non exhaustive list of sort modes: 0 Id, 1 Name, 3 Author, 5 Random, 7 Track number.

func (*VLC) Stop added in v0.3.0

func (instance *VLC) Stop() (err error)

Stop stops playback

func (*VLC) SubDelay added in v0.3.0

func (instance *VLC) SubDelay(delay float64) (err error)

SubDelay sets Subtitle Delay in seconds

func (*VLC) ToggleEQ added in v0.3.0

func (instance *VLC) ToggleEQ(enable bool) (err error)

ToggleEQ toggles the EQ (true to enable, false to disable)

func (*VLC) ToggleFullscreen added in v0.3.0

func (instance *VLC) ToggleFullscreen() (err error)

ToggleFullscreen toggles Fullscreen mode

func (*VLC) ToggleLoop added in v0.3.0

func (instance *VLC) ToggleLoop() (err error)

ToggleLoop toggles Random Playback

func (*VLC) ToggleRandom added in v0.3.0

func (instance *VLC) ToggleRandom() (err error)

ToggleRandom toggles Repeat

func (*VLC) ToggleRepeat added in v0.3.0

func (instance *VLC) ToggleRepeat() (err error)

ToggleRepeat toggles Playback Looping

func (*VLC) ToggleSD added in v0.3.0

func (instance *VLC) ToggleSD(val string) (err error)

ToggleSD toggle-enables service discovery module <val>. Typical values are: sap shoutcast, podcast, hal

func (*VLC) Vlm added in v0.3.0

func (instance *VLC) Vlm() (response string, err error)

Vlm returns the full list of VLM elements

func (*VLC) VlmCmd added in v0.3.0

func (instance *VLC) VlmCmd(cmd string) (response string, err error)

VlmCmd executes a VLM Command and returns the response. Command is internally URL percent-encoded

func (*VLC) VlmCmdErr added in v0.3.0

func (instance *VLC) VlmCmdErr() (response string, err error)

VlmCmdErr returns the last VLM Error

func (*VLC) Volume added in v0.3.0

func (instance *VLC) Volume(val string) (err error)

Volume sets Volume level <val> (can be absolute integer, or +/- relative value). Percentage isn't working at the moment. Allowed values are of the form: +<int>, -<int>, <int> or <int>%

type VideoEffects added in v0.4.0

type VideoEffects struct {
	Hue        int `json:"hue"`
	Saturation int `json:"saturation"`
	Contrast   int `json:"contrast"`
	Brightness int `json:"brightness"`
	Gamma      int `json:"gamma"`
}

VideoEffects contains the current video effects configuration. A VideoEffects variable is included in Status

Jump to

Keyboard shortcuts

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