youtube backup tools
This commit is contained in:
commit
c5454cf303
|
@ -0,0 +1,9 @@
|
||||||
|
channel (
|
||||||
|
unus_annus "https://www.youtube.com/channel/UCIcgBZ9hEJxHv6r_jDYOMqg"
|
||||||
|
nile_red "https://www.youtube.com/channel/UCFhXFikryT4aFcLkLw2LBLA"
|
||||||
|
mrbeast "https://www.youtube.com/user/MrBeast6000"
|
||||||
|
bill_wurtz "https://www.youtube.com/user/billwurtz"
|
||||||
|
tom_scott "https://www.youtube.com/user/enyay"
|
||||||
|
conlang_critic "https://www.youtube.com/user/HBMmaster8472"
|
||||||
|
worldbuilding_notes "https://www.youtube.com/channel/UCncTjqw75krp9j_wRRh5Gvw"
|
||||||
|
)
|
|
@ -0,0 +1,8 @@
|
||||||
|
module tulpa.dev/cadey/ytback
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/mkmik/stringlist v1.0.1
|
||||||
|
within.website/confyg v0.4.0
|
||||||
|
)
|
|
@ -0,0 +1,4 @@
|
||||||
|
github.com/mkmik/stringlist v1.0.1 h1:wOGoAqZusN1bbqhwkcdiMB8z/uOnJGnciKrWXWPXyW4=
|
||||||
|
github.com/mkmik/stringlist v1.0.1/go.mod h1:TyqoldqwIeKUiL8vmAjYzu0qZfSP3cXVxTAfgBpw/TE=
|
||||||
|
within.website/confyg v0.4.0 h1:FklkpJyMLYBxECCI4RS4R2c/x7PblOvbX0qBjk8Wkjs=
|
||||||
|
within.website/confyg v0.4.0/go.mod h1:KD5rDgkE3B+vbDiH/usiuK+CfiOkCiuD87NEF3/budk=
|
|
@ -0,0 +1,62 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/mkmik/stringlist"
|
||||||
|
"within.website/confyg/flagconfyg"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
config = flag.String("cfg", "dl.config", "file to look for channel configurations in")
|
||||||
|
channels = stringlist.Flag("channel", "the channels to archive")
|
||||||
|
)
|
||||||
|
|
||||||
|
func runCommand(ctx context.Context, command, dir string, args ...string) error {
|
||||||
|
cmd := exec.CommandContext(ctx, command, args...)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Dir = dir
|
||||||
|
err := cmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return cmd.Wait()
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
flagconfyg.CmdParse(*config)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
for _, ch := range *channels {
|
||||||
|
sp := strings.SplitN(ch, " ", 2)
|
||||||
|
name := sp[0]
|
||||||
|
url := sp[1][1 : len(sp[1])-1]
|
||||||
|
|
||||||
|
log.Printf("name: %s, url: %s", name, url)
|
||||||
|
wg.Add(1)
|
||||||
|
go backupChannel(ctx, &wg, name, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
log.Println("everything backed up")
|
||||||
|
}
|
||||||
|
|
||||||
|
func backupChannel(ctx context.Context, wg *sync.WaitGroup, name, url string) {
|
||||||
|
defer wg.Done()
|
||||||
|
os.MkdirAll(name, 0777)
|
||||||
|
err := runCommand(ctx, "youtube-dl", name, "--add-metadata", "--quiet", "--sleep-interval", "30", "--max-sleep-interval", "60", "--force-ipv6", url)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("can't backup %s: %v", name, err)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue