I built an AppleScript to run as a Service for Safari. But I am running into a problem where the audio and video aren't being muxed. This doesn't happen when entering the same command into terminal.
I have a configuration file for youtube-dl:
-f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]'
-o '/Volumes/Godzilla/Video/YouTube Video/%(title)s-%(id)s.%(ext)s'
This is the automator script which uses the current Safari URL as input:
on run {input, parameters}
try
do shell script "/usr/local/bin/youtube-dl " & input
(display notification input with title "YouTube Video Downloaded") beep
delay 1 --> avoid quit before notice
on error
display notification "YouTube Download Failed" -- show error message
end try
end run
EDIT: OK, I have requested the audio file in the config the question is why are the files not being merged after AppleScript runs youtube-dl?
I changed my AppleScript to this which provided some details to the issue:
on run {input, parameters}
try
tell application "System Events"
set pid to do shell script "cd /tmp/; /usr/local/bin/youtube-dl --newline " & input & " > /tmp/vidstatus 2>&1 & echo $!"
delay 1
repeat while ((do shell script "kill -0 " & pid) is "") -- check if pid is still responding
display dialog "Status: " & (do shell script "tail -n 1 /tmp/vidstatus") -- display last line of output
end repeat
end tell
on error
display notification "YouTube Download Failed" -- show error message
end try end run
This is the message I get from Status:
Status: [youtube] IrxpSFtGX1k: Downloading webpage [youtube] IrxpSFtGX1k: Downloading video info webpage WARNING: You have requested multiple formats but ffmpeg or avconv are not installed. The formats won't be merged.
This is odd because they are obviously installed. The same request is working from terminal. I am testing this script from within Automator—could this be the issue?
PATH
passed to ado shell script
command in a Run Shell Script action is/usr/bin:/bin:/usr/sbin:/sbin
and if anything else you're running requires something outside of that path you'll need to make allowances for it. Use fully qualified pathnames and orexport PATH; other_commands
wherePATH
inexport PATH; ...
is the actual path you want passed.