diff --git a/internal/model/enclosure.go b/internal/model/enclosure.go index 0e794575505..c142b5f4b09 100644 --- a/internal/model/enclosure.go +++ b/internal/model/enclosure.go @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 package model // import "miniflux.app/v2/internal/model" + import ( "strings" @@ -34,9 +35,34 @@ func (e Enclosure) Html5MimeType() string { return e.MimeType } +func (e *Enclosure) IsAudio() bool { + return strings.HasPrefix(strings.ToLower(e.MimeType), "audio/") +} + +func (e *Enclosure) IsVideo() bool { + return strings.HasPrefix(strings.ToLower(e.MimeType), "video/") +} + +func (e *Enclosure) IsImage() bool { + mimeType := strings.ToLower(e.MimeType) + mediaURL := strings.ToLower(e.URL) + return strings.HasPrefix(mimeType, "image/") || strings.HasSuffix(mediaURL, ".jpg") || strings.HasSuffix(mediaURL, ".jpeg") || strings.HasSuffix(mediaURL, ".png") || strings.HasSuffix(mediaURL, ".gif") +} + // EnclosureList represents a list of attachments. type EnclosureList []*Enclosure +// FindMediaPlayerEnclosure returns the first enclosure that can be played by a media player. +func (el EnclosureList) FindMediaPlayerEnclosure() *Enclosure { + for _, enclosure := range el { + if enclosure.URL != "" && strings.Contains(enclosure.MimeType, "audio/") || strings.Contains(enclosure.MimeType, "video/") { + return enclosure + } + } + + return nil +} + func (el EnclosureList) ContainsAudioOrVideo() bool { for _, enclosure := range el { if strings.Contains(enclosure.MimeType, "audio/") || strings.Contains(enclosure.MimeType, "video/") { diff --git a/internal/template/templates/views/entry.html b/internal/template/templates/views/entry.html index 7e082e5604e..0d507a28a42 100644 --- a/internal/template/templates/views/entry.html +++ b/internal/template/templates/views/entry.html @@ -165,56 +165,55 @@

{{ end }} {{ end }}
- {{ if (and .entry.Enclosures (not .entry.Feed.NoMediaPlayer)) }} - {{ range .entry.Enclosures }} - {{ if ne .URL "" }} - {{ if hasPrefix .MimeType "audio/" }} -
- - {{ template "enclosure_media_controls" . }} -
- {{ else if hasPrefix .MimeType "video/" }} -
- - {{ template "enclosure_media_controls" . }} -
- {{ end }} - {{ end }} + {{ end }} {{ end }} - {{end}} - {{ if .user }} + {{ end }} + + {{ if .user }} {{ noescape (proxyFilter .entry.Content) }} - {{ else }} + {{ else }} {{ noescape .entry.Content }} - {{ end }} + {{ end }}
{{ if .entry.Enclosures }}
@@ -222,45 +221,7 @@

{{ range .entry.Enclosures }} {{ if ne .URL "" }}
- {{ if hasPrefix .MimeType "audio/" }} -
- - {{ template "enclosure_media_controls" . }} -
- {{ else if hasPrefix .MimeType "video/" }} -
- - {{ template "enclosure_media_controls" . }} -
- {{ else if hasPrefix .MimeType "image/" }} + {{ if .IsImage }}
{{ if (and $.user (mustBeProxyfied "image")) }} {{ .URL }} ({{ .MimeType }}) @@ -271,7 +232,7 @@

{{ end }}
- {{ .URL | safeURL }} + {{ .URL | safeURL }} {{ if gt .Size 0 }} - {{ formatFileSize .Size }}{{ end }}