Last active
May 22, 2024 20:06
-
-
Save sullrich/69b6e28d377b91b36df875680307c09f to your computer and use it in GitHub Desktop.
tmm1/androidhdmi-for-channels hulu tuner script
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 | |
# | |
# bmitune110.sh | |
# This script is used with https://github.com/tmm1/androidhdmi-for-channels/blob/main/main.go | |
# | |
touch /tmp/bmitune110.lock | |
echo "$1" > /tmp/bmitune110.playing | |
rmlock() { | |
rm /tmp/bmitune110.lock | |
} | |
adb_connect() { | |
adb -s 10.0.250.154 disconnect | |
echo ">>> Connecting ADB to 10.0.250.154:5555" | |
local -i adbcounter=0 | |
sleep 1 | |
while true; do | |
adbstatus=$(adb connect 10.0.250.154) | |
if [[ $adbstatus == *"connected"* ]]; then | |
break | |
fi | |
if [[ $adbstatus == "adb: device offline" ]]; then | |
echo "!!! Error with adb" | |
rm /tmp/bmitune110.lock | |
exit 1 | |
fi | |
if ((adbcounter > 25)); then | |
echo "!!! Could not connect via ADB to 10.0.250.154:5555" | |
rm /tmp/bmitune110.lock | |
exit 1 | |
fi | |
sleep 1 | |
((adbcounter++)) | |
done | |
} | |
adb_connect | |
content_file="/Users/sullrich/androidhdmi-for-channels/hulu_contentid.txt" | |
content_id="" | |
# Read content_id from file | |
if [ -f "$content_file" ]; then | |
content_id=$(grep -w "^$1" "$content_file" | cut -d " " -f 2) | |
fi | |
# Check if content_id is empty | |
if [ -z "$content_id" ]; then | |
echo "Invalid option or content_id not found in $content_file" | |
rm /tmp/bmitune110.lock | |
exit 1 | |
fi | |
echo ">>> Sending HULU launch command" | |
adb -s 10.0.250.154 shell monkey -p com.hulu.plus -c android.intent.category.LAUNCHER 1 | |
sleep 2 | |
echo ">>> Sending media intent for $content_id" | |
adb -s 10.0.250.154 shell am start -a android.intent.action.VIEW -d https://www.hulu.com/watch/$content_id | |
declare -i counter=0 | |
declare -i failsafe=0 | |
declare -i giveup=0 | |
status="notplaying" | |
/bin/echo -n ">>> Waiting for stream to start..." | |
while [ "$status" == "notplaying" ]; do | |
sleep 1 | |
ms=$(adb -s 10.0.250.154 shell dumpsys media_session | grep "state=PlaybackState {state=3" | wc -l) | |
if ((ms > 0)); then | |
status="playing" | |
echo "" | |
echo ">>> Stream $content_id has started." | |
else | |
/bin/echo -n "." | |
if ((counter > 15)); then | |
((failsafe++)) | |
/bin/echo "" | |
/bin/echo ">>> Stream timeout. Sending intent again ($failsafe)." | |
adb -s 10.0.250.154 shell am start -a android.intent.action.VIEW -d https://www.hulu.com/watch/$content_id | |
counter=0 | |
fi | |
if ((failsafe > 2)); then | |
/bin/echo "" | |
/bin/echo "!!! Could not stream $content_id." | |
/bin/echo -n "!!! Issuing reboot." | |
adb -s 10.0.250.154 shell reboot | |
declare -i rebootcounter=0 | |
while true; do | |
if ((rebootcounter > 35)); then | |
echo | |
break | |
fi | |
/bin/echo -n "." | |
((rebootcounter++)) | |
sleep 3 | |
done | |
adb_connect | |
declare -i counter=0 | |
declare -i failsafe=0 | |
((giveup++)) | |
fi | |
if ((giveup > 2)); then | |
/bin/echo -n ">>> Cannot stream after rebooting Android device. Giving up." | |
rm /tmp/bmitune110.lock | |
exit 1 | |
fi | |
((counter++)) | |
fi | |
done | |
rm /tmp/bmitune110.lock |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment