Skip to content

Commit

Permalink
Rebase with main
Browse files Browse the repository at this point in the history
  • Loading branch information
Th0masL committed Nov 23, 2022
2 parents c8b4aa2 + 5b7ddeb commit 453484a
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 24 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
tags:
- 'v*'
schedule:
- cron: "0 0 * * *" # Every day at midnight

jobs:
publish:
Expand All @@ -29,10 +31,20 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

# Publish a new release from git tag.
- uses: goreleaser/goreleaser-action@v3.2.0
if: startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Publish nightly build.
- uses: goreleaser/goreleaser-action@v3.2.0
if: github.event_name == 'schedule'
with:
version: latest
args: release --rm-dist --nightly
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
10 changes: 7 additions & 3 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,18 @@ vimeo = [ # Multiple keys will be rotated.
# How often query for updates, examples: "60m", "4h", "2h45m"
update_period = "12h"

quality = "high" # or "low"
format = "video" # or "audio"
quality = "high" # "high" or "low"
format = "video" # "audio", "video" or "custom"
# When format = "custom"
# YouTubeDL format parameter and result file extension
custom_format = { youtube_dl_format = "bestaudio[ext=m4a]", extension = "m4a" }

playlist_sort = "asc" # or "desc", which will fetch playlist items from the end

# Optional maximal height of video, example: 720, 1080, 1440, 2160, ...
max_height = 720

# Optinally include this feed in OPML file (default value: false)
# Optionally include this feed in OPML file (default value: false)
opml = true

# Optional cron expression format for more precise update schedule.
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/mxpv/podsync

require (
github.com/BrianHicks/finch v0.0.0-20140409222414-419bd73c29ec
github.com/aws/aws-sdk-go v1.44.128
github.com/aws/aws-sdk-go v1.44.144
github.com/dgraph-io/badger v1.6.2
github.com/eduncan911/podcast v1.4.2
github.com/gilliek/go-opml v1.0.0
Expand All @@ -17,7 +17,7 @@ require (
github.com/stretchr/testify v1.8.1
github.com/zackradisic/soundcloud-api v0.1.8
golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
google.golang.org/api v0.0.0-20180718221112-efcb5f25ac56
google.golang.org/appengine v1.1.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
Expand Down
27 changes: 19 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/aws/aws-sdk-go v1.44.128 h1:X34pX5t0LIZXjBY11yf9JKMP3c1aZgirh+5PjtaZyJ4=
github.com/aws/aws-sdk-go v1.44.128/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go v1.44.144 h1:mMWdnYL8HZsobrQe1mwvQ18Xt8UbOVhWgipjuma5Mkg=
github.com/aws/aws-sdk-go v1.44.144/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down Expand Up @@ -94,22 +94,28 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zackradisic/soundcloud-api v0.1.8 h1:Fc4IVbee8ggGZ/vyx26uyTwKeh6Vn3cCrPXdTbQypjI=
github.com/zackradisic/soundcloud-api v0.1.8/go.mod h1:ycGIZFVZdUVC7B8pcfgze1bRBePPmjYlIGnRptKByQ0=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd h1:O7DYs+zxREGLKzKoMQrtrEacpb0ZVXA5rIwylE2Xchk=
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.1.0 h1:hZ/3BUoy5aId7sCpA/Tc5lt8DkFgdVS2onTpJsZ/fl0=
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd h1:QQhib242ErYDSMitlBm8V7wYCm/1a25hV8qMadIKLPA=
golang.org/x/oauth2 v0.0.0-20180620175406-ef147856a6dd/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -119,18 +125,23 @@ golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
7 changes: 7 additions & 0 deletions pkg/feed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Config struct {
MaxHeight int `toml:"max_height"`
// Format to use for this feed
Format model.Format `toml:"format"`
// Custom format properties
CustomFormat CustomFormat `toml:"custom_format"`
// Only download episodes that match the filters (defaults to matching anything)
Filters Filters `toml:"filters"`
// Clean is a cleanup policy to use for this feed
Expand All @@ -44,6 +46,11 @@ type Config struct {
PlaylistSort model.Sorting `toml:"playlist_sort"`
}

type CustomFormat struct {
YouTubeDLFormat string `toml:"youtube_dl_format"`
Extension string `toml:"extension"`
}

type Filters struct {
Title string `toml:"title"`
NotTitle string `toml:"not_title"`
Expand Down
28 changes: 28 additions & 0 deletions pkg/feed/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ func Build(_ctx context.Context, feed *model.Feed, cfg *Config, hostname string)
if feed.Format == model.FormatAudio {
enclosureType = itunes.MP3
}
if feed.Format == model.FormatCustom {
enclosureType = EnclosureFromExtension(cfg)
}

var (
episodeName = EpisodeName(cfg, episode)
Expand Down Expand Up @@ -165,6 +168,31 @@ func EpisodeName(feedConfig *Config, episode *model.Episode) string {
if feedConfig.Format == model.FormatAudio {
ext = "mp3"
}
if feedConfig.Format == model.FormatCustom {
ext = feedConfig.CustomFormat.Extension
}

return fmt.Sprintf("%s.%s", episode.ID, ext)
}

func EnclosureFromExtension(feedConfig *Config) itunes.EnclosureType {
ext := feedConfig.CustomFormat.Extension

switch {
case ext == "m4a":
return itunes.M4A
case ext == "m4v":
return itunes.M4V
case ext == "mp4":
return itunes.MP4
case ext == "mp3":
return itunes.MP3
case ext == "mov":
return itunes.MOV
case ext == "pdf":
return itunes.PDF
case ext == "epub":
return itunes.EPUB
}
return -1
}
5 changes: 3 additions & 2 deletions pkg/model/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ const (
type Format string

const (
FormatAudio = Format("audio")
FormatVideo = Format("video")
FormatAudio = Format("audio")
FormatVideo = Format("video")
FormatCustom = Format("custom")
)

// Playlist sorting style
Expand Down
8 changes: 7 additions & 1 deletion pkg/ytdl/ytdl.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ func (dl *YoutubeDl) Download(ctx context.Context, feedConfig *feed.Config, epis
if feedConfig.Format == model.FormatAudio {
ext = "mp3"
}
if feedConfig.Format == model.FormatCustom {
ext = feedConfig.CustomFormat.Extension
}

// filePath now with the final extension
filePath = filepath.Join(tmpDir, fmt.Sprintf("%s.%s", episode.ID, ext))
f, err := os.Open(filePath)
Expand Down Expand Up @@ -236,14 +240,16 @@ func buildArgs(feedConfig *feed.Config, episode *model.Episode, outputFilePath s
}

args = append(args, "--format", format)
} else {
} else if feedConfig.Format == model.FormatAudio {
// Audio, mp3, high by default
format := "bestaudio"
if feedConfig.Quality == model.QualityLow {
format = "worstaudio"
}

args = append(args, "--extract-audio", "--audio-format", "mp3", "--format", format)
} else {
args = append(args, "--audio-format", feedConfig.CustomFormat.Extension, "--format", feedConfig.CustomFormat.YouTubeDLFormat)
}

// Insert additional per-feed youtube-dl arguments
Expand Down
27 changes: 19 additions & 8 deletions pkg/ytdl/ytdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (

func TestBuildArgs(t *testing.T) {
tests := []struct {
name string
format model.Format
quality model.Quality
maxHeight int
output string
videoURL string
ytdlArgs []string
expect []string
name string
format model.Format
customFormat feed.CustomFormat
quality model.Quality
maxHeight int
output string
videoURL string
ytdlArgs []string
expect []string
}{
{
name: "Audio unknown quality",
Expand Down Expand Up @@ -101,13 +102,23 @@ func TestBuildArgs(t *testing.T) {
ytdlArgs: []string{"--write-sub", "--embed-subs", "--sub-lang", "en,en-US,en-GB"},
expect: []string{"--format", "bestvideo[ext=mp4][vcodec^=avc1]+bestaudio[ext=m4a]/best[ext=mp4][vcodec^=avc1]/best[ext=mp4]/best", "--write-sub", "--embed-subs", "--sub-lang", "en,en-US,en-GB", "--output", "/tmp/2", "http://url1"},
},
{
name: "Custom format",
format: model.FormatCustom,
customFormat: feed.CustomFormat{YouTubeDLFormat: "bestaudio[ext=m4a]", Extension: "m4a"},
quality: model.QualityHigh,
output: "/tmp/2",
videoURL: "http://url1",
expect: []string{"--audio-format", "m4a", "--format", "bestaudio[ext=m4a]", "--output", "/tmp/2", "http://url1"},
},
}

for _, tst := range tests {
t.Run(tst.name, func(t *testing.T) {
result := buildArgs(&feed.Config{
Format: tst.format,
Quality: tst.quality,
CustomFormat: tst.customFormat,
MaxHeight: tst.maxHeight,
YouTubeDLArgs: tst.ytdlArgs,
}, &model.Episode{
Expand Down

0 comments on commit 453484a

Please sign in to comment.