youtube backup tools

This commit is contained in:
Cadey Ratio 2019-11-19 01:02:19 +00:00
commit c5454cf303
4 changed files with 83 additions and 0 deletions

9
dl.config Normal file
View File

@ -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"
)

8
go.mod Normal file
View File

@ -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
)

4
go.sum Normal file
View File

@ -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=

62
main.go Normal file
View File

@ -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)
}
}