Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 []
|
||||
|
||||
13
config/config.go
Normal file → Executable file
13
config/config.go
Normal file → Executable file
@@ -1,10 +1,19 @@
|
||||
package config
|
||||
|
||||
import "os"
|
||||
|
||||
var (
|
||||
Feed = "https://www.youtube.com/feeds/videos.xml?channel_id=UCwX0AEx-qIhQ9kgtlNhyIXw"
|
||||
Root = "/tmp"
|
||||
Feed = orEnv("FEED", "https://www.youtube.com/feeds/videos.xml?channel_id=UCwX0AEx-qIhQ9kgtlNhyIXw")
|
||||
Root = orEnv("ROOT", "/tmp")
|
||||
)
|
||||
|
||||
func orEnv(k, v string) string {
|
||||
if w, ok := os.LookupEnv(k); ok {
|
||||
return w
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
/*
|
||||
config = {
|
||||
"path" : "../TV/Shepherds_Chapel" ,
|
||||
|
||||
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
37
main.go
Normal file → Executable file
37
main.go
Normal file → Executable file
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"local/youtuber/config"
|
||||
"local/youtuber/feed"
|
||||
@@ -9,19 +10,32 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Setenv("LC_ALL", "C.UTF-8")
|
||||
results, err := feed.Fetch(config.Feed)
|
||||
client, err := youtubedl.New()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
log.Println(results)
|
||||
interval := time.Hour * 4
|
||||
for true {
|
||||
err := do(client)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
log.Printf("sleeping until %v", time.Now().Add(interval))
|
||||
time.Sleep(interval)
|
||||
}
|
||||
}
|
||||
|
||||
youtubedl, err := youtubedl.New()
|
||||
func do(client *youtubedl.Client) error {
|
||||
errs := ""
|
||||
|
||||
results, err := feed.Fetch(config.Feed)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return err
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
@@ -32,10 +46,17 @@ func main() {
|
||||
result.Date.Day(),
|
||||
strings.Join(strings.Split(result.Title, " ")[2:], "_"),
|
||||
)
|
||||
if err := youtubedl.Download(result.Link, path.Join(config.Root, target)); err != nil {
|
||||
panic(err)
|
||||
target = path.Join(config.Root, target)
|
||||
if _, err := os.Stat(strings.ReplaceAll(target, "%(ext)s", "mp4")); !os.IsNotExist(err) {
|
||||
log.Printf("already exists: %s", target)
|
||||
continue
|
||||
}
|
||||
if err := client.Download(result.Link, path.Join(config.Root, target)); err != nil {
|
||||
errs += ", " + err.Error()
|
||||
}
|
||||
return
|
||||
}
|
||||
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 (
|
||||
"errors"
|
||||
"log"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
@@ -31,11 +32,15 @@ func installPyPip3() error {
|
||||
[]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:]...)
|
||||
if err := cmd.Run(); err == nil {
|
||||
err := cmd.Run()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
log.Println("%v: %v", err, combo)
|
||||
}
|
||||
return errors.New("cannot get python3 and pip3")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user