3 Commits
v0.7 ... v0.8

Author SHA1 Message Date
Bel LaPointe
0016e5afa9 Configurable interval 2021-01-25 08:53:15 -06:00
Bel LaPointe
70f0231371 helpfuller dockerfile 2021-01-25 08:49:49 -06:00
Bel LaPointe
5ac21eed3a change storage structure for seasons episodes 2021-01-25 08:37:32 -06:00
3 changed files with 17 additions and 13 deletions

View File

@@ -6,6 +6,8 @@ WORKDIR /main
COPY . .
RUN test -e /main/exec-youtuber
ENV GOPATH=""
ENV MNT="/mnt/"
ENTRYPOINT ["/main/exec-youtuber"]

View File

@@ -4,14 +4,16 @@ import (
"local/args"
"local/sandbox/contact/contact"
"os"
"time"
)
var (
Feed string
Root string
To string
Subject string
Emailer *contact.Emailer
Feed string
Root string
To string
Subject string
Emailer *contact.Emailer
Interval time.Duration
)
func init() {
@@ -28,6 +30,7 @@ func init() {
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")
as.Append(args.DURATION, "interval", "check interval", time.Hour)
if err := as.Parse(); err != nil {
panic(err)

15
main.go
View File

@@ -18,7 +18,7 @@ func main() {
if err != nil {
panic(err)
}
interval := time.Minute * 30
interval := config.Interval
for true {
err := do(client)
if err != nil {
@@ -45,18 +45,17 @@ func do(client *youtubedl.Client) error {
}
for _, result := range results {
target := fmt.Sprintf(
"s%02d%02de%02d_%s.%%(ext)s",
result.Date.Year()-2000,
result.Date.Month(),
result.Date.Day(),
strings.Join(strings.Split(result.Title, " ")[2:], "_"),
)
seasonNumber := fmt.Sprintf("%02d%02d", result.Date.Year()-2000, result.Date.Month())
episodeNumber := fmt.Sprintf("%02d", result.Date.Day())
season := fmt.Sprintf("Season_%s", seasonNumber)
episode := fmt.Sprintf("Episode_%s_-_%s", episodeNumber, strings.Join(strings.Split(result.Title, " ")[2:], "_"))
target := fmt.Sprintf("%s/%s.%%(ext)s", season, episode)
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
}
os.MkdirAll(path.Dir(target), os.ModePerm)
if err := client.Download(result.Link, target); err != nil {
errs += ", " + err.Error()
}