Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5daa95058d | ||
|
|
e4ede9c4e1 | ||
|
|
c98a50c5ab | ||
|
|
eba8001ca0 | ||
|
|
20326f2f39 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
ytubeSpdrun
|
ytubeSpdrun
|
||||||
**/*.sw*
|
**/*.sw*
|
||||||
|
exec-*
|
||||||
youtuber
|
youtuber
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -18,7 +18,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
interval := time.Hour * 4
|
interval := time.Minute * 30
|
||||||
for true {
|
for true {
|
||||||
err := do(client)
|
err := do(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -57,7 +57,7 @@ func do(client *youtubedl.Client) error {
|
|||||||
log.Printf("already exists: %s", target)
|
log.Printf("already exists: %s", target)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := client.Download(result.Link, path.Join(config.Root, target)); err != nil {
|
if err := client.Download(result.Link, target); err != nil {
|
||||||
errs += ", " + err.Error()
|
errs += ", " + err.Error()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,15 +15,49 @@ func New() (*Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Download(video, local string) error {
|
func (c *Client) Download(video, local string) error {
|
||||||
cmd := exec.Command("youtube-dl", "-f", "22", "-o", local, "--write-sub", "--write-auto-sub", "--sub-format", "srt", video)
|
errs := []error{}
|
||||||
log.Println(cmd.Path, cmd.Args)
|
for _, extras := range [][]string{
|
||||||
out, err := cmd.CombinedOutput()
|
[]string{"--add-metadata", "--metadata-from-title", ".*[0-9]/[0-9][0-9] (?P<title>.+)"},
|
||||||
if err != nil {
|
[]string{},
|
||||||
err = fmt.Errorf("%v: %s", err, out)
|
} {
|
||||||
|
args := append([]string{
|
||||||
|
"youtube-dl",
|
||||||
|
"-f",
|
||||||
|
"22",
|
||||||
|
"-o",
|
||||||
|
local,
|
||||||
|
"--write-sub",
|
||||||
|
"--write-auto-sub",
|
||||||
|
"--sub-format",
|
||||||
|
"srt",
|
||||||
|
}, extras...)
|
||||||
|
args = append(args, video)
|
||||||
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
|
log.Println(cmd.Path, cmd.Args)
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("failed with %v: %s", err, out)
|
||||||
|
errs = append(errs, fmt.Errorf("%v: %s", err, out))
|
||||||
|
} else {
|
||||||
|
log.Printf("passed with %s", out)
|
||||||
|
errs = nil
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(errs) > 0 {
|
||||||
|
err := fmt.Errorf("%v", errs)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cmd = exec.Command("python3", "-m", "vtt_to_srt", path.Dir(local))
|
cmd := exec.Command(
|
||||||
out, err = cmd.CombinedOutput()
|
"/bin/bash",
|
||||||
|
"-c",
|
||||||
|
fmt.Sprintf(
|
||||||
|
"true; python3 -m vtt_to_srt %q || python3 /usr/bin/vtt_to_srt.py %q",
|
||||||
|
path.Dir(local),
|
||||||
|
path.Dir(local),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("%v: %s", err, out)
|
err = fmt.Errorf("%v: %s", err, out)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func install() error {
|
func install() error {
|
||||||
if err := installPyPip3(); err != nil {
|
if err := installPyPip3FFMPEG(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := installYtdl(); err != nil {
|
if err := installYtdl(); err != nil {
|
||||||
@@ -19,30 +19,32 @@ func install() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func installPyPip3() error {
|
func installPyPip3FFMPEG() error {
|
||||||
hasPy := exec.Command("python3", "--version")
|
hasPy := exec.Command("python3", "--version")
|
||||||
hasPip := exec.Command("pip3", "--version")
|
hasPip := exec.Command("pip3", "--version")
|
||||||
|
hasFFMPEG := exec.Command("which", "ffmpeg")
|
||||||
if err := hasPy.Run(); err != nil {
|
if err := hasPy.Run(); err != nil {
|
||||||
} else if err := hasPip.Run(); err != nil {
|
} else if err := hasPip.Run(); err != nil {
|
||||||
|
} else if err := hasFFMPEG.Run(); err != nil {
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, combo := range [][]string{
|
for _, combo := range [][]string{
|
||||||
[]string{"sudo", "apt", "install", "python3", "pip3"},
|
[]string{"sudo", "apt", "install", "python3", "pip3", "ffmpeg"},
|
||||||
[]string{"apt", "install", "python3", "pip3"},
|
[]string{"apt", "install", "python3", "pip3", "ffmpeg"},
|
||||||
[]string{"apk", "add", "python3", "py3-pip"},
|
[]string{"apk", "add", "python3", "py3-pip", "ffmpeg"},
|
||||||
[]string{"sudo", "apk", "add", "python3", "py3-pip"},
|
[]string{"sudo", "apk", "add", "python3", "py3-pip", "ffmpeg"},
|
||||||
[]string{"/sbin/apk", "add", "python3", "py3-pip"},
|
[]string{"/sbin/apk", "add", "python3", "py3-pip", "ffmpeg"},
|
||||||
[]string{"sudo", "/sbin/apk", "add", "python3", "py3-pip"},
|
[]string{"sudo", "/sbin/apk", "add", "python3", "py3-pip", "ffmpeg"},
|
||||||
} {
|
} {
|
||||||
cmd := exec.Command(combo[0], combo[1:]...)
|
cmd := exec.Command(combo[0], combo[1:]...)
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
log.Println("%v: %v", err, combo)
|
log.Printf("%v: %v", err, combo)
|
||||||
}
|
}
|
||||||
return errors.New("cannot get python3 and pip3")
|
return errors.New("cannot get python3 and pip3 and ffmpeg")
|
||||||
}
|
}
|
||||||
|
|
||||||
func installYtdl() error {
|
func installYtdl() error {
|
||||||
|
|||||||
Reference in New Issue
Block a user