2 Commits
v0.3 ... v0.4

Author SHA1 Message Date
bel
c98a50c5ab Use new vtt to srt of needed 2020-12-08 07:47:10 -07:00
bel
eba8001ca0 Whoops I lost this repo and scraped from docker image 2020-12-08 07:43:50 -07:00
3 changed files with 22 additions and 11 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
ytubeSpdrun ytubeSpdrun
**/*.sw* **/*.sw*
exec-*
youtuber youtuber

View File

@@ -17,7 +17,7 @@ func New() (*Client, error) {
func (c *Client) Download(video, local string) error { func (c *Client) Download(video, local string) error {
errs := []error{} errs := []error{}
for _, extras := range [][]string{ for _, extras := range [][]string{
[]string{"--metadata-from-title", ".*[0-9]/[0-9][0-9] (?P<title>.+)"}, []string{"--add-metadata", "--metadata-from-title", ".*[0-9]/[0-9][0-9] (?P<title>.+)"},
[]string{}, []string{},
} { } {
args := append([]string{ args := append([]string{
@@ -48,7 +48,15 @@ func (c *Client) Download(video, local string) error {
err := fmt.Errorf("%v", errs) err := fmt.Errorf("%v", errs)
return err return err
} }
cmd := exec.Command("python3", "-m", "vtt_to_srt", path.Dir(local)) cmd := exec.Command(
"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() out, err := cmd.CombinedOutput()
if err != nil { if err != nil {
err = fmt.Errorf("%v: %s", err, out) err = fmt.Errorf("%v: %s", err, out)

View File

@@ -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,21 +19,23 @@ 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()
@@ -42,7 +44,7 @@ func installPyPip3() error {
} }
log.Println("%v: %v", err, combo) log.Println("%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 {