diff --git a/app/app.go b/app/app.go index ff5cff3..8abc56a 100644 --- a/app/app.go +++ b/app/app.go @@ -68,16 +68,20 @@ func ProcessFeed(feed *FeedCfg, scheduler Scheduler, dbDir string, tgram telegra return } - data, err := Download(feed.Url, feed.Proxy) - if err != nil { - log.Error("download failed", "feed", feed.Name, "url", feed.Url, "proxy", feed.Proxy, "error", err) - return - } + var entries []parser.FeedEntry + for _, url := range feed.Url { + data, err := Download(url, feed.Proxy) + if err != nil { + log.Error("download failed", "feed", feed.Name, "url", url, "proxy", feed.Proxy, "error", err) + return + } - entries, err := parser.ParseFeed(feed.Type, data) - if err != nil { - log.Error("feed parsing failed", "feed", feed.Name, "data", data, "error", err) - return + currentEntries, err := parser.ParseFeed(feed.Type, data) + if err != nil { + log.Error("feed parsing failed", "feed", feed.Name, "url", url, "data", data, "error", err) + return + } + entries = append(entries, currentEntries...) } scheduler.Good(feed.Name) diff --git a/app/config.go b/app/config.go index 997355e..fb68032 100644 --- a/app/config.go +++ b/app/config.go @@ -1,6 +1,7 @@ package app import ( + "fmt" "os" "path" @@ -12,11 +13,13 @@ type FeedLimit int const NoLimit FeedLimit = -1 +type FeedURL []string + type FeedCfg struct { Name string `yaml:"name"` Channel string `yaml:"channel"` Rhash string `yaml:"rhash"` - Url string `yaml:"url"` + Url FeedURL `yaml:"url"` Cron string `yaml:"cron"` Proxy string `yaml:"proxy"` Type parser.FeedType `yaml:"type"` @@ -105,3 +108,14 @@ func ParseConfig(configPath string) (*Config, error) { return &c, nil } + +func (fu *FeedURL) UnmarshalYAML(node *yaml.Node) error { + *fu = []string{""} + switch node.Kind { + case yaml.SequenceNode: + return node.Decode((*[]string)(fu)) + case yaml.ScalarNode: + return node.Decode(&(*fu)[0]) + } + return fmt.Errorf("unexpected node type: %s, at %d:%d", node.ShortTag(), node.Line, node.Column) +}