Compare commits
10 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
53d7c826ef | |
|
|
d256ad7916 | |
|
|
71588dee79 | |
|
|
879ce2c090 | |
|
|
0016e5afa9 | |
|
|
70f0231371 | |
|
|
5ac21eed3a | |
|
|
da38522dc3 | |
|
|
5daa95058d | |
|
|
e4ede9c4e1 |
|
|
@ -6,6 +6,8 @@ WORKDIR /main
|
|||
|
||||
COPY . .
|
||||
|
||||
RUN test -e /main/exec-youtuber
|
||||
|
||||
ENV GOPATH=""
|
||||
ENV MNT="/mnt/"
|
||||
ENTRYPOINT ["/main/exec-youtuber"]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -43,4 +46,5 @@ func init() {
|
|||
POP3: as.Get("pop3").GetString(),
|
||||
Password: as.Get("password").GetString(),
|
||||
}
|
||||
Interval = as.GetDuration("interval")
|
||||
}
|
||||
|
|
|
|||
15
main.go
15
main.go
|
|
@ -18,7 +18,7 @@ func main() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
interval := time.Hour * 4
|
||||
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()
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -3,6 +3,7 @@ package youtubedl
|
|||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
)
|
||||
|
|
@ -15,13 +16,17 @@ func New() (*Client, 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{}
|
||||
for _, extras := range [][]string{
|
||||
[]string{"--add-metadata", "--metadata-from-title", ".*[0-9]/[0-9][0-9] (?P<title>.+)"},
|
||||
[]string{},
|
||||
} {
|
||||
args := append([]string{
|
||||
"youtube-dl",
|
||||
"/tmp/yt-dlp",
|
||||
"-f",
|
||||
"22",
|
||||
"-o",
|
||||
|
|
@ -30,6 +35,7 @@ func (c *Client) Download(video, local string) error {
|
|||
"--write-auto-sub",
|
||||
"--sub-format",
|
||||
"srt",
|
||||
"--no-check-certificate",
|
||||
}, extras...)
|
||||
args = append(args, video)
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
|
|
@ -49,10 +55,11 @@ func (c *Client) Download(video, local string) error {
|
|||
return err
|
||||
}
|
||||
cmd := exec.Command(
|
||||
"bash",
|
||||
"/bin/sh",
|
||||
"-c",
|
||||
fmt.Sprintf(
|
||||
"true; python3 -m vtt_to_srt %q || python3 /usr/bin/vtt_to_srt.py %q",
|
||||
"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),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -2,11 +2,16 @@ package youtubedl
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func install() error {
|
||||
if _, ok := os.LookupEnv("TEST"); ok {
|
||||
return nil
|
||||
}
|
||||
if err := installPyPip3FFMPEG(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -42,22 +47,36 @@ func installPyPip3FFMPEG() error {
|
|||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
log.Println("%v: %v", err, combo)
|
||||
log.Printf("%v: %v", err, combo)
|
||||
}
|
||||
return errors.New("cannot get python3 and pip3 and ffmpeg")
|
||||
}
|
||||
|
||||
func installYtdl() error {
|
||||
cmd := exec.Command("youtube-dl", "--version")
|
||||
cmd := exec.Command("/tmp/yt-dlp", "--version")
|
||||
if err := cmd.Run(); err == nil {
|
||||
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 {
|
||||
cmd = exec.Command("pip3", "install", "youtube-dl")
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
o, _ := cmd.CombinedOutput()
|
||||
return fmt.Errorf("failed wget yt-dlp: %v: %s", err, o)
|
||||
}
|
||||
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue