Skip to content

Commit

Permalink
added rss enclosures
Browse files Browse the repository at this point in the history
  • Loading branch information
wybiral committed Jun 29, 2019
1 parent 0b87a11 commit 0979457
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 16 additions & 1 deletion pkg/app/app.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package app

import (
"fmt"
"html/template"
"log"
"net"
"net/http"
"net/url"
"path"
"strconv"
"time"

"github.com/fsnotify/fsnotify"
Expand Down Expand Up @@ -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
}
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions pkg/media/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Video struct {
Thumb []byte
ThumbType string
Modified string
Size int64
Timestamp time.Time
}

Expand All @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 0979457

Please sign in to comment.