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 (
|
2023-10-21 22:50:29 -04:00
|
|
|
"errors"
|
2023-10-22 19:07:06 -04:00
|
|
|
"io"
|
2018-10-14 14:46:41 -04:00
|
|
|
|
2023-08-10 22:46:45 -04: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 14:46:41 -04:00
|
|
|
)
|
|
|
|
|
2023-10-21 22:50:29 -04:00
|
|
|
var ErrFeedFormatNotDetected = errors.New("parser: unable to detect feed format")
|
|
|
|
|
2018-10-14 14:46:41 -04:00
|
|
|
// ParseFeed analyzes the input data and returns a normalized feed object.
|
2023-10-22 19:07:06 -04:00
|
|
|
func ParseFeed(baseURL string, r io.ReadSeeker) (*model.Feed, error) {
|
|
|
|
r.Seek(0, io.SeekStart)
|
|
|
|
switch DetectFeedFormat(r) {
|
2018-10-14 14:46:41 -04:00
|
|
|
case FormatAtom:
|
2023-10-22 19:07:06 -04:00
|
|
|
r.Seek(0, io.SeekStart)
|
|
|
|
return atom.Parse(baseURL, r)
|
2018-10-14 14:46:41 -04:00
|
|
|
case FormatRSS:
|
2023-10-22 19:07:06 -04:00
|
|
|
r.Seek(0, io.SeekStart)
|
|
|
|
return rss.Parse(baseURL, r)
|
2018-10-14 14:46:41 -04:00
|
|
|
case FormatJSON:
|
2023-10-22 19:07:06 -04:00
|
|
|
r.Seek(0, io.SeekStart)
|
|
|
|
return json.Parse(baseURL, r)
|
2018-10-14 14:46:41 -04:00
|
|
|
case FormatRDF:
|
2023-10-22 19:07:06 -04:00
|
|
|
r.Seek(0, io.SeekStart)
|
|
|
|
return rdf.Parse(baseURL, r)
|
2018-10-14 14:46:41 -04:00
|
|
|
default:
|
2023-10-21 22:50:29 -04:00
|
|
|
return nil, ErrFeedFormatNotDetected
|
2018-10-14 14:46:41 -04:00
|
|
|
}
|
|
|
|
}
|