Skip to content

Instantly share code, notes, and snippets.

@0187773933
Last active July 2, 2020 09:22
Show Gist options
  • Save 0187773933/7cbd948f70a31284cd3a006f709f687e to your computer and use it in GitHub Desktop.
Save 0187773933/7cbd948f70a31284cd3a006f709f687e to your computer and use it in GitHub Desktop.
Casts Twitch or Youtube or anything youtube-dl can Find to Chromecast via npm castnow
#!/bin/bash
# Quick Find Chromecast IP's
# python3 -c 'import pychromecast; print(pychromecast.get_chromecasts())'
# Then ARP Scan to Find Matching MacAddress
# arp -na
MacAddress="f0:ef:86:9:c3:30"
ChromecastIP=$(arp -na | grep -i $MacAddress | tail -1 | awk '{print $2}' | cut -d "(" -f2 | cut -d ")" -f1)
if [ -z "$ChromecastIP" ]; then
echo "arp scan empty"
if [[ "$OSTYPE" == "linux-gnu" ]]; then
DefaultGateway=$(netstat -rn -A inet | grep -A 1 "Gateway" | tail -1 | awk '{print $2}')
elif [[ "$OSTYPE" == "darwin"* ]]; then
DefaultGateway=$(ip route ls | grep default | awk '{print $3}')
fi
echo "Default Gateway = $DefaultGateway"
echo "nmaping Default Gateway ..."
ChromecastIP=$(sudo nmap -sn $DefaultGateway/24 | grep -i '$MacAddress' -B 2 | head -1 | awk '{print $(NF)}')
fi
if [ -z "$ChromecastIP" ]; then
ChromecastIP=$(arp -na | grep -i $MacAddress | tail -1 | awk '{print $2}' | cut -d "(" -f2 | cut -d ")" -f1)
fi
echo "ChromecastIP = $ChromecastIP"
DirectURL=$(youtube-dl --no-warnings -f "best" --no-playlist --get-url $1)
echo $DirectURL
castnow --address $ChromecastIP "$DirectURL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment