update july 6, 2015: no need for noodlesoft's hazel anymore--to set it up using folder actions, look here: os x: automatically move files using folder actions.
hey, here's a great video. you have to see it!
but what if i can’t or don't want to watch it right now? i can send the link to my own email address; or i can save it to my reading list; or i can copy the link to my notes app. oh boy, what a hassle.
here is what i do now
from any device i currently use, i just send the link to a special email address. once i am in from of my mac, the video popups up on my desktop.
and here is how
if you want to do the same, you need:
- your own vps, i.e. uberspace
- homebrew
- youtube-dl
- bittorrent sync (btsync)
- hazel (os x only) *not necessary anymore*
- email address for incoming video urls
- script running on your server
in this how to article, i assume, all the listed requirements are in place.
uberspace
register at uberspace (or your favorite provider) and log in via ssh.
homebrew
please read the article about homebrew in the uberspace-wiki and install it:
$ git clone https://github.com/Homebrew/linuxbrew.git ~/.linuxbrew
$ echo "PATH=\"$HOME/.linuxbrew/bin:$PATH\"" >> ~/.bashrc
$ echo "MANPATH=\"$HOME/.linuxbrew/share/man:$MANPATH\"" >> ~/.bashrc
$ echo "INFOPATH=\"$HOME/.linuxbrew/share/info:$INFOPATH\"" >> ~/.bashrc
$ source ~/.bashrc
youtube-dl
install youtube-dl:
$ brew install youtube-dl
bittorrent sync
install and set up bittorrent sync on uberspace and download the app to your computer.
please create a folder for transferring the downloaded video files. mine is ´recorder´, saved inside my uberspace in this path:
~/BTSync/storage/recorder
link the folder to a local folder on your mac. (my local path is ~/Public/BTSync/recorder
)
please untick the checkbox store deleted files in folder archive
(on both the server and your local app):
hazel
before reading on, read this: os x: automatically move files using folder actions
get hazel; after successful installation, open it’s .prefpane
in system preferences. create a new rule to move all, but .bts
files to your desktop.
please note: files currently transferred using btsync have the extension .bts
.
email address for incoming video urls
understand what's written about vmailmgr here, then setup vmailmgr:
$ vsetup
vsetup: created users directory.
vsetup: wrote '.qmail-default' file.
and create a new user/email account:
$ vadduser youtube-dl
Enter the user's new password:
…
vadduser: user 'youtube-dl' successfully added
script running on your server
create folder for the script (if it doesn't exist)
$ mkdir ~/bin
now, connect all the parts to a full featured workflow by creating the script:
$ touch ~/recorder.sh
$ chmod +x ~/bin/recorder.sh
$ nano ~/bin/recorder.sh
copy & paste this:
#!/bin/bash
### Change for your needs:
# MAILADDRESS - E-Mail address, youtube-dl will use to send mails
MAILADDRESS="youtube-dl@yourdomain.tld"
# MAILDIR - Folder which contains incoming Mails
MAILDIR="/home/YOURACCOUNTNAME/users/youtube-dl/new/"
# OUTDIR - Folder to put downloaded video in
OUTDIR="/home/YOURACCOUNTNAME/BTSync/storage/recorder/"
# TOMAILADDRESS - E-Mail address, this script will send a confirmation to
MAILADDRESS="you@yourdomain.tld"
# YOUTUBEDLPATH - Path to youtube-dl
YOUTUBEDLPATH="/home/YOURACCOUNTNAME/.linuxbrew/bin/youtube-dl"
### No Editing below this line
# URL Encode Function
rawurlencode() {
local string="${1}"
local strlen=${#string}
local encoded=""
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* )
printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}"
}
# Get E-Mails
READMAILS=`ls $MAILDIR`
# Iterate through mails
for MAIL in $READMAILS
do
# Check if mail is being processed
FILE="${MAILDIR}${MAIL}.inprogress"
if [ -f $FILE ]; then
# File exists
# do nothing
sleep 0
else
# File does not exist
# set "in progress"
touch "${MAILDIR}${MAIL}.inprogress"
# Get Variables
while read LINE
do
case $LINE in
# Get E-Mail of Sender
"From:"*)
SENDER=${LINE}
SENDER=${SENDER#*<}
SENDER=${SENDER%>*}
;;
# Get Subject (contains URL)
"Subject:"*)
URL=${LINE/"Subject:"/""}
;;
esac
done < $MAILDIR$MAIL
# Use youtube-dl to download video file and save output (to extract file name)
OUTPUT="$(${YOUTUBEDLPATH} -o "$OUTDIR%(title)s.%(ext)s" $URL)"
# Send E-Mail
# Subject
SUBJECT="New Video from $SENDER"
# Message
MESSAGE="<html><body><p>You received a new video:<br /><a href=\"$URL\">$URL</a></p><p>$SENDER</p></body></html>"
# Sending E-Mail
(
echo "From: ${MAILADDRESS}";
echo "To: ${TOMAILADDRESS}";
echo "Subject: ${SUBJECT}";
echo "Content-Type: text/html";
echo "MIME-Version: 1.0";
echo "";
echo "${MESSAGE}";
) | /usr/sbin/sendmail -t
# Remove E-Mail from Inbox
rm ${MAILDIR}${MAIL}
rm "${MAILDIR}${MAIL}.inprogress"
fi
done
save the file and close nano with these shortcuts:
- [ctrl] + [o]
- enter
- [ctrl] + [x]
create a cronjob
finally, set up a cronjob to check for new videos:
$ crontab -e
add these two lines:
# download videos using youtube-dl
*/4 * * * * ~/bin/youtube-dl.sh
save & close the editor. you should see this line:
crontab: installing new crontab
done.
now create a new email, put the video's url as subject and send it to your youtube-dl's email address (youtube-dl@yourdomain.tld) . after no more than four minutes, the script should be triggered, and another few seconds/minutes later (depending on video size and your internet connection), you should see a new video file popping up on your computer.