appu

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DownloadFile = func(URL, fileName string) error {
	file, err := os.Create(fileName)
	if err != nil {
		return err
	}

	resp, err := http.Get(URL)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	_, err = io.Copy(file, resp.Body)
	if err != nil {
		return err
	}
	defer file.Close()

	return nil
}

DownloadFile allows to download a URL content into a file.

View Source
var GetEpisodeLength = func(URL string) (int, error) {
	res, err := http.Head(URL)
	if err != nil {
		return 0, err
	}

	return int(res.ContentLength), nil
}

GetEpisodeLength returns the Content-Length HTTP header value for a URL.

View Source
var GetFeed = func(URL string) (string, error) {
	resp, err := http.Get(URL)
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	bodyBytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "", err
	}

	return string(bodyBytes), nil
}

GetFeed returns the content of the XML feed defined in `URL`, or an error.

View Source
var GetPubDate = time.Now

GetPubDate returns the `time.Time` value for current publication.

View Source
var GetScript = func(episodeTag string) (string, error) {
	q := fmt.Sprintf("name contains '%v'", episodeTag)

	svc, err := gdrive.GetService(os.Getenv("DRIVE_CREDENTIALS_FILE"))
	if err != nil {
		return "", err
	}

	if len(q) == 0 {
		return "", fmt.Errorf("no matching scripts, please add a query returning one single document")
	}

	r, err := stationery.GetFiles(svc, q)
	if err != nil {
		return "", err
	}

	if len(r) > 1 {
		return "", fmt.Errorf("too many results. Query must return only one document, not %v", len(r))
	}

	content, err := stationery.ExportHTML(svc, r[0])
	if err != nil {
		return "", err
	}

	return content, nil
}

GetScript returns the content of the script which name matches the `episodeTag` in HTML, or an error.

Functions

func AddNewEpisode

func AddNewEpisode(cfg *Config, feed *podcast.Podcast) error

AddNewEpisode creates a new episode from `cfg` and adds it to `feed`.

func CreateFeedItem

func CreateFeedItem(cfg *Config) (*etree.Element, error)

CreateFeedItem creates a new feed's Item from the Config information.

func GetEpisodeDetails

func GetEpisodeDetails(trackName, podcastYAML string) (map[string]interface{}, error)

GetEpisodeDetails provides the corresponding episode details for the `trackName` provided according to the features defined in `podcastYAML`.

func ReadXML

func ReadXML(feedFileName string) (*podcast.Podcast, error)

ReadXML loads XML from a file into a `podcast.Podcast` for processing.

func WriteXML

func WriteXML(p *podcast.Podcast)

WriteXML creates a new file on disk with the appropriate XML contents from `doc`.

Types

type Config

type Config struct {
	Album          string `yaml:"album"`
	Artist         string `yaml:"artist"`
	Bucket         string `yaml:"bucket"`
	Cover          string `yaml:"cover"`
	CoverFileName  string
	Image          string    `yaml:"image"`
	Intro          string    `yaml:"intro"`
	Links          []string  `yaml:"links"`
	Master         string    `yaml:"master"`
	PubDate        time.Time `yaml:"pubDate"`
	Summary        string    `yaml:"summary"`
	Title          string    `yaml:"title"`
	TrackNo        int       `yaml:"trackNo"`
	EpisodeURL     string    `yaml:"episodeURL"`
	DistributionID string    `yaml:"distributionID"`
	ConfigFileName string
}

Config contains all the configuration data from the YAML file. Part of it is used by the appu container.

func LoadConfigYAML

func LoadConfigYAML(YAMLFile string) (cfg *Config, err error)

LoadConfigYAML reads the `YAMLFile` and gets the data loaded in `cfg`, or any error happened in the process.

func (*Config) PrepareFiles

func (c *Config) PrepareFiles() (err error)

PrepareFiles makes all the configuration ready to be used by the appu container.

type Podcast

type Podcast struct {
	FeedURL          string `yaml:"feedURL"`
	MasterURLPattern string `yaml:"masterURLPattern"`
	PublishURL       string `yaml:"publishURL"`
	DistributionID   string `yaml:"distributionID"`
	DirectFields     struct {
		Cover         string `yaml:"cover"`
		Artist        string `yaml:"artist"`
		Album         string `yaml:"album"`
		IntroURL      string `yaml:"introURL"`
		EpisodeBucket string `yaml:"episodeBucket"`
	} `yaml:"directFields"`
	ScriptFieldHooks []struct {
		Name      string `yaml:"name"`
		Hook      string `yaml:"hook"`
		List      bool   `yaml:"list"`
		Attribute string `yaml:"attribute"`
	} `yaml:"scriptFieldHooks"`
	EpisodeScriptHooks map[string]string `yaml:"episodeScriptHooks"`
	// contains filtered or unexported fields
}

Podcast contains all the parameters to get the episode details for a podcast.

func NewPodcast

func NewPodcast(trackName, YAMLFile string) (*Podcast, error)

NewPodcast constructs the `Podcast` object for a `trackName` according with the properties defined in the `YAMLFile`, or an error.

Jump to

Keyboard shortcuts

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