2023-06-19 17:42:47 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-10-14 14:46:41 -04:00
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
package parser // import "miniflux.app/v2/internal/reader/parser"
|
2018-10-14 14:46:41 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2023-08-10 22:46:45 -04:00
|
|
|
"miniflux.app/v2/internal/errors"
|
|
|
|
"miniflux.app/v2/internal/model"
|
|
|
|
"miniflux.app/v2/internal/reader/atom"
|
|
|
|
"miniflux.app/v2/internal/reader/json"
|
|
|
|
"miniflux.app/v2/internal/reader/rdf"
|
|
|
|
"miniflux.app/v2/internal/reader/rss"
|
2018-10-14 14:46:41 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// ParseFeed analyzes the input data and returns a normalized feed object.
|
2020-12-02 23:47:11 -05:00
|
|
|
func ParseFeed(baseURL, data string) (*model.Feed, *errors.LocalizedError) {
|
2018-10-14 14:46:41 -04:00
|
|
|
switch DetectFeedFormat(data) {
|
|
|
|
case FormatAtom:
|
2020-12-02 23:47:11 -05:00
|
|
|
return atom.Parse(baseURL, strings.NewReader(data))
|
2018-10-14 14:46:41 -04:00
|
|
|
case FormatRSS:
|
2020-12-02 23:47:11 -05:00
|
|
|
return rss.Parse(baseURL, strings.NewReader(data))
|
2018-10-14 14:46:41 -04:00
|
|
|
case FormatJSON:
|
2020-12-02 23:47:11 -05:00
|
|
|
return json.Parse(baseURL, strings.NewReader(data))
|
2018-10-14 14:46:41 -04:00
|
|
|
case FormatRDF:
|
2020-12-02 23:47:11 -05:00
|
|
|
return rdf.Parse(baseURL, strings.NewReader(data))
|
2018-10-14 14:46:41 -04:00
|
|
|
default:
|
|
|
|
return nil, errors.NewLocalizedError("Unsupported feed format")
|
|
|
|
}
|
|
|
|
}
|