Documentation ¶
Index ¶
- Constants
- Variables
- func DownloadVideo(url string, storageEngine StorageEngine, useRandomSleep bool) error
- func GenerateFeed(feed []FeedItem, storageEngine StorageEngine) (generatedFeed feeds.Feed, err error)
- func GetAvatarForShow(youtubeURL string) (avatarURL string)
- func GetUUIDFromURL(url string) (filename string)
- func Inspect(name string, object interface{})
- func LogHTTPRequest(req *http.Request)
- func StartServer(config Config, storageEngine StorageEngine)
- type Config
- type FeedItem
- type LocalStorage
- func (l *LocalStorage) BasePath() string
- func (l *LocalStorage) CreateDirectory(relativePath string) (err error)
- func (l *LocalStorage) DoesFileExist(absolutePath string) bool
- func (l *LocalStorage) FileServerPath() string
- func (l *LocalStorage) FileSize(filename string) (fileSizeInBytes int64, err error)
- func (l *LocalStorage) PutFile(filename string, fileData []byte) (err error)
- func (l *LocalStorage) TempDir() string
- type NullStorage
- func (n NullStorage) BasePath() string
- func (n NullStorage) CreateDirectory(path string) (err error)
- func (n NullStorage) DoesFileExist(absolutePath string) bool
- func (n NullStorage) FileServerPath() string
- func (n NullStorage) FileSize(filename string) (fileSizeInBytes int64, err error)
- func (n NullStorage) PutFile(filename string, fileData []byte) (err error)
- func (n NullStorage) TempDir() string
- type S3
- func (s *S3) BasePath() string
- func (s *S3) CreateDirectory(path string) (err error)
- func (s *S3) DoesFileExist(absolutePath string) bool
- func (s *S3) FileServerPath() string
- func (s *S3) FileSize(filename string) (fileSizeInBytes int64, err error)
- func (s *S3) PutFile(filename string, fileData []byte) (err error)
- func (s *S3) TempDir() string
- type StorageEngine
Constants ¶
const ( YoutubeRSSRegexp = `https://www.youtube.com/feeds/videos.xml\?[A-Za-z0-9_=-]+` YoutubeAvatarRegexp = `"avatar":(.*?),"banner":` FileExtension = ".mp4" )
const HomePage = `` /* 711-byte string literal not displayed */
HomePage controls the content shown on the index page of PodcastMaker if the `ShowFrontPage` option is enabled in the Config.
Variables ¶
var ( // NullStorageError is returned whenever a bad config value for // StorageEngineType is used. NullStorageError = errors.New("bad config value for StorageEngineType") )
Functions ¶
func DownloadVideo ¶
func DownloadVideo(url string, storageEngine StorageEngine, useRandomSleep bool) error
DownloadVideo invokes `yt-dlp` to download a video after a randomly-selected delay (in order to avoid throttling), uploads it to the configured StorageEngine, then deletes the temporary local copy.
func GenerateFeed ¶
func GenerateFeed(feed []FeedItem, storageEngine StorageEngine) (generatedFeed feeds.Feed, err error)
GenerateFeed will create an RSS feed from a slice of `FeedItem`s and a `StorageEngine`.
func GetAvatarForShow ¶
GetAvatarForShow will return a URL to the channel's image.
func GetUUIDFromURL ¶
GetUUIDFromURL will convert a URL into a predictable filename. This function relies on UUID v5 namespaces to deterministically convert a given URL into a consistent UUID. Ref: https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_(namespace_name-based)
func Inspect ¶
func Inspect(name string, object interface{})
Inspect is a handy utility to print debug various objects.
func LogHTTPRequest ¶
LogHTTPRequest is a small helper function designed to make logging HTTP requests consistent and easy.
func StartServer ¶
func StartServer(config Config, storageEngine StorageEngine)
StartServer will start podcastmaker's webserver and listen for incoming requests. As URLs are requested, PodcastMaker will automatically obtain a list of the most recent uploaded videos, download them, and push them to the configured StorageEngine.
Types ¶
type Config ¶
type Config struct { // ShowFrontPage controls whether or not you want to display the instructions // on the front page. If not, the user will receive a 404 error when // nativating to the site root. // Default: true ShowFrontPage bool `yaml:"ShowFrontPage"` // ServerHost determines the host domain or IP you would like to listen on. // Default: 0.0.0.0 // Example: podcastmaker.example.com ServerHost string `yaml:"ServerHost"` // ServerPort controls the port you would like to listen on. // Default: 3000 ServerPort int `yaml:"ServerPort"` // StorageEngineType determines the type of storage engine are you using. // Valid Storage Engines: // * LocalStorage // * S3 // Default: LocalStorage StorageEngineType string `yaml:"StorageEngineType"` // LocalStorageBasePath controls the path where LocalStorage should store // files. // Default: ./downloads // Example: /opt/podcastmaker/dowloads LocalStorageBasePath string `yaml:"LocalStorageBasePath,omitempty,flow"` // LocalStorageFileServerPath controls the path that you want files to be // served from. // Default: http://127.0.0.1:3000/files/ // Example: http://example.com/videos/ LocalStorageFileServerPath string `yaml:"LocalStorageFileServerPath,omitempty"` // TempDirPath controls the path that you want yt-dlp files and fragments to // be downloaded to initially. These files will be moved to their final // location when the current video has finished downloading. // Default: ./tmp // Example: /opt/podcastmaker/tmp TempDirPath string `yaml:"TempDirPath,omitempty"` // S3BucketName is the name of your bucket. // Example: freds-podcast-maker S3BucketName string `yaml:"S3BucketName,omitempty"` // S3Region is where your bucket was created. // Example: us-east-1 S3Region string `yaml:"S3Region,omitempty"` // S3Endpoint is the S3 endpoint you're using. // Example: s3.us-east-1.amazonaws.com S3Endpoint string `yaml:"S3Endpoint,omitempty"` // S3UseEnvironmentCreds allows you to toggle using S3 credentials from // environment variables or default credential storage locations. This option // disables S3AccessKey, S3SecretKey, and S3SessionToken variables. This can // be helpful if you're running PodcastMaker from an AWS Lambda function or // using assumed roles. // Default: false S3UseEnvironmentCreds bool `yaml:"S3UseEnvironmentCreds,omitempty"` // S3AccessKey is your API access key. // Example: EXAMPLEACCESSKEY S3AccessKey string `yaml:"S3AccessKey,omitempty"` // S3SecretKey is your API secret key. // Example: ExampleSecretKeyThatIsLongerAndProbablyHasNumbersSomewhere1234 S3SecretKey string `yaml:"S3SecretKey,omitempty"` // S3SessionToken is your temporary session key. This is optional and used // with temporarily-assumed roles. // Example: ThisIsReallyLongAndChangesOften S3SessionToken string `yaml:"S3SessionToken,omitempty"` // S3FileDirectory is the subdirectory where you want to store // videos. Make sure this path ends in a '/'. // Example: /episode-files/ S3FileDirectory string `yaml:"S3FileDirectory,omitempty"` // CDNURL is the optional CDN URL for your bucket (if enabled). If this option // is used, videos will be served from this URL instead of the default // endpoint directory. // Example: podcastmakerfiles.example.com CDNURL string `yaml:"CDNURL,omitempty"` }
Config contains every option that powers podcastmaker.
func Init ¶
Init will set up PodcastMaker flags, read a config file (if the path is provided), and return a new Config object ready to run BuildStorageEngine and get used with StartServer.
func ReadConfig ¶
ReadConfig reads a file into a Config object.
func (*Config) BuildStorageEngine ¶
func (c *Config) BuildStorageEngine() (storageEngine StorageEngine, err error)
BuildStorageEngine will configure a StorageEngine given the options in a Config object.
type FeedItem ¶
type FeedItem struct { ID string `json:"id"` Channel string `json:"channel"` ChannelURL string `json:"channel_url"` Description string `json:"description"` Playlist string `json:"playlist"` Title string `json:"title"` UploadDate string `json:"upload_date"` UploaderID string `json:"uploader_id"` URL string `json:"webpage_url"` }
FeedItem is used to unmarshal JSON returned from `yt-dlp -j <URL>` into a usable format.
func DownloadVideosForChannel ¶
func DownloadVideosForChannel(config *Config, channelURL string, storageEngine StorageEngine) (feed []FeedItem, err error)
DownloadVideosForChannel will download all videos for a particular channel. This will only download the 5 most recent videos.
func (*FeedItem) ParseUploadDate ¶
ParseUploadDate will return the upload date as a `time.Time` object.
type LocalStorage ¶
type LocalStorage struct {
// contains filtered or unexported fields
}
LocalStorage allows the use of the local filesystem to store PodcastMaker downloads.
func NewLocalStorage ¶
func NewLocalStorage(relativeBasePath string, fileServerPath string, tempDirPath string) *LocalStorage
NewLocalStorage configures and returns a LocalStorage StorageEngine.
func (*LocalStorage) BasePath ¶
func (l *LocalStorage) BasePath() string
BasePath returns the configured path prefix.
func (*LocalStorage) CreateDirectory ¶
func (l *LocalStorage) CreateDirectory(relativePath string) (err error)
CreateDirectory creates a directory on the configured filesystem.
func (*LocalStorage) DoesFileExist ¶
func (l *LocalStorage) DoesFileExist(absolutePath string) bool
DoesFileExist will return if a file exists or not.
func (*LocalStorage) FileServerPath ¶
func (l *LocalStorage) FileServerPath() string
FileServerPath returns the configured hostname.
func (*LocalStorage) FileSize ¶
func (l *LocalStorage) FileSize(filename string) (fileSizeInBytes int64, err error)
FileSize returns the size of a file in bytes.
func (*LocalStorage) PutFile ¶
func (l *LocalStorage) PutFile(filename string, fileData []byte) (err error)
PutFile writes data to a specified path on a filesystem.
func (*LocalStorage) TempDir ¶
func (l *LocalStorage) TempDir() string
TempDir returns where temporary video downloads should be stored.
type NullStorage ¶
type NullStorage struct{}
NullStorage is used to provide error returns when reading bad StorageEngineType values in Config structs.
func (NullStorage) BasePath ¶
func (n NullStorage) BasePath() string
func (NullStorage) CreateDirectory ¶
func (n NullStorage) CreateDirectory(path string) (err error)
func (NullStorage) DoesFileExist ¶
func (n NullStorage) DoesFileExist(absolutePath string) bool
func (NullStorage) FileServerPath ¶
func (n NullStorage) FileServerPath() string
func (NullStorage) FileSize ¶
func (n NullStorage) FileSize(filename string) (fileSizeInBytes int64, err error)
func (NullStorage) PutFile ¶
func (n NullStorage) PutFile(filename string, fileData []byte) (err error)
func (NullStorage) TempDir ¶
func (n NullStorage) TempDir() string
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 is an S3-compatible StorageEngine with optional CDN support.
func NewS3 ¶
func NewS3(basePath string, region string, endpoint string, bucketName string, useEnvironmentCreds bool, accessKey string, secretKey string, sessionToken string, cdnURL string, tempDirPath string) *S3
NewS3 returns a fully-configured S3 StorageEngine.
func (*S3) CreateDirectory ¶
CreateDirectory creates a directory in the configured bucket.
func (*S3) DoesFileExist ¶
DoesFileExist will return whether or not a key exists in S3.
func (*S3) FileServerPath ¶
FileServerPath returns a fully-qualified path to the bucket on the configured S3 endpoint.
func (*S3) PutFile ¶
PutFile uploads data to a specific S3 key in the configured bucket. This function utilizes S3 Multipart Upload. Each file is uploaded in 100 MiB chunks (controlled by the `partSize` constant) and finalized once the final chunk is uploaded. This is necessary for any video file that exceeds 5GB.
type StorageEngine ¶
type StorageEngine interface { BasePath() string // What each download path should be prefixed with FileServerPath() string // Returns a fully-qualified path to the video-serving host PutFile(filename string, fileData []byte) (err error) // Uploads a video file CreateDirectory(path string) (err error) // Creates a directory DoesFileExist(absolutePath string) bool // Identifies if a particular filename exists FileSize(filename string) (fileSizeInBytes int64, err error) // Returns the size of a file TempDir() string // Where videos should be temporarily stored before upload }
StorageEngine controls how PodcastMaker stores, uploads, and serves video files.