2017-11-20 06:10:04 +01:00
|
|
|
// Copyright 2017 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package model // import "miniflux.app/model"
|
2017-11-20 06:10:04 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-05-25 23:06:56 +02:00
|
|
|
"math"
|
2017-11-20 06:10:04 +01:00
|
|
|
"time"
|
2018-10-15 06:43:48 +02:00
|
|
|
|
2020-05-25 23:06:56 +02:00
|
|
|
"miniflux.app/config"
|
2018-10-15 06:43:48 +02:00
|
|
|
"miniflux.app/http/client"
|
2017-11-20 06:10:04 +01:00
|
|
|
)
|
|
|
|
|
2021-01-04 22:49:28 +01:00
|
|
|
// List of supported schedulers.
|
|
|
|
const (
|
2021-01-27 14:09:50 +01:00
|
|
|
SchedulerRoundRobin = "round_robin"
|
|
|
|
SchedulerEntryFrequency = "entry_frequency"
|
2021-01-18 22:22:09 +01:00
|
|
|
// Default settings for the feed query builder
|
|
|
|
DefaultFeedSorting = "parsing_error_count"
|
|
|
|
DefaultFeedSortingDirection = "desc"
|
2021-01-04 22:49:28 +01:00
|
|
|
)
|
|
|
|
|
2018-10-15 06:43:48 +02:00
|
|
|
// Feed represents a feed in the application.
|
2017-11-20 06:10:04 +01:00
|
|
|
type Feed struct {
|
2021-02-21 22:42:49 +01:00
|
|
|
ID int64 `json:"id"`
|
|
|
|
UserID int64 `json:"user_id"`
|
|
|
|
FeedURL string `json:"feed_url"`
|
|
|
|
SiteURL string `json:"site_url"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
CheckedAt time.Time `json:"checked_at"`
|
|
|
|
NextCheckAt time.Time `json:"next_check_at"`
|
|
|
|
EtagHeader string `json:"etag_header"`
|
|
|
|
LastModifiedHeader string `json:"last_modified_header"`
|
|
|
|
ParsingErrorMsg string `json:"parsing_error_message"`
|
|
|
|
ParsingErrorCount int `json:"parsing_error_count"`
|
|
|
|
ScraperRules string `json:"scraper_rules"`
|
|
|
|
RewriteRules string `json:"rewrite_rules"`
|
|
|
|
Crawler bool `json:"crawler"`
|
|
|
|
BlocklistRules string `json:"blocklist_rules"`
|
|
|
|
KeeplistRules string `json:"keeplist_rules"`
|
2022-07-12 06:12:26 +02:00
|
|
|
UrlRewriteRules string `json:"urlrewrite_rules"`
|
2021-02-21 22:42:49 +01:00
|
|
|
UserAgent string `json:"user_agent"`
|
2021-03-23 04:27:58 +01:00
|
|
|
Cookie string `json:"cookie"`
|
2021-02-21 22:42:49 +01:00
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
Disabled bool `json:"disabled"`
|
Add Media Player and resume to last playback position
In order to ease podcast listening, the player can be put on top of the feed entry as main content.
Use the `Use podcast player` option to enable that. It works on audio and video.
Also, when playing audio or video, progression will be saved in order to be able to resume listening later.
This position saving is done using the original attachement/enclosures player AND podcast player and do not rely on
the podcast player option ti be enabled.
Additionally, I made the player fill the width with the entry container to ease seeking and have a bigger video.
updateEnclosures now keep existing enclosures based on URL
When feeds get updated, enclosures entries are always wiped and re-created. This cause two issue
- enclosure progression get lost in the process
- enclosure ID changes
I used the URL as identifier of an enclosure. Not perfect but hopefully should work.
When an enclosure already exist, I simply do nothing and leave the entry as is in the database.
If anyone is listening/watching to this enclosure during the refresh, the id stay coherent and progression saving still works.
The updateEnclosures function got a bit more complex. I tried to make it the more clear I could.
Some optimisation are possible but would make the function harder to read in my opinion.
I'm not sure if this is often the case, but some feeds may include tracking or simply change the url each
time we update the feed. In those situation, enclosures ids and progression will be lost.
I have no idea how to handle this last situation. Use the size instead/alongside url to define the identity of an enclosure ?
Translation: english as placeholder for every language except French
Aside, I tested a video feed and fixed a few things for it. In fact, the MimeType was not working
at all on my side, and found a pretty old stackoverflow discussion that suggest to use an Apple non-standard MimeType for
m4v video format. I only did one substitution because I only have one feed to test. Any new video feed can make this go away
or evolve depending on the situation. Real video feeds does not tend to be easy to find and test extensively this.
Co-authored-by: toastal
2023-04-13 11:46:43 +02:00
|
|
|
NoMediaPlayer bool `json:"no_media_player"`
|
2021-02-21 22:42:49 +01:00
|
|
|
IgnoreHTTPCache bool `json:"ignore_http_cache"`
|
|
|
|
AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
|
|
|
|
FetchViaProxy bool `json:"fetch_via_proxy"`
|
|
|
|
Category *Category `json:"category,omitempty"`
|
|
|
|
Entries Entries `json:"entries,omitempty"`
|
|
|
|
Icon *FeedIcon `json:"icon"`
|
2021-08-15 17:32:43 +02:00
|
|
|
HideGlobally bool `json:"hide_globally"`
|
2021-02-21 22:42:49 +01:00
|
|
|
UnreadCount int `json:"-"`
|
|
|
|
ReadCount int `json:"-"`
|
2017-11-20 06:10:04 +01:00
|
|
|
}
|
|
|
|
|
2022-05-21 20:44:56 +02:00
|
|
|
type FeedCounters struct {
|
|
|
|
ReadCounters map[int64]int `json:"reads"`
|
|
|
|
UnreadCounters map[int64]int `json:"unreads"`
|
|
|
|
}
|
|
|
|
|
2017-11-20 06:10:04 +01:00
|
|
|
func (f *Feed) String() string {
|
|
|
|
return fmt.Sprintf("ID=%d, UserID=%d, FeedURL=%s, SiteURL=%s, Title=%s, Category={%s}",
|
|
|
|
f.ID,
|
|
|
|
f.UserID,
|
|
|
|
f.FeedURL,
|
|
|
|
f.SiteURL,
|
|
|
|
f.Title,
|
|
|
|
f.Category,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2018-10-15 06:43:48 +02:00
|
|
|
// WithClientResponse updates feed attributes from an HTTP request.
|
|
|
|
func (f *Feed) WithClientResponse(response *client.Response) {
|
|
|
|
f.EtagHeader = response.ETag
|
|
|
|
f.LastModifiedHeader = response.LastModified
|
|
|
|
f.FeedURL = response.EffectiveURL
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithCategoryID initializes the category attribute of the feed.
|
|
|
|
func (f *Feed) WithCategoryID(categoryID int64) {
|
|
|
|
f.Category = &Category{ID: categoryID}
|
|
|
|
}
|
|
|
|
|
|
|
|
// WithError adds a new error message and increment the error counter.
|
|
|
|
func (f *Feed) WithError(message string) {
|
|
|
|
f.ParsingErrorCount++
|
|
|
|
f.ParsingErrorMsg = message
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResetErrorCounter removes all previous errors.
|
|
|
|
func (f *Feed) ResetErrorCounter() {
|
|
|
|
f.ParsingErrorCount = 0
|
|
|
|
f.ParsingErrorMsg = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// CheckedNow set attribute values when the feed is refreshed.
|
|
|
|
func (f *Feed) CheckedNow() {
|
|
|
|
f.CheckedAt = time.Now()
|
|
|
|
|
|
|
|
if f.SiteURL == "" {
|
|
|
|
f.SiteURL = f.FeedURL
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-25 23:06:56 +02:00
|
|
|
// ScheduleNextCheck set "next_check_at" of a feed based on the scheduler selected from the configuration.
|
|
|
|
func (f *Feed) ScheduleNextCheck(weeklyCount int) {
|
2020-05-25 23:59:15 +02:00
|
|
|
switch config.Opts.PollingScheduler() {
|
|
|
|
case SchedulerEntryFrequency:
|
2020-05-25 23:06:56 +02:00
|
|
|
var intervalMinutes int
|
|
|
|
if weeklyCount == 0 {
|
2020-05-25 23:59:15 +02:00
|
|
|
intervalMinutes = config.Opts.SchedulerEntryFrequencyMaxInterval()
|
2020-05-25 23:06:56 +02:00
|
|
|
} else {
|
|
|
|
intervalMinutes = int(math.Round(float64(7*24*60) / float64(weeklyCount)))
|
|
|
|
}
|
2020-05-25 23:59:15 +02:00
|
|
|
intervalMinutes = int(math.Min(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMaxInterval())))
|
|
|
|
intervalMinutes = int(math.Max(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMinInterval())))
|
|
|
|
f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(intervalMinutes))
|
2020-05-25 23:06:56 +02:00
|
|
|
default:
|
2020-05-25 23:59:15 +02:00
|
|
|
f.NextCheckAt = time.Now()
|
2020-05-25 23:06:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-04 22:49:28 +01:00
|
|
|
// FeedCreationRequest represents the request to create a feed.
|
|
|
|
type FeedCreationRequest struct {
|
2021-02-21 22:42:49 +01:00
|
|
|
FeedURL string `json:"feed_url"`
|
|
|
|
CategoryID int64 `json:"category_id"`
|
|
|
|
UserAgent string `json:"user_agent"`
|
2021-03-23 04:27:58 +01:00
|
|
|
Cookie string `json:"cookie"`
|
2021-02-21 22:42:49 +01:00
|
|
|
Username string `json:"username"`
|
|
|
|
Password string `json:"password"`
|
|
|
|
Crawler bool `json:"crawler"`
|
|
|
|
Disabled bool `json:"disabled"`
|
Add Media Player and resume to last playback position
In order to ease podcast listening, the player can be put on top of the feed entry as main content.
Use the `Use podcast player` option to enable that. It works on audio and video.
Also, when playing audio or video, progression will be saved in order to be able to resume listening later.
This position saving is done using the original attachement/enclosures player AND podcast player and do not rely on
the podcast player option ti be enabled.
Additionally, I made the player fill the width with the entry container to ease seeking and have a bigger video.
updateEnclosures now keep existing enclosures based on URL
When feeds get updated, enclosures entries are always wiped and re-created. This cause two issue
- enclosure progression get lost in the process
- enclosure ID changes
I used the URL as identifier of an enclosure. Not perfect but hopefully should work.
When an enclosure already exist, I simply do nothing and leave the entry as is in the database.
If anyone is listening/watching to this enclosure during the refresh, the id stay coherent and progression saving still works.
The updateEnclosures function got a bit more complex. I tried to make it the more clear I could.
Some optimisation are possible but would make the function harder to read in my opinion.
I'm not sure if this is often the case, but some feeds may include tracking or simply change the url each
time we update the feed. In those situation, enclosures ids and progression will be lost.
I have no idea how to handle this last situation. Use the size instead/alongside url to define the identity of an enclosure ?
Translation: english as placeholder for every language except French
Aside, I tested a video feed and fixed a few things for it. In fact, the MimeType was not working
at all on my side, and found a pretty old stackoverflow discussion that suggest to use an Apple non-standard MimeType for
m4v video format. I only did one substitution because I only have one feed to test. Any new video feed can make this go away
or evolve depending on the situation. Real video feeds does not tend to be easy to find and test extensively this.
Co-authored-by: toastal
2023-04-13 11:46:43 +02:00
|
|
|
NoMediaPlayer bool `json:"no_media_player"`
|
2021-02-21 22:42:49 +01:00
|
|
|
IgnoreHTTPCache bool `json:"ignore_http_cache"`
|
|
|
|
AllowSelfSignedCertificates bool `json:"allow_self_signed_certificates"`
|
|
|
|
FetchViaProxy bool `json:"fetch_via_proxy"`
|
|
|
|
ScraperRules string `json:"scraper_rules"`
|
|
|
|
RewriteRules string `json:"rewrite_rules"`
|
|
|
|
BlocklistRules string `json:"blocklist_rules"`
|
|
|
|
KeeplistRules string `json:"keeplist_rules"`
|
2021-08-15 17:32:43 +02:00
|
|
|
HideGlobally bool `json:"hide_globally"`
|
2022-07-12 06:12:26 +02:00
|
|
|
UrlRewriteRules string `json:"urlrewrite_rules"`
|
2021-01-04 22:49:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// FeedModificationRequest represents the request to update a feed.
|
|
|
|
type FeedModificationRequest struct {
|
2021-02-21 22:42:49 +01:00
|
|
|
FeedURL *string `json:"feed_url"`
|
|
|
|
SiteURL *string `json:"site_url"`
|
|
|
|
Title *string `json:"title"`
|
|
|
|
ScraperRules *string `json:"scraper_rules"`
|
|
|
|
RewriteRules *string `json:"rewrite_rules"`
|
|
|
|
BlocklistRules *string `json:"blocklist_rules"`
|
|
|
|
KeeplistRules *string `json:"keeplist_rules"`
|
2022-07-12 06:12:26 +02:00
|
|
|
UrlRewriteRules *string `json:"urlrewrite_rules"`
|
2021-02-21 22:42:49 +01:00
|
|
|
Crawler *bool `json:"crawler"`
|
|
|
|
UserAgent *string `json:"user_agent"`
|
2021-03-23 04:27:58 +01:00
|
|
|
Cookie *string `json:"cookie"`
|
2021-02-21 22:42:49 +01:00
|
|
|
Username *string `json:"username"`
|
|
|
|
Password *string `json:"password"`
|
|
|
|
CategoryID *int64 `json:"category_id"`
|
|
|
|
Disabled *bool `json:"disabled"`
|
Add Media Player and resume to last playback position
In order to ease podcast listening, the player can be put on top of the feed entry as main content.
Use the `Use podcast player` option to enable that. It works on audio and video.
Also, when playing audio or video, progression will be saved in order to be able to resume listening later.
This position saving is done using the original attachement/enclosures player AND podcast player and do not rely on
the podcast player option ti be enabled.
Additionally, I made the player fill the width with the entry container to ease seeking and have a bigger video.
updateEnclosures now keep existing enclosures based on URL
When feeds get updated, enclosures entries are always wiped and re-created. This cause two issue
- enclosure progression get lost in the process
- enclosure ID changes
I used the URL as identifier of an enclosure. Not perfect but hopefully should work.
When an enclosure already exist, I simply do nothing and leave the entry as is in the database.
If anyone is listening/watching to this enclosure during the refresh, the id stay coherent and progression saving still works.
The updateEnclosures function got a bit more complex. I tried to make it the more clear I could.
Some optimisation are possible but would make the function harder to read in my opinion.
I'm not sure if this is often the case, but some feeds may include tracking or simply change the url each
time we update the feed. In those situation, enclosures ids and progression will be lost.
I have no idea how to handle this last situation. Use the size instead/alongside url to define the identity of an enclosure ?
Translation: english as placeholder for every language except French
Aside, I tested a video feed and fixed a few things for it. In fact, the MimeType was not working
at all on my side, and found a pretty old stackoverflow discussion that suggest to use an Apple non-standard MimeType for
m4v video format. I only did one substitution because I only have one feed to test. Any new video feed can make this go away
or evolve depending on the situation. Real video feeds does not tend to be easy to find and test extensively this.
Co-authored-by: toastal
2023-04-13 11:46:43 +02:00
|
|
|
NoMediaPlayer *bool `json:"no_media_player"`
|
2021-02-21 22:42:49 +01:00
|
|
|
IgnoreHTTPCache *bool `json:"ignore_http_cache"`
|
|
|
|
AllowSelfSignedCertificates *bool `json:"allow_self_signed_certificates"`
|
|
|
|
FetchViaProxy *bool `json:"fetch_via_proxy"`
|
2021-08-15 17:32:43 +02:00
|
|
|
HideGlobally *bool `json:"hide_globally"`
|
2021-01-04 22:49:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Patch updates a feed with modified values.
|
|
|
|
func (f *FeedModificationRequest) Patch(feed *Feed) {
|
|
|
|
if f.FeedURL != nil && *f.FeedURL != "" {
|
|
|
|
feed.FeedURL = *f.FeedURL
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.SiteURL != nil && *f.SiteURL != "" {
|
|
|
|
feed.SiteURL = *f.SiteURL
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Title != nil && *f.Title != "" {
|
|
|
|
feed.Title = *f.Title
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.ScraperRules != nil {
|
|
|
|
feed.ScraperRules = *f.ScraperRules
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.RewriteRules != nil {
|
|
|
|
feed.RewriteRules = *f.RewriteRules
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.KeeplistRules != nil {
|
|
|
|
feed.KeeplistRules = *f.KeeplistRules
|
|
|
|
}
|
|
|
|
|
2022-07-12 06:12:26 +02:00
|
|
|
if f.UrlRewriteRules != nil {
|
|
|
|
feed.UrlRewriteRules = *f.UrlRewriteRules
|
|
|
|
}
|
|
|
|
|
2021-01-04 22:49:28 +01:00
|
|
|
if f.BlocklistRules != nil {
|
|
|
|
feed.BlocklistRules = *f.BlocklistRules
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Crawler != nil {
|
|
|
|
feed.Crawler = *f.Crawler
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.UserAgent != nil {
|
|
|
|
feed.UserAgent = *f.UserAgent
|
|
|
|
}
|
|
|
|
|
2021-03-23 04:27:58 +01:00
|
|
|
if f.Cookie != nil {
|
|
|
|
feed.Cookie = *f.Cookie
|
|
|
|
}
|
|
|
|
|
2021-01-04 22:49:28 +01:00
|
|
|
if f.Username != nil {
|
|
|
|
feed.Username = *f.Username
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Password != nil {
|
|
|
|
feed.Password = *f.Password
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.CategoryID != nil && *f.CategoryID > 0 {
|
|
|
|
feed.Category.ID = *f.CategoryID
|
|
|
|
}
|
|
|
|
|
|
|
|
if f.Disabled != nil {
|
|
|
|
feed.Disabled = *f.Disabled
|
|
|
|
}
|
|
|
|
|
Add Media Player and resume to last playback position
In order to ease podcast listening, the player can be put on top of the feed entry as main content.
Use the `Use podcast player` option to enable that. It works on audio and video.
Also, when playing audio or video, progression will be saved in order to be able to resume listening later.
This position saving is done using the original attachement/enclosures player AND podcast player and do not rely on
the podcast player option ti be enabled.
Additionally, I made the player fill the width with the entry container to ease seeking and have a bigger video.
updateEnclosures now keep existing enclosures based on URL
When feeds get updated, enclosures entries are always wiped and re-created. This cause two issue
- enclosure progression get lost in the process
- enclosure ID changes
I used the URL as identifier of an enclosure. Not perfect but hopefully should work.
When an enclosure already exist, I simply do nothing and leave the entry as is in the database.
If anyone is listening/watching to this enclosure during the refresh, the id stay coherent and progression saving still works.
The updateEnclosures function got a bit more complex. I tried to make it the more clear I could.
Some optimisation are possible but would make the function harder to read in my opinion.
I'm not sure if this is often the case, but some feeds may include tracking or simply change the url each
time we update the feed. In those situation, enclosures ids and progression will be lost.
I have no idea how to handle this last situation. Use the size instead/alongside url to define the identity of an enclosure ?
Translation: english as placeholder for every language except French
Aside, I tested a video feed and fixed a few things for it. In fact, the MimeType was not working
at all on my side, and found a pretty old stackoverflow discussion that suggest to use an Apple non-standard MimeType for
m4v video format. I only did one substitution because I only have one feed to test. Any new video feed can make this go away
or evolve depending on the situation. Real video feeds does not tend to be easy to find and test extensively this.
Co-authored-by: toastal
2023-04-13 11:46:43 +02:00
|
|
|
if f.NoMediaPlayer != nil {
|
|
|
|
feed.NoMediaPlayer = *f.NoMediaPlayer
|
|
|
|
}
|
|
|
|
|
2021-01-04 22:49:28 +01:00
|
|
|
if f.IgnoreHTTPCache != nil {
|
|
|
|
feed.IgnoreHTTPCache = *f.IgnoreHTTPCache
|
|
|
|
}
|
|
|
|
|
2021-02-21 22:42:49 +01:00
|
|
|
if f.AllowSelfSignedCertificates != nil {
|
|
|
|
feed.AllowSelfSignedCertificates = *f.AllowSelfSignedCertificates
|
|
|
|
}
|
|
|
|
|
2021-01-04 22:49:28 +01:00
|
|
|
if f.FetchViaProxy != nil {
|
|
|
|
feed.FetchViaProxy = *f.FetchViaProxy
|
|
|
|
}
|
2021-08-15 17:32:43 +02:00
|
|
|
|
|
|
|
if f.HideGlobally != nil {
|
|
|
|
feed.HideGlobally = *f.HideGlobally
|
|
|
|
}
|
2021-01-04 22:49:28 +01:00
|
|
|
}
|
|
|
|
|
2017-11-20 06:10:04 +01:00
|
|
|
// Feeds is a list of feed
|
|
|
|
type Feeds []*Feed
|