Remove timeout kill
This commit is contained in:
24
download.go
24
download.go
@@ -8,13 +8,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/kkdai/youtube/v2"
|
"github.com/kkdai/youtube/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const OUTPUT_DIR = "C:/Users/Administrator/ytdlpVideos"
|
const OUTPUT_DIR = "C:/Users/Administrator/ytdlpVideos"
|
||||||
const STUCK_TIMEOUT = time.Duration(60)*time.Second
|
|
||||||
|
|
||||||
func DownloadNative(event PBEvent, status chan error) {
|
func DownloadNative(event PBEvent, status chan error) {
|
||||||
log.Printf("%s: Downloading %s", event.Record.Id, event.Record.Link)
|
log.Printf("%s: Downloading %s", event.Record.Id, event.Record.Link)
|
||||||
@@ -61,12 +59,12 @@ func DownloadNative(event PBEvent, status chan error) {
|
|||||||
|
|
||||||
func Download(event PBEvent, status chan error) {
|
func Download(event PBEvent, status chan error) {
|
||||||
cmd := exec.Command("yt-dlp",
|
cmd := exec.Command("yt-dlp",
|
||||||
"-v",
|
|
||||||
"--mark-watched",
|
"--mark-watched",
|
||||||
"--color", "never",
|
"--color", "never",
|
||||||
"-r", "50M",
|
"-r", "50M",
|
||||||
"--http-chunk-size", "20M",
|
"--http-chunk-size", "20M",
|
||||||
"-o", "C:/Users/Administrator/ytdlpVideos/%(title)s.%(ext)s",
|
"-N", "4",
|
||||||
|
"-o", "C:/Users/Administrator/ytdlpVideos/%(uploader)s/%(title)s.%(ext)s",
|
||||||
"-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]",
|
"-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]",
|
||||||
event.Record.Link)
|
event.Record.Link)
|
||||||
|
|
||||||
@@ -92,11 +90,9 @@ func Download(event PBEvent, status chan error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
lastMessage := time.Now()
|
|
||||||
stdoutScanner := bufio.NewScanner(stdout)
|
stdoutScanner := bufio.NewScanner(stdout)
|
||||||
go func() {
|
go func() {
|
||||||
for stdoutScanner.Scan() {
|
for stdoutScanner.Scan() {
|
||||||
lastMessage = time.Now()
|
|
||||||
log.Printf("%s: %s", event.Record.Id, stdoutScanner.Text())
|
log.Printf("%s: %s", event.Record.Id, stdoutScanner.Text())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
@@ -104,26 +100,10 @@ func Download(event PBEvent, status chan error) {
|
|||||||
stderrScanner := bufio.NewScanner(stderr)
|
stderrScanner := bufio.NewScanner(stderr)
|
||||||
go func() {
|
go func() {
|
||||||
for stderrScanner.Scan() {
|
for stderrScanner.Scan() {
|
||||||
lastMessage = time.Now()
|
|
||||||
log.Printf("%s: %s", event.Record.Id, stderrScanner.Text())
|
log.Printf("%s: %s", event.Record.Id, stderrScanner.Text())
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
if time.Since(lastMessage) > STUCK_TIMEOUT {
|
|
||||||
log.Printf("Command timed out, killing process")
|
|
||||||
err := cmd.Process.Kill()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error killing process: %v", err)
|
|
||||||
}
|
|
||||||
status <- fmt.Errorf("command timed out")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
err = cmd.Wait()
|
err = cmd.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
exitError, ok := err.(*exec.ExitError)
|
exitError, ok := err.(*exec.ExitError)
|
||||||
|
Reference in New Issue
Block a user