mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
+1
-1
@@ -30,4 +30,4 @@ dist/
|
||||
venv/
|
||||
|
||||
.DS_Store
|
||||
podsync
|
||||
/podsync
|
||||
|
||||
@@ -39,7 +39,6 @@ In order to query YouTube or Vimeo API you have to obtain an API token first.
|
||||
[server]
|
||||
port = 8080
|
||||
data_dir = "/path/to/data/directory"
|
||||
hostname = "hostname"
|
||||
|
||||
[tokens]
|
||||
youtube = "{YOUTUBE_API_TOKEN}"
|
||||
@@ -54,9 +53,21 @@ vimeo = "{VIMEO_API_TOKEN}"
|
||||
format = "video" # or "audio"
|
||||
```
|
||||
|
||||
Episodes files will be kept at: `/path/to/data/directory/ID1`
|
||||
Episodes files will be kept at: `/path/to/data/directory/ID1`, feed will be accessible from: `http://localhost/ID1.xml`
|
||||
|
||||
Feed will be accessible from: `http://hostname:8080/ID1.xml`
|
||||
If you want to hide Podsync behind reverse proxy like nginx, you can use `hostname` field:
|
||||
|
||||
```toml
|
||||
[server]
|
||||
port = 8080
|
||||
hostname = "https://my.test.host:4443"
|
||||
|
||||
[feeds]
|
||||
[feeds.ID1]
|
||||
...
|
||||
```
|
||||
|
||||
Server will be accessible from `http://localhost:8080`, but episode links will point to `https://my.test.host:4443/ID1/...`
|
||||
|
||||
## How to run
|
||||
|
||||
|
||||
+11
-6
@@ -219,13 +219,9 @@ func (u *Updater) makeEnclosure(feed *model.Feed, episode *model.Episode, cfg *c
|
||||
contentType = itunes.MP3
|
||||
}
|
||||
|
||||
// Make sure there is no http:// prefix
|
||||
hostname := strings.TrimPrefix(u.config.Server.Hostname, "http://")
|
||||
|
||||
url := fmt.Sprintf(
|
||||
"http://%s:%d/%s/%s.%s",
|
||||
hostname,
|
||||
u.config.Server.Port,
|
||||
"%s/%s/%s.%s",
|
||||
u.hostname(),
|
||||
cfg.ID,
|
||||
episode.ID,
|
||||
ext,
|
||||
@@ -234,6 +230,15 @@ func (u *Updater) makeEnclosure(feed *model.Feed, episode *model.Episode, cfg *c
|
||||
return url, contentType, episode.Size
|
||||
}
|
||||
|
||||
func (u *Updater) hostname() string {
|
||||
hostname := strings.TrimSuffix(u.config.Server.Hostname, "/")
|
||||
if !strings.HasPrefix(hostname, "http") {
|
||||
hostname = fmt.Sprintf("http://%s", hostname)
|
||||
}
|
||||
|
||||
return hostname
|
||||
}
|
||||
|
||||
func (u *Updater) episodeName(feedConfig *config.Feed, episode *model.Episode) string {
|
||||
ext := "mp4"
|
||||
if feedConfig.Format == model.FormatAudio {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/mxpv/podsync/pkg/config"
|
||||
)
|
||||
|
||||
func TestUpdater_hostname(t *testing.T) {
|
||||
u := Updater{
|
||||
config: &config.Config{
|
||||
Server: config.Server{
|
||||
Hostname: "localhost",
|
||||
Port: 7979,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, "http://localhost", u.hostname())
|
||||
|
||||
// Trim end slash
|
||||
u.config.Server.Hostname = "https://localhost:8080/"
|
||||
assert.Equal(t, "https://localhost:8080", u.hostname())
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
@@ -103,7 +104,11 @@ func (c *Config) validate() error {
|
||||
|
||||
func (c *Config) applyDefaults() {
|
||||
if c.Server.Hostname == "" {
|
||||
c.Server.Hostname = model.DefaultHostname
|
||||
if c.Server.Port != 0 && c.Server.Port != 80 {
|
||||
c.Server.Hostname = fmt.Sprintf("http://localhost:%d", c.Server.Port)
|
||||
} else {
|
||||
c.Server.Hostname = "http://localhost"
|
||||
}
|
||||
}
|
||||
|
||||
for _, feed := range c.Feeds {
|
||||
|
||||
@@ -89,3 +89,28 @@ data_dir = "/data"
|
||||
assert.EqualValues(t, feed.Quality, "high")
|
||||
assert.EqualValues(t, feed.Format, "video")
|
||||
}
|
||||
|
||||
func TestDefaultHostname(t *testing.T) {
|
||||
cfg := Config{
|
||||
Server: Server{},
|
||||
}
|
||||
|
||||
t.Run("empty hostname", func(t *testing.T) {
|
||||
cfg.applyDefaults()
|
||||
assert.Equal(t, "http://localhost", cfg.Server.Hostname)
|
||||
})
|
||||
|
||||
t.Run("empty hostname with port", func(t *testing.T) {
|
||||
cfg.Server.Hostname = ""
|
||||
cfg.Server.Port = 7979
|
||||
cfg.applyDefaults()
|
||||
assert.Equal(t, "http://localhost:7979", cfg.Server.Hostname)
|
||||
})
|
||||
|
||||
t.Run("skip overwrite", func(t *testing.T) {
|
||||
cfg.Server.Hostname = "https://my.host:4443"
|
||||
cfg.Server.Port = 80
|
||||
cfg.applyDefaults()
|
||||
assert.Equal(t, "https://my.host:4443", cfg.Server.Hostname)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
DefaultHostname = "http://localhost"
|
||||
DefaultFormat = FormatVideo
|
||||
DefaultQuality = QualityHigh
|
||||
DefaultPageSize = 50
|
||||
|
||||
Reference in New Issue
Block a user