2023-06-19 23:42:47 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2018-10-14 20:46:41 +02:00
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
package parser // import "miniflux.app/v2/internal/reader/parser"
|
2018-10-14 20:46:41 +02:00
|
|
|
|
|
|
|
import (
|
2023-10-22 04:50:29 +02:00
|
|
|
"errors"
|
2018-10-14 20:46:41 +02:00
|
|
|
"strings"
|
|
|
|
|
2023-08-11 04:46:45 +02:00
|
|
|
"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 20:46:41 +02:00
|
|
|
)
|
|
|
|
|
2023-10-22 04:50:29 +02:00
|
|
|
var ErrFeedFormatNotDetected = errors.New("parser: unable to detect feed format")
|
|
|
|
|
2018-10-14 20:46:41 +02:00
|
|
|
// ParseFeed analyzes the input data and returns a normalized feed object.
|
2023-10-22 04:50:29 +02:00
|
|
|
func ParseFeed(baseURL, data string) (*model.Feed, error) {
|
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:
|
2023-10-22 04:50:29 +02:00
|
|
|
return nil, ErrFeedFormatNotDetected
|
2018-10-14 20:46:41 +02:00
|
|
|
}
|
|
|
|
}
|