added rss enclosures

This commit is contained in:
davy 2019-06-29 11:16:01 -05:00
parent 0b87a1137f
commit 0979457d75
3 changed files with 20 additions and 2 deletions

View file

@ -5,7 +5,7 @@
"port": 0
},
"feed": {
"external_url": "http://your-url.example",
"external_url": "",
"title": "Feed Title",
"link": "http://your-url.example/about",
"description": "Feed Description",

View file

@ -1,12 +1,14 @@
package app
import (
"fmt"
"html/template"
"log"
"net"
"net/http"
"net/url"
"path"
"strconv"
"time"
"github.com/fsnotify/fsnotify"
@ -179,8 +181,16 @@ func (a *App) rssHandler(w http.ResponseWriter, r *http.Request) {
Created: now,
Copyright: cfg.Copyright,
}
var externalURL string
if len(cfg.ExternalURL) > 0 {
externalURL = cfg.ExternalURL
} else {
host := a.Config.Server.Host
port := a.Config.Server.Port
externalURL = fmt.Sprintf("http://%s:%d", host, port)
}
for _, v := range a.Library.Playlist() {
u, err := url.Parse(cfg.ExternalURL)
u, err := url.Parse(externalURL)
if err != nil {
return
}
@ -191,6 +201,11 @@ func (a *App) rssHandler(w http.ResponseWriter, r *http.Request) {
Title: v.Title,
Link: &feeds.Link{Href: id},
Description: v.Description,
Enclosure: &feeds.Enclosure{
Url: id + ".mp4",
Length: strconv.FormatInt(v.Size, 10),
Type: "video/mp4",
},
Author: &feeds.Author{
Name: cfg.Author.Name,
Email: cfg.Author.Email,

View file

@ -16,6 +16,7 @@ type Video struct {
Thumb []byte
ThumbType string
Modified string
Size int64
Timestamp time.Time
}
@ -28,6 +29,7 @@ func ParseVideo(path string) (*Video, error) {
if err != nil {
return nil, err
}
size := info.Size()
timestamp := info.ModTime()
modified := timestamp.Format("2006-01-02 03:04 PM")
name := info.Name()
@ -52,6 +54,7 @@ func ParseVideo(path string) (*Video, error) {
Album: m.Album(),
Description: m.Comment(),
Modified: modified,
Size: size,
Timestamp: timestamp,
}
// Add thumbnail (if exists)