Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio fix, install dependencies and alternative youtube-dl #18

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions examples/benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ID="Dgxz0kZ2dp4"
TIMEFORMAT='%3R'

[ ! -e "/tmp/gotubecast" ] && {
mkdir "/tmp/gotubecast"
cd "/tmp/gotubecast"
[ ! -e "./youtube-dl" ] && {
wget "https://yt-dl.org/downloads/latest/youtube-dl" -O ./youtube-dl
chmod +x ./youtube-dl
}
[ ! -e "./youtubedr" ] && {
wget "https://github.com/kkdai/youtube/releases/download/v2.3.0/youtube_2.3.0_linux_armv6.tar.gz" -O ./youtubedr.tar.gz
tar xf ./youtubedr.tar.gz
}
} || cd "/tmp/gotubecast"

time { # rpi1: 3.956
function urldecode {
echo -e "$(sed 's/+/ /g;s/%\(..\)/\\x\1/g;')"
}
GET=$(wget -qO- "https://www.youtube.com/get_video_info?html5=1&video_id=$ID")
for s in $(echo $GET | tr "&" "\n")
do
if [ "${s%%=*}" = "player_response" ]; then
YTURL=$(echo ${s:16} | urldecode | jq '.streamingData.formats[-1].url' | tail -c +2 | head -c -2)
fi
done
echo $YTURL;
}
time { # rpi1: 5.069
YTURL=$(./youtubedr url -q hd1080 "https://www.youtube.com/watch?v=$ID")
echo $YTURL;
}
time { # rpi1: 67.614
YTURL=$(./youtube-dl -g -f mp4 "https://www.youtube.com/watch?v=$ID")
echo $YTURL;
}
14 changes: 14 additions & 0 deletions examples/dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# script dependencies raspi.sh

[ $(id -u) -ne 0 ] && {
echo "Please run as root"
exit 1
} || {
[ ! -z `type -p apt` ] && {
[ -z `type -p bc` ] && apt install bc -y
[ -z `type -p omxplayer` ] && apt install omxplayer -y
[ -z `type -p youtube-dl` ] && [ -z `type -p ytdl` ] && [ -z `type -p jq` ] && apt install jq -y
[ ! -z "$ANNOTATE" ] && [ ! -z `type -p nitrogen` ] && [ -e "background.png" ] && [ -z `type -p convert` ] && apt install imagemagick -y
}
}
32 changes: 24 additions & 8 deletions examples/raspi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
# simple YouTube TV for Raspberry Pi
# kills any currently playing video as soon as a new video is queued
# needs youtube-dl (or ytdl) and omxplayer
export SCREEN_ID=""
[ ! -e ".screen_id" ] && wget -O ".screen_id" "https://www.youtube.com/api/lounge/pairing/generate_screen_id"
export SCREEN_ID=$(cat ".screen_id")
export SCREEN_NAME="Raspberry Pi"
export SCREEN_APP="pitubecast-v1"
export OMX_OPTS="-o hdmi"
# http://rg3.github.io/youtube-dl/
export YOUTUBEDL="youtube-dl -g -f mp4 https://www.youtube.com/watch?v="
# https://github.com/rylio/ytdl
export YTDL="ytdl -u "
export EXTRACTOR="$YOUTUBEDL"
export OMX_OPTS="-o both"
# export ANNOTATE="+0+245"
export VOL="1.0"

function omxdbus {
Expand All @@ -20,6 +17,9 @@ function omxdbus {
export DBUS_SESSION_BUS_PID=`cat $OMXPLAYER_DBUS_PID`
dbus-send --print-reply=literal --session --reply-timeout=100 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 $*
}
function urldecode {
echo -e "$(sed 's/+/ /g;s/%\(..\)/\\x\1/g;')"
}

gotubecast -s "$SCREEN_ID" -n "$SCREEN_NAME" -i "$SCREEN_APP" | while read line
do
Expand All @@ -28,13 +28,29 @@ do
case "$cmd" in
pairing_code)
echo "Your pairing code: $arg"
[ ! -z "$ANNOTATE" ] && [ ! -z `type -p nitrogen` ] && [ -e "background.png" ] && {
convert "background.png" -gravity North -pointsize 30 -fill white -annotate "$ANNOTATE" "$arg" "/tmp/code.png"
sudo nitrogen --set-centered "/tmp/code.png"
}
;;
remote_join)
cut -d ' ' -f3- <<< "$line connected"
;;
video_id)
YTURL="`$EXTRACTOR$arg`"
killall omxplayer.bin
[ ! -z `type -p youtube-dl` ] && { # http://rg3.github.io/youtube-dl/
YTURL="`youtube-dl -g -f mp4 https://www.youtube.com/watch?v=$arg`"
} || [ ! -z `type -p ytdl` ] && { # https://github.com/rylio/ytdl
YTURL="`ytdl -u $arg`"
} || {
GET=$(wget -qO- "https://www.youtube.com/get_video_info?html5=1&video_id=$arg")
for s in $(echo $GET | tr "&" "\n")
do
if [ "${s%%=*}" = "player_response" ]; then
YTURL=$(echo ${s:16} | urldecode | jq '.streamingData.formats[-1].url' | tail -c +2 | head -c -2)
fi
done
}
vol=(`log=$(echo "l($VOL)/l(10)" | bc -l); val=$(echo "$log * 2000" | bc); echo ${val%.*}`)
omxplayer $OMX_OPTS --vol $vol "$YTURL" </dev/null &
;;
Expand Down