Created
December 15, 2015 17:07
-
-
Save marcotrosi/ec4fa686682745d5021d to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# extend PATH variable; dirty workaround for the audio extraction feature which requires ffmpeg | |
PATH=$PATH:/usr/local/bin | |
# save tool paths in variables | |
CocoaDialog='/Applications/cocoaDialog.app/Contents/MacOS/cocoaDialog' | |
YoutubeDL='/usr/local/bin/youtube-dl' | |
# get clipboard content | |
Clipboard=$(pbpaste) | |
# run cocoaDialog | |
# the Return variable contains the selected button string (Cancel,Audio,Video) and the textbox string (URL) in case of Audio and Video | |
# e.g. "Audio https://www.youtube.com/watch?v=PZeU7S2xKpA" | |
Return=`$CocoaDialog inputbox --string-output --no-newline --float --title "YoutubeDL" --informative-text "VideoURL" --text "$Clipboard" --button1 "Video" --button2 "Audio" --button3 "Cancel"` | |
# check if aborted | |
if [ ${Return:0:6} == "Cancel" ]; then | |
exit 0; | |
fi | |
# split Return variable into Audio/Video and URL | |
Type=${Return:0:5} | |
URL=${Return:6} | |
# create audio extraction flag | |
if [ $Type == "Audio" ]; then | |
ExtractAudio="-x"; | |
else | |
ExtractAudio=""; | |
fi | |
# run youtube-dl | |
$YoutubeDL ${ExtractAudio} -o "/Users/${USER}/Downloads/%(title)s.%(ext)s" $URL | |
# create info bubble | |
if [ $? -eq 0 ]; then | |
$CocoaDialog bubble --timeout 3 --title "YoutubeDL" --text "Download Successful"; | |
else | |
$CocoaDialog bubble --timeout 3 --title "YoutubeDL" --text "Download Failed"; | |
fi | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment