Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb0eea6140 | ||
|
|
1f14a2b147 |
13
Dockerfile
Executable file
13
Dockerfile
Executable file
@@ -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 []
|
||||||
|
|
||||||
56
config/config.go
Normal file → Executable file
56
config/config.go
Normal file → Executable file
@@ -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(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|||||||
0
feed/feed.go
Normal file → Executable file
0
feed/feed.go
Normal file → Executable file
0
feed/item.go
Normal file → Executable file
0
feed/item.go
Normal file → Executable file
45
main.go
Normal file → Executable file
45
main.go
Normal file → Executable file
@@ -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, path.Join(config.Root, target)); err != nil {
|
||||||
|
errs += ", " + err.Error()
|
||||||
}
|
}
|
||||||
log.Println(youtubedl)
|
}
|
||||||
|
if errs != "" {
|
||||||
|
return errors.New(errs)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
0
youtubedl/client.go
Normal file → Executable file
0
youtubedl/client.go
Normal file → Executable file
7
youtubedl/install.go
Normal file → Executable file
7
youtubedl/install.go
Normal file → Executable file
@@ -2,6 +2,7 @@ package youtubedl
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -31,11 +32,15 @@ func installPyPip3() error {
|
|||||||
[]string{"apt", "install", "python3", "pip3"},
|
[]string{"apt", "install", "python3", "pip3"},
|
||||||
[]string{"apk", "add", "python3", "py3-pip"},
|
[]string{"apk", "add", "python3", "py3-pip"},
|
||||||
[]string{"sudo", "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:]...)
|
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")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user