Last active
August 29, 2015 14:13
-
-
Save colby/6da28731f31802e973f8 to your computer and use it in GitHub Desktop.
A bash script to find the first HD video that matches the current Rdio song playing.
This file contains 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
#!/usr/bin/env bash | |
if ! pgrep -q Rdio | |
then | |
echo "Error: Rdio is not running"; exit 1 | |
fi | |
function check { | |
which "$1" || echo "Missing dep: $1"; exit 1 | |
} | |
# check deps | |
CUT=$(check cut) | |
SED=$(check sed) | |
GREP=$(check grep) | |
CURL=$(check curl) | |
RDIO=$(check rdio) | |
CURRENT=$($RDIO current | $CUT -d: -f2-) | |
ARTIST=$(echo "$CURRENT" | $CUT -d'/' -f2) | |
SONG=$(echo "$CURRENT" | $CUT -d'/' -f1) | |
YOUTUBE="https://www.youtube.com" | |
LINK="$YOUTUBE/results?search_query=" | |
URI=$(echo "$ARTIST-$SONG, hd" | $SED -r 's/ /+/g') | |
SEARCH=$($CURL -s "$LINK$URI" | $GREP -o 'href=\"/watch?v=.*\"' -m1 | $CUT -d'"' -f2) | |
open -a "/Applications/Google Chrome.app" "$YOUTUBE$SEARCH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment