2018-10-14 20:46:41 +02:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package parser // import "miniflux.app/reader/parser"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"miniflux.app/errors"
|
|
|
|
"miniflux.app/model"
|
|
|
|
"miniflux.app/reader/atom"
|
|
|
|
"miniflux.app/reader/json"
|
|
|
|
"miniflux.app/reader/rdf"
|
|
|
|
"miniflux.app/reader/rss"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ParseFeed analyzes the input data and returns a normalized feed object.
|
2020-12-03 05:47:11 +01:00
|
|
|
func ParseFeed(baseURL, data string) (*model.Feed, *errors.LocalizedError) {
|
2018-10-14 20:46:41 +02:00
|
|
|
switch DetectFeedFormat(data) {
|
|
|
|
case FormatAtom:
|
2020-12-03 05:47:11 +01:00
|
|
|
return atom.Parse(baseURL, strings.NewReader(data))
|
2018-10-14 20:46:41 +02:00
|
|
|
case FormatRSS:
|
2020-12-03 05:47:11 +01:00
|
|
|
return rss.Parse(baseURL, strings.NewReader(data))
|
2018-10-14 20:46:41 +02:00
|
|
|
case FormatJSON:
|
2020-12-03 05:47:11 +01:00
|
|
|
return json.Parse(baseURL, strings.NewReader(data))
|
2018-10-14 20:46:41 +02:00
|
|
|
case FormatRDF:
|
2020-12-03 05:47:11 +01:00
|
|
|
return rdf.Parse(baseURL, strings.NewReader(data))
|
2018-10-14 20:46:41 +02:00
|
|
|
default:
|
|
|
|
return nil, errors.NewLocalizedError("Unsupported feed format")
|
|
|
|
}
|
|
|
|
}
|