2

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?

  • The PATH passed to a do 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 or export PATH; other_commands where PATH in export PATH; ... is the actual path you want passed. – user3439894 Mar 6 at 0:45
  • It would really improve this to display progress bar instead of a repeat statement and also a notification with an option to "open" the downloaded file. – John Mar 6 at 2:00
2

I did some more digging and found I needed to add the location of ffmpeg binary in the "do shell script" call by adding: --ffmpeg-location /usr/local/bin/ffmpeg

on run {input, parameters}
    try
        tell application "System Events"
            set pid to do shell script "cd /tmp/; /usr/local/bin/youtube-dl  --newline --ffmpeg-location /usr/local/bin/ffmpeg " & 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
                delay 5
            end repeat
        end tell
    on error
        display notification "YouTube Download Finished" -- show error message
    end try
end run
| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .