2021-11-20 21:26:39 +00:00
|
|
|
/*
|
|
|
|
* Ekster is a microsub server
|
|
|
|
* Copyright (c) 2021 The Ekster authors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Package jsonfeed parses feeds in the jsonfeed format
|
2018-08-04 20:43:57 +00:00
|
|
|
package jsonfeed
|
|
|
|
|
2018-12-18 18:40:56 +00:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2021-05-31 23:07:55 +00:00
|
|
|
// Attachment contains attachments for podcasts
|
2018-08-04 20:43:57 +00:00
|
|
|
type Attachment struct {
|
|
|
|
URL string `json:"url"`
|
|
|
|
MimeType string `json:"mime_type"`
|
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
SizeInBytes int `json:"size_in_bytes,omitempty"`
|
|
|
|
DurationInSeconds int `json:"duration_in_seconds,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-05-31 23:07:55 +00:00
|
|
|
// Item is the main item in the feed
|
2018-08-04 20:43:57 +00:00
|
|
|
type Item struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
ContentText string `json:"content_text,omitempty"`
|
|
|
|
ContentHTML string `json:"content_html,omitempty"`
|
|
|
|
Summary string `json:"summary,omitempty"`
|
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
Image string `json:"image,omitempty"`
|
|
|
|
ExternalURL string `json:"external_url,omitempty"`
|
|
|
|
DatePublished string `json:"date_published,omitempty"`
|
|
|
|
Author Author `json:"author,omitempty"`
|
|
|
|
Tags []string `json:"tags,omitempty"`
|
|
|
|
Attachments []Attachment `json:"attachments,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-05-31 23:07:55 +00:00
|
|
|
// Author is the author of the Item
|
2018-08-04 20:43:57 +00:00
|
|
|
type Author struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
Avatar string `json:"avatar,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-05-31 23:07:55 +00:00
|
|
|
// Hub contains a reference to a feed hub
|
2018-08-04 20:43:57 +00:00
|
|
|
type Hub struct {
|
|
|
|
Type string `json:"type"`
|
|
|
|
URL string `json:"url"`
|
|
|
|
}
|
|
|
|
|
2021-05-31 23:07:55 +00:00
|
|
|
// Feed is the main object
|
2018-08-04 20:43:57 +00:00
|
|
|
type Feed struct {
|
|
|
|
Version string `json:"version"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
HomePageURL string `json:"home_page_url"`
|
|
|
|
FeedURL string `json:"feed_url"`
|
2020-10-05 19:49:33 +00:00
|
|
|
NextURL string `json:"next_url"`
|
2018-08-04 20:43:57 +00:00
|
|
|
Icon string `json:"icon"`
|
|
|
|
Favicon string `json:"favicon"`
|
|
|
|
Author Author `json:"author,omitempty"`
|
|
|
|
Items []Item `json:"items"`
|
|
|
|
Hubs []Hub `json:"hubs"`
|
|
|
|
}
|
2018-12-18 18:40:56 +00:00
|
|
|
|
|
|
|
// Parse parses a jsonfeed
|
|
|
|
func Parse(body io.Reader) (Feed, error) {
|
|
|
|
var feed Feed
|
2021-05-31 23:07:55 +00:00
|
|
|
err := json.NewDecoder(body).Decode(&feed)
|
2018-12-18 18:40:56 +00:00
|
|
|
return feed, err
|
|
|
|
}
|