videodl

package
v0.0.0-...-0caaa62 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2017 License: GPL-3.0-or-later Imports: 25 Imported by: 0

Documentation

Overview

Package videodl provides a video file downloader around the youtube-dl command (only for now).

Index

Constants

View Source
const (
	HistoryFile = "videodl_history.txt"
	WebPath     = "video"
)

HistoryFile defines the name of the default history file.

View Source
const (
	ActionOpenFolder = iota
	ActionCancelDownload
	ActionEnableDownload
	ActionEnableWeb
	ActionEditList
	ActionCount // Number of defined actions
)

Videodl actions.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackendID

type BackendID int

BackendID represents the identifier of a backend.

const (
	BackendInternal BackendID = iota
	BackendYoutubeDL
)

Backends list.

type Commands

type Commands struct {
	CmdOpenDir   string
	CmdOpenWeb   string
	CmdOpenVideo string
}

Commands defines custom user commands to open programs.

type Config

type Config struct {
	BackendID BackendID
	Path      string
	Quality   Quality
	TypeDL    TypeDL
	EnabledDL bool
	// EnabledWeb     bool
	// StartedWeb     bool
	JSWindowOption string

	Blacklist []string
}

Config defines the videodl service configuration. Can be used directly as applet config.

type Controler

type Controler interface {
	Action() cdtype.AppAction
	PopupDialog(cdtype.DialogData) error
}

Controler defines actions needed from a cdtype.AppBase.

type DownloadFunc

type DownloadFunc func(*Video, *Format)

DownloadFunc defines a quality set function.

type Downloader

type Downloader interface {
	// SetConfig sets the config data for the manager.
	//
	SetConfig(*Config)

	// SetEditList updates the edit list call action.
	//
	SetEditList(call func() error)

	// SetPreCheck sets the pre-upload action.
	//
	SetPreCheck(call func() error)

	// SetPostCheck sets the post-upload action.
	//
	SetPostCheck(call func() error)

	// IsActive returns whether a download is in progress or not.
	//
	IsActive() bool

	// FilterBlacklist provides a filter formats call to remove blacklisted file types.
	//
	FilterBlacklist() FuncFilterFormats

	WebRegister()
	WebUnregister()

	WebAutoStart() func()

	// SetEnabledWeb sets the web service state.
	//
	SetEnabledWeb(WebState)

	// WebURL formats the web service base url.
	//
	WebURL() string

	// Download downloads a video file from the server at configured quality (can be ask).
	//
	Download(url string)

	// Enqueue enqueues an item to the download list.
	//
	Enqueue(*Video)
	EnqueueAndStart(*Video)
	Start()

	OpenFolder()
	CancelDownload()

	Actions(firstID int, actionAdd func(...*cdtype.Action))
	Menu(cdtype.Menuer)
	DialogQuality(filterFormats FuncFilterFormats, callDialog FuncPopupDialog, callDL DownloadFunc, v *Video)
}

Downloader defines the usage of the video download manager.

type Entry

type Entry struct {
	Name   string // name of the object
	IsDir  bool
	Mode   os.FileMode
	Viewed bool
	URL    string
	Fail   bool
}

Entry defines a list entry to provide as json

type Filer

type Filer interface {
	Title() (string, error)
	DownloadCmd(path string, format *Format, progress *Progress) func() error
	Formats() ([]*Format, error)
}

Filer defines the usage of a video file downloader.

func NewYTDLFile

func NewYTDLFile(log cdtype.Logger, url string) (Filer, error)

NewYTDLFile creates a video file downloader.

func NewYoutubeDLFile

func NewYoutubeDLFile(log cdtype.Logger, url string) (Filer, error)

NewYoutubeDLFile creates a video file downloader.

type Format

type Format struct {
	Itag       int    // Key reference for the stream.
	Extension  string // Media extension (mp4, flv...)
	Resolution string // Video resolution.
	Size       int    // File size in MiB.

	VideoEncoding string
	AudioEncoding string
	AudioBitrate  int
	// contains filtered or unexported fields
}

Format defines the format of a media stream (audio or video).

func FilterFormats

func FilterFormats(formats []*Format, filters ...FuncFilterFormatTest) []*Format

FilterFormats filters a list of formats with the provided test.

type FuncFilterFormatTest

type FuncFilterFormatTest func(*Format) bool

FuncFilterFormatTest defines a filter format test callback.

type FuncFilterFormats

type FuncFilterFormats func([]*Format) []*Format

FuncFilterFormats defines a filter format test callback.

type FuncNewFiler

type FuncNewFiler func(log cdtype.Logger, url string) (Filer, error)

FuncNewFiler defines the filer creation from a download backend.

type FuncPopupDialog

type FuncPopupDialog func(cdtype.DialogData) error

FuncPopupDialog defines a dialog display function.

type HistoryVideo

type HistoryVideo struct {
	history.History
	Queue []*Video // still to do.
	List  []*Video // already done.
}

HistoryVideo stores and saves videodl done and queued lists.

func NewHistoryVideo

func NewHistoryVideo(app history.AppletLike, filename string) *HistoryVideo

NewHistoryVideo creates a videodl history manager with the given file location.

func (*HistoryVideo) Add

func (h *HistoryVideo) Add(q *Video) error

Add adds a video to the download queue.

func (*HistoryVideo) Done

func (h *HistoryVideo) Done() error

Done moves the first item in the queue to the done list.

func (*HistoryVideo) Find

func (h *HistoryVideo) Find(url string) *Video

Find finds the video patching the given source url.

func (*HistoryVideo) Next

func (h *HistoryVideo) Next() (*Video, bool)

Next returns the first video in the download queue.

func (*HistoryVideo) Queued

func (h *HistoryVideo) Queued() int

Queued returns the size of the download queue.

func (*HistoryVideo) Remove

func (h *HistoryVideo) Remove(vid *Video, list *[]*Video) error

Remove removes the given video from the given list.

type Manager

type Manager struct {
	*Config
	*Commands

	EnabledWeb bool
	StartedWeb bool
	// contains filtered or unexported fields
}

Manager defines a video file download manager.

func NewManager

func NewManager(control Controler, log cdtype.Logger, hist *HistoryVideo) *Manager

NewManager creates a video file download manager.

func (*Manager) Actions

func (m *Manager) Actions(firstID int, actionAdd func(acts ...*cdtype.Action))

Actions fills an applet actions list with videodl actions.

func (*Manager) CancelDownload

func (m *Manager) CancelDownload()

CancelDownload stops the current download.

func (*Manager) DialogCategory

func (m *Manager) DialogCategory(filterFormats FuncFilterFormats, callDialog FuncPopupDialog, callDL DownloadFunc, vid *Video)

DialogCategory prepares a dialog to ask the category assigned to next downloads.

func (*Manager) DialogQuality

func (m *Manager) DialogQuality(filterFormats FuncFilterFormats, callDialog FuncPopupDialog, callDL DownloadFunc, vid *Video)

DialogQuality prepares a dialog to ask the desired quality and download.

func (*Manager) Download

func (m *Manager) Download(url string)

Download downloads a video file from the server at configured quality (can be ask).

func (*Manager) Enqueue

func (m *Manager) Enqueue(vid *Video)

Enqueue enqueues an item to the download list.

func (*Manager) EnqueueAndStart

func (m *Manager) EnqueueAndStart(vid *Video)

EnqueueAndStart enqueues an item and starts downloading.

func (*Manager) FilePath

func (m *Manager) FilePath(vid Video) string

FilePath returns the full path to the video file.

func (*Manager) FilterBlacklist

func (m *Manager) FilterBlacklist() FuncFilterFormats

FilterBlacklist provides a filter formats call to remove blacklisted file types.

func (*Manager) IsActive

func (m *Manager) IsActive() bool

IsActive returns whether a download is in progress or not.

func (*Manager) Menu

func (m *Manager) Menu(menu cdtype.Menuer)

Menu fills an applet actions list with videodl actions.

func (*Manager) MenuQuality

func (m *Manager) MenuQuality(menu cdtype.Menuer, qual *Quality, list []Quality)

MenuQuality returns the list of available streams and formats for the video.

func (*Manager) MenuTypeDL

func (m *Manager) MenuTypeDL(menu cdtype.Menuer, typ *TypeDL)

MenuTypeDL fills the menu with a submenu to select TypeDL (audio, video or both).

func (*Manager) OpenFolder

func (m *Manager) OpenFolder()

OpenFolder opens the destination folder.

func (*Manager) ServeHTTP

func (m *Manager) ServeHTTP(rw http.ResponseWriter, req *http.Request)

func (*Manager) SetConfig

func (m *Manager) SetConfig(conf *Config)

SetConfig sets the config data for the manager.

func (*Manager) SetEditList

func (m *Manager) SetEditList(call func() error)

SetEditList updates the edit list call action.

func (*Manager) SetEnabledWeb

func (m *Manager) SetEnabledWeb(s WebState)

SetEnabledWeb sets the web service state.

func (*Manager) SetPostCheck

func (m *Manager) SetPostCheck(call func() error)

SetPostCheck sets the post-upload action.

func (*Manager) SetPreCheck

func (m *Manager) SetPreCheck(call func() error)

SetPreCheck sets the pre-upload action.

func (*Manager) SetStartedWeb

func (m *Manager) SetStartedWeb(b bool)

SetStartedWeb sets the status of the web service.

func (*Manager) Start

func (m *Manager) Start()

Start starts downloading queued items.

func (*Manager) ToggleEnableDownload

func (m *Manager) ToggleEnableDownload()

ToggleEnableDownload toggles the status of the download activity (dl/pause).

func (*Manager) ToggleEnableWeb

func (m *Manager) ToggleEnableWeb()

ToggleEnableWeb toggles the status of the web service.

func (*Manager) WebAutoStart

func (m *Manager) WebAutoStart() func()

WebAutoStart starts temporarily the web service, until the returned stop func is called.

func (*Manager) WebRegister

func (m *Manager) WebRegister()

WebRegister registers the web service.

func (*Manager) WebStart

func (m *Manager) WebStart()

WebStart starts the web service.

func (*Manager) WebStop

func (m *Manager) WebStop()

WebStop stops the web service.

func (*Manager) WebURL

func (m *Manager) WebURL() string

WebURL formats the web service base url.

func (*Manager) WebUnregister

func (m *Manager) WebUnregister()

WebUnregister unregister the web service.

type Progress

type Progress struct {
	// contains filtered or unexported fields
}

Progress will try to provide download progress report.

func NewProgress

func NewProgress() *Progress

NewProgress creates a download progress reporter.

func (*Progress) SetMax

func (p *Progress) SetMax(m int64)

SetMax sets the expected size of the download.

func (*Progress) Write

func (p *Progress) Write(data []byte) (n int, e error)

Write implements io.Writer to count download progress.

type Quality

type Quality int

Quality defines the download quality setting.

const (
	QualityAsk Quality = iota
	QualityBestFound
	QualityBestPossible
	QualityCount // Number of quality actions defined.
)

Quality settings.

func (Quality) String

func (q Quality) String() string

func (Quality) Tooltip

func (q Quality) Tooltip() string

Tooltip returns the tooltip text displayed for the quality setting.

type TypeDL

type TypeDL int

TypeDL defines the media type filtering.

const (
	TypeDLAll TypeDL = iota
	TypeDLAudio
	TypeDLVideo
	TypeDLVideoWithAudio
)

TypeDL settings.

func (TypeDL) String

func (t TypeDL) String() string

func (TypeDL) Tooltip

func (t TypeDL) Tooltip() string

Tooltip returns the tooltip text displayed for the media type filter.

type Video

type Video struct {
	*Format

	Name      string
	URL       string
	DateAdded time.Time
	DateDone  *time.Time
	Fail      bool
	Viewed    bool
	Category  string
	// contains filtered or unexported fields
}

Video defines a video

func NewVideo

func NewVideo(url string, filer Filer) (*Video, error)

NewVideo creates a video for the remote url.

type VideoDler

type VideoDler interface {
	New(log cdtype.Logger, url string) (Filer, error)
	MenuQuality() []Quality
}

VideoDler defines the backend interface.

type WebState

type WebState int

WebState defines the state of the web service.

const (
	WebStateDisabled WebState = iota
	WebStateStopped
	WebStateStarted
)

TypeDL settings.

func (WebState) Tooltip

func (s WebState) Tooltip() string

Tooltip returns the tooltip text displayed for the web service state.

type YTDL

type YTDL struct{}

YTDL implements the VideoDler interface with internal ytdl library.

func (YTDL) MenuQuality

func (f YTDL) MenuQuality() []Quality

MenuQuality returns the list of available streams and formats for the video.

func (YTDL) New

func (f YTDL) New(log cdtype.Logger, url string) (Filer, error)

New creates a filer with the ytdl backend for the given url.

type YTDLFile

type YTDLFile struct {
	ytdl.VideoInfo
	// contains filtered or unexported fields
}

YTDLFile defines a video file downloader around the ytdl library.

func (*YTDLFile) DownloadCmd

func (f *YTDLFile) DownloadCmd(path string, locformat *Format, progress *Progress) func() error

DownloadCmd downloads the video file from server.

func (*YTDLFile) Formats

func (f *YTDLFile) Formats() ([]*Format, error)

Formats returns the list of available streams and formats for the video.

func (*YTDLFile) Title

func (f *YTDLFile) Title() (string, error)

Title gets the title of the video.

type YoutubeDL

type YoutubeDL struct{}

YoutubeDL implements the VideoDler interface with external youtube-dl command.

func (YoutubeDL) MenuQuality

func (f YoutubeDL) MenuQuality() []Quality

MenuQuality returns the list of available streams and formats for the video.

func (YoutubeDL) New

func (f YoutubeDL) New(log cdtype.Logger, url string) (Filer, error)

New creates a filer with the youtube-dl backend for the given url.

type YoutubeDLFile

type YoutubeDLFile struct {
	// contains filtered or unexported fields
}

YoutubeDLFile defines a video file downloader around the youtube-dl command.

func (*YoutubeDLFile) DownloadCmd

func (f *YoutubeDLFile) DownloadCmd(path string, format *Format, progress *Progress) func() error

DownloadCmd downloads the video file from server.

func (*YoutubeDLFile) Formats

func (f *YoutubeDLFile) Formats() ([]*Format, error)

Formats returns the list of available streams and formats for the video.

func (*YoutubeDLFile) Title

func (f *YoutubeDLFile) Title() (string, error)

Title gets the title of the video.

Jump to

Keyboard shortcuts

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