49 lines
1.4 KiB
Plaintext
Executable File
49 lines
1.4 KiB
Plaintext
Executable File
#!/mod/bin/jimsh
|
|
|
|
# Queue url for backround download
|
|
package require cgi
|
|
source /mod/webif/lib/setup
|
|
|
|
proc log {msg {level 1}} {
|
|
puts "[\
|
|
clock format [clock seconds] -format "%T"\
|
|
] - $msg"
|
|
flush stdout
|
|
|
|
puts $::qlogfd "[\
|
|
clock format [clock seconds] -format "%T"\
|
|
] - $msg"
|
|
flush $::qlogfd
|
|
}
|
|
|
|
httpheader
|
|
|
|
set logfile "/mod/tmp/qtube.log"
|
|
set ::qlogfd [open $logfile "a+"]
|
|
set url [cgi_get url "http://example.com"]
|
|
set opts [cgi_get opts ""]
|
|
set sess [clock format [clock seconds] -format "qtube%H%M"]
|
|
|
|
log "--------------------------------------------------------------"
|
|
log "Starting immediate download of $url Options $opts"
|
|
log "Be VERY patient - it can take a couple of minutes for download to start!"
|
|
# Fix to cmd invocation thanks to @/df
|
|
# https://hummy.tv/forum/threads/qtube-webif-front-end-for-youtube-dl.8948/page-7#post-139719
|
|
#set cmd [list "abduco" "-n" $sess "youtube" "--newline"]
|
|
set cmd [list "youtube" "--newline"]
|
|
lappend cmd {*}$opts $url
|
|
log $cmd
|
|
log "{*}[lmap e $cmd {concat $e}]"
|
|
if {[catch {exec {*}[lmap e $cmd {concat $e}] \
|
|
| awk {{print strftime("%H:%M:%S -"), $0; fflush(); }} \
|
|
| tee -i -a $logfile \
|
|
>@stdout 2>@1} msg catchopts]
|
|
} {
|
|
log "Caught error: $msg"
|
|
#log "$catchopts"
|
|
} else {
|
|
log "Completed immediate download of $url Options $opts"
|
|
}
|
|
|
|
close $::qlogfd
|