Compare commits

...

12 Commits
v0.3 ... master

Author SHA1 Message Date
Bel LaPointe 53d7c826ef youtube-dl to yt-dlp 2021-08-23 17:30:07 -04:00
Bel LaPointe d256ad7916 test via manual and $TEST 2021-05-14 09:32:41 -04:00
Bel LaPointe 71588dee79 whoops 2021-01-25 09:00:38 -06:00
Bel LaPointe 879ce2c090 invoke vtt to srt as dedicated binary 2021-01-25 08:56:50 -06:00
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
Bel LaPointe da38522dc3 from bash to sh 2021-01-03 20:46:23 -05:00
bel 5daa95058d more often and fix bash 2020-12-14 22:09:21 -07:00
bel e4ede9c4e1 Fix install cmd 2020-12-08 07:50:11 -07:00
bel c98a50c5ab Use new vtt to srt of needed 2020-12-08 07:47:10 -07:00
bel eba8001ca0 Whoops I lost this repo and scraped from docker image 2020-12-08 07:43:50 -07:00
7 changed files with 74 additions and 32 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
ytubeSpdrun ytubeSpdrun
**/*.sw* **/*.sw*
exec-*
youtuber youtuber

View File

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

View File

@ -4,14 +4,16 @@ import (
"local/args" "local/args"
"local/sandbox/contact/contact" "local/sandbox/contact/contact"
"os" "os"
"time"
) )
var ( var (
Feed string Feed string
Root string Root string
To string To string
Subject string Subject string
Emailer *contact.Emailer Emailer *contact.Emailer
Interval time.Duration
) )
func init() { 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, "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.STRING, "root", "root to save videos", "/tmp")
as.Append(args.DURATION, "interval", "check interval", time.Hour)
if err := as.Parse(); err != nil { if err := as.Parse(); err != nil {
panic(err) panic(err)
@ -43,4 +46,5 @@ func init() {
POP3: as.Get("pop3").GetString(), POP3: as.Get("pop3").GetString(),
Password: as.Get("password").GetString(), Password: as.Get("password").GetString(),
} }
Interval = as.GetDuration("interval")
} }

15
main.go
View File

@ -18,7 +18,7 @@ func main() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
interval := time.Hour * 4 interval := config.Interval
for true { for true {
err := do(client) err := do(client)
if err != nil { if err != nil {
@ -45,18 +45,17 @@ func do(client *youtubedl.Client) error {
} }
for _, result := range results { for _, result := range results {
target := fmt.Sprintf( seasonNumber := fmt.Sprintf("%02d%02d", result.Date.Year()-2000, result.Date.Month())
"s%02d%02de%02d_%s.%%(ext)s", episodeNumber := fmt.Sprintf("%02d", result.Date.Day())
result.Date.Year()-2000, season := fmt.Sprintf("Season_%s", seasonNumber)
result.Date.Month(), episode := fmt.Sprintf("Episode_%s_-_%s", episodeNumber, strings.Join(strings.Split(result.Title, " ")[2:], "_"))
result.Date.Day(), target := fmt.Sprintf("%s/%s.%%(ext)s", season, episode)
strings.Join(strings.Split(result.Title, " ")[2:], "_"),
)
target = path.Join(config.Root, target) target = path.Join(config.Root, target)
if _, err := os.Stat(strings.ReplaceAll(target, "%(ext)s", "mp4")); !os.IsNotExist(err) { if _, err := os.Stat(strings.ReplaceAll(target, "%(ext)s", "mp4")); !os.IsNotExist(err) {
log.Printf("already exists: %s", target) log.Printf("already exists: %s", target)
continue continue
} }
os.MkdirAll(path.Dir(target), os.ModePerm)
if err := client.Download(result.Link, target); err != nil { if err := client.Download(result.Link, target); err != nil {
errs += ", " + err.Error() errs += ", " + err.Error()
} }

BIN
youtubedl/.client.go.un~ Normal file

Binary file not shown.

View File

@ -3,6 +3,7 @@ package youtubedl
import ( import (
"fmt" "fmt"
"log" "log"
"os"
"os/exec" "os/exec"
"path" "path"
) )
@ -15,13 +16,17 @@ func New() (*Client, error) {
} }
func (c *Client) Download(video, local string) error { func (c *Client) Download(video, local string) error {
if _, ok := os.LookupEnv("TEST"); ok {
log.Println("youtube-dl download", video, local)
return nil
}
errs := []error{} errs := []error{}
for _, extras := range [][]string{ for _, extras := range [][]string{
[]string{"--metadata-from-title", ".*[0-9]/[0-9][0-9] (?P<title>.+)"}, []string{"--add-metadata", "--metadata-from-title", ".*[0-9]/[0-9][0-9] (?P<title>.+)"},
[]string{}, []string{},
} { } {
args := append([]string{ args := append([]string{
"youtube-dl", "/tmp/yt-dlp",
"-f", "-f",
"22", "22",
"-o", "-o",
@ -30,6 +35,7 @@ func (c *Client) Download(video, local string) error {
"--write-auto-sub", "--write-auto-sub",
"--sub-format", "--sub-format",
"srt", "srt",
"--no-check-certificate",
}, extras...) }, extras...)
args = append(args, video) args = append(args, video)
cmd := exec.Command(args[0], args[1:]...) cmd := exec.Command(args[0], args[1:]...)
@ -48,7 +54,16 @@ func (c *Client) Download(video, local string) error {
err := fmt.Errorf("%v", errs) err := fmt.Errorf("%v", errs)
return err return err
} }
cmd := exec.Command("python3", "-m", "vtt_to_srt", path.Dir(local)) cmd := exec.Command(
"/bin/sh",
"-c",
fmt.Sprintf(
"true; python3 -m vtt_to_srt %q || python3 /usr/bin/vtt_to_srt.py %q || vtt_to_srt %q",
path.Dir(local),
path.Dir(local),
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)

View File

@ -2,12 +2,17 @@ package youtubedl
import ( import (
"errors" "errors"
"fmt"
"log" "log"
"os"
"os/exec" "os/exec"
) )
func install() error { func install() error {
if err := installPyPip3(); err != nil { if _, ok := os.LookupEnv("TEST"); ok {
return nil
}
if err := installPyPip3FFMPEG(); err != nil {
return err return err
} }
if err := installYtdl(); err != nil { if err := installYtdl(); err != nil {
@ -19,43 +24,59 @@ 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"}, []string{"/sbin/apk", "add", "python3", "py3-pip", "ffmpeg"},
[]string{"sudo", "/sbin/apk", "add", "python3", "py3-pip"}, []string{"sudo", "/sbin/apk", "add", "python3", "py3-pip", "ffmpeg"},
} { } {
cmd := exec.Command(combo[0], combo[1:]...) cmd := exec.Command(combo[0], combo[1:]...)
err := cmd.Run() err := cmd.Run()
if err == nil { if err == nil {
return nil return nil
} }
log.Println("%v: %v", err, combo) log.Printf("%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 {
cmd := exec.Command("youtube-dl", "--version") cmd := exec.Command("/tmp/yt-dlp", "--version")
if err := cmd.Run(); err == nil { if err := cmd.Run(); err == nil {
return err return err
} }
cmd = exec.Command("sudo", "pip3", "install", "youtube-dl") os.Remove("/tmp/yt-dlp")
cmd = exec.Command(
"wget",
"https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp",
"--no-check-certificate",
"-O",
"/tmp/yt-dlp",
)
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
cmd = exec.Command("pip3", "install", "youtube-dl") o, _ := cmd.CombinedOutput()
if err := cmd.Run(); err != nil { return fmt.Errorf("failed wget yt-dlp: %v: %s", err, o)
return err }
} cmd = exec.Command(
"chmod",
"a+rx",
"/tmp/yt-dlp",
)
if err := cmd.Run(); err != nil {
o, _ := cmd.CombinedOutput()
return fmt.Errorf("failed chmod yt-dlp: %v: %s", err, o)
} }
return nil return nil
} }