Compare commits
3 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
740f02bf6b | |
|
|
cb0eea6140 | |
|
|
1f14a2b147 |
|
|
@ -0,0 +1,13 @@
|
||||||
|
FROM frolvlad/alpine-glibc:alpine-3.9_glibc-2.29
|
||||||
|
RUN apk update && apk add --no-cache ca-certificates
|
||||||
|
|
||||||
|
RUN mkdir -p /var/log
|
||||||
|
WORKDIR /main
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
ENV GOPATH=""
|
||||||
|
ENV MNT="/mnt/"
|
||||||
|
ENTRYPOINT ["/main/exec-youtuber"]
|
||||||
|
CMD []
|
||||||
|
|
||||||
|
|
@ -1,20 +1,46 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
var (
|
import (
|
||||||
Feed = "https://www.youtube.com/feeds/videos.xml?channel_id=UCwX0AEx-qIhQ9kgtlNhyIXw"
|
"local/args"
|
||||||
Root = "/tmp"
|
"local/sandbox/contact/contact"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
var (
|
||||||
config = {
|
Feed string
|
||||||
"path" : "../TV/Shepherds_Chapel" ,
|
Root string
|
||||||
"rss" : "https://www.youtube.com/feeds/videos.xml?channel_id=UCwX0AEx-qIhQ9kgtlNhyIXw" ,
|
To string
|
||||||
"last" : 0 ,
|
Subject string
|
||||||
"lasttime" : datetime.datetime(1999,1,1) ,
|
Emailer *contact.Emailer
|
||||||
"onlynew" : False ,
|
)
|
||||||
"delay" : 12 ,
|
|
||||||
"clear" : False ,
|
func init() {
|
||||||
"logloc" : "./log" ,
|
os.Setenv("LC_ALL", "C.UTF-8")
|
||||||
"idle" : False ,
|
|
||||||
|
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(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"local/youtuber/config"
|
"local/youtuber/config"
|
||||||
"local/youtuber/feed"
|
"local/youtuber/feed"
|
||||||
|
|
@ -9,20 +10,39 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
os.Setenv("LC_ALL", "C.UTF-8")
|
client, err := youtubedl.New()
|
||||||
results, err := feed.Fetch(config.Feed)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
log.Println(results)
|
interval := time.Hour * 4
|
||||||
|
for true {
|
||||||
youtubedl, err := youtubedl.New()
|
err := do(client)
|
||||||
if err != nil {
|
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)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
log.Printf("sleeping until %v", time.Now().Add(interval))
|
||||||
|
time.Sleep(interval)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func do(client *youtubedl.Client) error {
|
||||||
|
errs := ""
|
||||||
|
|
||||||
|
results, err := feed.Fetch(config.Feed)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for _, result := range results {
|
for _, result := range results {
|
||||||
target := fmt.Sprintf(
|
target := fmt.Sprintf(
|
||||||
|
|
@ -32,10 +52,17 @@ func main() {
|
||||||
result.Date.Day(),
|
result.Date.Day(),
|
||||||
strings.Join(strings.Split(result.Title, " ")[2:], "_"),
|
strings.Join(strings.Split(result.Title, " ")[2:], "_"),
|
||||||
)
|
)
|
||||||
if err := youtubedl.Download(result.Link, path.Join(config.Root, target)); err != nil {
|
target = path.Join(config.Root, target)
|
||||||
panic(err)
|
if _, err := os.Stat(strings.ReplaceAll(target, "%(ext)s", "mp4")); !os.IsNotExist(err) {
|
||||||
|
log.Printf("already exists: %s", target)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
return
|
if err := client.Download(result.Link, target); err != nil {
|
||||||
|
errs += ", " + err.Error()
|
||||||
}
|
}
|
||||||
log.Println(youtubedl)
|
}
|
||||||
|
if errs != "" {
|
||||||
|
return errors.New(errs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,41 @@ 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{}
|
||||||
|
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)
|
log.Println(cmd.Path, cmd.Args)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("%v: %s", err, out)
|
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("python3", "-m", "vtt_to_srt", 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)
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,12 @@ package youtubedl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
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 {
|
||||||
|
|
@ -18,26 +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", "ffmpeg"},
|
||||||
|
[]string{"sudo", "/sbin/apk", "add", "python3", "py3-pip", "ffmpeg"},
|
||||||
} {
|
} {
|
||||||
cmd := exec.Command(combo[0], combo[1:]...)
|
cmd := exec.Command(combo[0], combo[1:]...)
|
||||||
if err := cmd.Run(); err == nil {
|
err := cmd.Run()
|
||||||
|
if err == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
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 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue