From d09271096bc2d758a88bb1e45c121c2e81eafb70 Mon Sep 17 00:00:00 2001 From: Maksym Pavlenko Date: Fri, 15 Nov 2019 10:57:55 -0800 Subject: [PATCH] Fix download links when using custom port #43 --- README.md | 4 ++-- cmd/podsync/updater.go | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5f6f445..3b634e0 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ 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 = "http://hostname" +hostname = "hostname" [tokens] youtube = "{YOUTUBE_API_TOKEN}" @@ -54,7 +54,7 @@ vimeo = "{VIMEO_API_TOKEN}" Episodes files will be kept at: `/path/to/data/directory/ID1` -Feed will be accessible from: `http://hostname/ID1.xml` +Feed will be accessible from: `http://hostname:8080/ID1.xml` ## How to run diff --git a/cmd/podsync/updater.go b/cmd/podsync/updater.go index d5176fc..4bfac15 100644 --- a/cmd/podsync/updater.go +++ b/cmd/podsync/updater.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "strconv" + "strings" "time" itunes "github.com/mxpv/podcast" @@ -216,7 +217,18 @@ func (u *Updater) makeEnclosure(feed *model.Feed, episode *model.Episode, cfg *c contentType = itunes.MP3 } - url := fmt.Sprintf("%s/%s/%s.%s", u.config.Server.Hostname, cfg.ID, episode.ID, ext) + // 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, + cfg.ID, + episode.ID, + ext, + ) + return url, contentType, episode.Size }