Commit ba503d5c authored by Tom Webster's avatar Tom Webster
Browse files

Added ease-of-use pm-dap utility

parent f4fe4b90
Pipeline #327693657 passed with stage
in 4 minutes and 5 seconds
......@@ -6,4 +6,5 @@
/.cache
/Dockerfiles/Application/config.yml
/Dockerfiles/Application/podcastmaker
/pmapp.tar.xz
\ No newline at end of file
/pmapp.tar.xz
/utilities/pm-dap/pm-dap
\ No newline at end of file
......@@ -33,7 +33,7 @@ func DownloadVideosForChannel(config *Config, channelURL string, storageEngine S
log.Println("Looks like I already have:", feedEntry.Title, "("+fullPath+")")
} else {
log.Println("I need to download a file:", feedEntry.Title, "("+fullPath+")")
err := DownloadVideo(feedEntry.URL, storageEngine)
err := DownloadVideo(feedEntry.URL, storageEngine, true)
if err != nil {
return []FeedItem{}, err
}
......@@ -46,17 +46,27 @@ func DownloadVideosForChannel(config *Config, channelURL string, storageEngine S
return feed, nil
}
func DownloadVideo(url string, storageEngine StorageEngine) error {
func DownloadVideo(url string, storageEngine StorageEngine, useRandomSleep bool) error {
filename := GetUUIDFromURL(url) + FileExtension
filepath := filepath.Join(storageEngine.TempDir(), filename)
ytdl := exec.Command(
"youtube-dl",
"--newline",
"--sleep-interval", "30",
"--max-sleep-interval", "60",
"-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4",
"-o", filepath,
url)
var ytdl *exec.Cmd
if useRandomSleep {
ytdl = exec.Command(
"youtube-dl",
"--newline",
"--sleep-interval", "30",
"--max-sleep-interval", "60",
"-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4",
"-o", filepath,
url)
} else {
ytdl = exec.Command(
"youtube-dl",
"--newline",
"-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/mp4",
"-o", filepath,
url)
}
log.Println("Running:", ytdl.String())
output, err := ytdl.CombinedOutput()
log.Println(string(output))
......
# pm-dap
The "PodcastMaker Download and Push" utility. Use this to re-download and
re-upload videos, just in case something got broken.
## Usage
`pm-dap` uses the same flags as `podcastmaker` and requires a single additional
argument to download-and-push a video to your `StorageEngine`: `-url`.
Use it like this: `pm-dap -c config.yml -url https://www.youtube.com/watch?v=ZZ5LpwO-An4`
**NOTE:** `pm-dap` will automatically remove backslash characters from your URL.
module gitlab.com/samurailink3/podcastmaker/utilities/pm-dap
go 1.16
require gitlab.com/samurailink3/podcastmaker/lib/podcastmaker v0.0.0
replace gitlab.com/samurailink3/podcastmaker/lib/podcastmaker v0.0.0 => ../../lib/podcastmaker
github.com/aws/aws-sdk-go v1.38.68 h1:aOG8geU4SohNp659eKBHRBgbqSrZ6jNZlfimIuJAwL8=
github.com/aws/aws-sdk-go v1.38.68/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gorilla/feeds v1.1.1 h1:HwKXxqzcRNg9to+BbvJog4+f3s/xzvtZXICcQGutYfY=
github.com/gorilla/feeds v1.1.1/go.mod h1:Nk0jZrvPFZX1OBe5NPiddPw7CfwF6Q9eqzaBbaightA=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201216054612-986b41b23924/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
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=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
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.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
pm "gitlab.com/samurailink3/podcastmaker/lib/podcastmaker"
)
func main() {
url := flag.String("url", "", "the url of the video you would like to download and push")
config, err := pm.Init()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
storageEngine, err := config.BuildStorageEngine()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(*url) == 0 {
fmt.Println("You must include a video url to download with the `-url` flag")
flag.PrintDefaults()
os.Exit(1)
}
// Remove backspaces from URL, some shells like zsh will helpfully escape
// URLs
*url = strings.ReplaceAll(*url, `\`, "")
err = DownloadAndPush(*url, storageEngine)
if err != nil {
log.Fatal(err)
}
}
// DownloadAndPush will download the video from the URL argument and upload it
// to your configured StorageEngine.
func DownloadAndPush(url string, storageEngine pm.StorageEngine) (err error) {
err = pm.DownloadVideo(url, storageEngine, false)
if err != nil {
return err
}
return nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment