Compare commits
No commits in common. "master" and "v0.1" have entirely different histories.
|
|
@ -1,46 +1,29 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"local/args"
|
||||
"local/sandbox/contact/contact"
|
||||
"os"
|
||||
)
|
||||
import "os"
|
||||
|
||||
var (
|
||||
Feed string
|
||||
Root string
|
||||
To string
|
||||
Subject string
|
||||
Emailer *contact.Emailer
|
||||
Feed = orEnv("FEED", "https://www.youtube.com/feeds/videos.xml?channel_id=UCwX0AEx-qIhQ9kgtlNhyIXw")
|
||||
Root = orEnv("ROOT", "/tmp")
|
||||
)
|
||||
|
||||
func init() {
|
||||
os.Setenv("LC_ALL", "C.UTF-8")
|
||||
|
||||
as := args.NewArgSet()
|
||||
|
||||
as.Append(args.STRING, "to", "message recipient", "squeaky2x3@gmail.com")
|
||||
as.Append(args.STRING, "subject", "message subject", "youtuber error")
|
||||
as.Append(args.STRING, "from", "message sender", "breellocaldev@gmail.com")
|
||||
as.Append(args.STRING, "password", "message sender password", "ML3WQRFSqe9rQ8qNkm")
|
||||
as.Append(args.STRING, "smtp", "smtp server:port", "smtp.gmail.com:465")
|
||||
as.Append(args.STRING, "pop3", "pop3 server:port", "pop.gmail.com:995")
|
||||
|
||||
as.Append(args.STRING, "feed", "feed URL", "https://www.youtube.com/feeds/videos.xml?channel_id=UCwX0AEx-qIhQ9kgtlNhyIXw")
|
||||
as.Append(args.STRING, "root", "root to save videos", "/tmp")
|
||||
|
||||
if err := as.Parse(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Feed = as.Get("feed").GetString()
|
||||
Root = as.Get("root").GetString()
|
||||
To = as.Get("to").GetString()
|
||||
Subject = as.Get("subject").GetString()
|
||||
Emailer = &contact.Emailer{
|
||||
From: as.Get("from").GetString(),
|
||||
SMTP: as.Get("smtp").GetString(),
|
||||
POP3: as.Get("pop3").GetString(),
|
||||
Password: as.Get("password").GetString(),
|
||||
func orEnv(k, v string) string {
|
||||
if w, ok := os.LookupEnv(k); ok {
|
||||
return w
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
/*
|
||||
config = {
|
||||
"path" : "../TV/Shepherds_Chapel" ,
|
||||
"rss" : "https://www.youtube.com/feeds/videos.xml?channel_id=UCwX0AEx-qIhQ9kgtlNhyIXw" ,
|
||||
"last" : 0 ,
|
||||
"lasttime" : datetime.datetime(1999,1,1) ,
|
||||
"onlynew" : False ,
|
||||
"delay" : 12 ,
|
||||
"clear" : False ,
|
||||
"logloc" : "./log" ,
|
||||
"idle" : False ,
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
10
main.go
10
main.go
|
|
@ -14,6 +14,7 @@ import (
|
|||
)
|
||||
|
||||
func main() {
|
||||
os.Setenv("LC_ALL", "C.UTF-8")
|
||||
client, err := youtubedl.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
|
@ -23,13 +24,6 @@ func main() {
|
|||
err := do(client)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
if err := config.Emailer.Send(
|
||||
config.To,
|
||||
config.Subject,
|
||||
fmt.Sprintf("error getting youtuber: %v", err),
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
log.Printf("sleeping until %v", time.Now().Add(interval))
|
||||
time.Sleep(interval)
|
||||
|
|
@ -57,7 +51,7 @@ func do(client *youtubedl.Client) error {
|
|||
log.Printf("already exists: %s", target)
|
||||
continue
|
||||
}
|
||||
if err := client.Download(result.Link, target); err != nil {
|
||||
if err := client.Download(result.Link, path.Join(config.Root, target)); err != nil {
|
||||
errs += ", " + err.Error()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,41 +15,15 @@ func New() (*Client, error) {
|
|||
}
|
||||
|
||||
func (c *Client) Download(video, local string) error {
|
||||
errs := []error{}
|
||||
for _, extras := range [][]string{
|
||||
[]string{"--add-metadata", "--metadata-from-title", ".*[0-9]/[0-9][0-9] (?P<title>.+)"},
|
||||
[]string{},
|
||||
} {
|
||||
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)
|
||||
cmd := exec.Command("youtube-dl", "-f", "22", "-o", local, "--write-sub", "--write-auto-sub", "--sub-format", "srt", video)
|
||||
log.Println(cmd.Path, cmd.Args)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%v: %s", err, out)
|
||||
return err
|
||||
}
|
||||
cmd := exec.Command("python3", "-m", "vtt_to_srt", path.Dir(local))
|
||||
out, err := cmd.CombinedOutput()
|
||||
cmd = exec.Command("python3", "-m", "vtt_to_srt", path.Dir(local))
|
||||
out, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%v: %s", err, out)
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func install() error {
|
||||
if err := installPyPip3FFMPEG(); err != nil {
|
||||
if err := installPyPip3(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := installYtdl(); err != nil {
|
||||
|
|
@ -19,23 +19,21 @@ func install() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func installPyPip3FFMPEG() error {
|
||||
func installPyPip3() error {
|
||||
hasPy := exec.Command("python3", "--version")
|
||||
hasPip := exec.Command("pip3", "--version")
|
||||
hasFFMPEG := exec.Command("which", "ffmpeg")
|
||||
if err := hasPy.Run(); err != nil {
|
||||
} else if err := hasPip.Run(); err != nil {
|
||||
} else if err := hasFFMPEG.Run(); err != nil {
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
for _, combo := range [][]string{
|
||||
[]string{"sudo", "apt", "install", "python3", "pip3", "ffmpeg"},
|
||||
[]string{"apt", "install", "python3", "pip3", "ffmpeg"},
|
||||
[]string{"apk", "add", "python3", "py3-pip", "ffmpeg"},
|
||||
[]string{"sudo", "apk", "add", "python3", "py3-pip", "ffmpeg"},
|
||||
[]string{"/sbin/apk", "add", "python3", "py3-pip", "ffmpeg"},
|
||||
[]string{"sudo", "/sbin/apk", "add", "python3", "py3-pip", "ffmpeg"},
|
||||
[]string{"sudo", "apt", "install", "python3", "pip3"},
|
||||
[]string{"apt", "install", "python3", "pip3"},
|
||||
[]string{"apk", "add", "python3", "py3-pip"},
|
||||
[]string{"sudo", "apk", "add", "python3", "py3-pip"},
|
||||
[]string{"/sbin/apk", "add", "python3", "py3-pip"},
|
||||
[]string{"sudo", "/sbin/apk", "add", "python3", "py3-pip"},
|
||||
} {
|
||||
cmd := exec.Command(combo[0], combo[1:]...)
|
||||
err := cmd.Run()
|
||||
|
|
@ -44,7 +42,7 @@ func installPyPip3FFMPEG() error {
|
|||
}
|
||||
log.Println("%v: %v", err, combo)
|
||||
}
|
||||
return errors.New("cannot get python3 and pip3 and ffmpeg")
|
||||
return errors.New("cannot get python3 and pip3")
|
||||
}
|
||||
|
||||
func installYtdl() error {
|
||||
|
|
|
|||
Loading…
Reference in New Issue