-
-
Save ergoz/9f98bc3e0d99f58d6a807408bee23b5e to your computer and use it in GitHub Desktop.
AppleScript file to download youtube videos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
script to download videos from youtube using the youtube-dl program | |
you can paste this code in a ScriptEditor file or use it inside a | |
'Run AppleScript' block in an Automator Application | |
*) | |
set question to display dialog "Youtube URL to fetch?" default answer "" buttons {"Cancel", "Open in Browser", "Download"} default button 3 | |
set pageURL to (text returned of result) | |
if pageURL is "" then return "No URL" | |
set choice to (button returned of question) | |
set progress total steps to 1 | |
set progress completed steps to 0 | |
set progress description to "Downloading video..." | |
if choice is "Download" then | |
try | |
set pid to do shell script "cd ~/Downloads/youtube/; /usr/local/bin/youtube-dl --newline " & pageURL & " > /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 -n1 /tmp/vidstatus") -- display last line of output | |
set progress completed steps to 0 | |
end repeat | |
on error | |
set progress completed steps to 1 | |
display dialog "Download complete!" -- eh, success, hopefully :) | |
set progress total steps to 0 | |
set progress completed steps to 0 | |
set progress description to "Done!" | |
end try | |
else if choice is "Open in Browser" then | |
try | |
open location pageURL | |
on error | |
display dialog "Cannot open " + pageURL + " !" | |
end try | |
end if | |
return input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment