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"
|
2023-10-23 01:07:06 +02:00
|
|
|
"io"
|
2018-10-14 20:46:41 +02:00
|
|
|
|
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-23 01:07:06 +02:00
|
|
|
func ParseFeed(baseURL string, r io.ReadSeeker) (*model.Feed, error) {
|
|
|
|
r.Seek(0, io.SeekStart)
|
2024-03-12 13:11:56 +01:00
|
|
|
format, version := DetectFeedFormat(r)
|
|
|
|
switch format {
|
2018-10-14 20:46:41 +02:00
|
|
|
case FormatAtom:
|
2023-10-23 01:07:06 +02:00
|
|
|
r.Seek(0, io.SeekStart)
|
2024-03-12 13:11:56 +01:00
|
|
|
return atom.Parse(baseURL, r, version)
|
2018-10-14 20:46:41 +02:00
|
|
|
case FormatRSS:
|
2023-10-23 01:07:06 +02:00
|
|
|
r.Seek(0, io.SeekStart)
|
|
|
|
return rss.Parse(baseURL, r)
|
2018-10-14 20:46:41 +02:00
|
|
|
case FormatJSON:
|
2023-10-23 01:07:06 +02:00
|
|
|
r.Seek(0, io.SeekStart)
|
|
|
|
return json.Parse(baseURL, r)
|
2018-10-14 20:46:41 +02:00
|
|
|
case FormatRDF:
|
2023-10-23 01:07:06 +02:00
|
|
|
r.Seek(0, io.SeekStart)
|
|
|
|
return rdf.Parse(baseURL, r)
|
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
|
|
|
}
|
|
|
|
}
|