#!/bin/bash #------------------------------------------------------------------------------------------------------------------- # CopyRight Shorewall a.k.a. Kowalsky :D shorewall@mail.com # # RaiNix is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # #---------------------------------------------------------------------------------------------------------------------------------------- # RAI films player by Shorewall (Still in Alpha state, but working) # From an idea of Lucaucca, which wrote the origina raiFilm.php script # #---------------------------------------------------------------------------------------------------------------------------------------- # Set here your user preferences #--------------------------------------------------------------------------------------------------------------------------------------- Ua="Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" #--------------------------------------------------------------------------------------------------------------------------------------- ScriptHome="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" LogHome="$ScriptHome" Me=$(basename $0) Version="0.3 Beta" Codename="'Aurora C.'" echo -ne "\033]30;$Me\007" Savedir="/tmp/${Me}_Recording" mkdir -p "$Savedir" 2>/dev/null #--------------------------------------------------------------------------------------------------------------------------------------- PlayersList="mpv livestreamer ffplay vlc" # Set your player order preference for Player in $PlayersList; do if [ -n "`which $Player 2>/dev/null`" ]; then break fi done #--------------------------------------------------------------------------------------------------------------------------------------- FFplayOpt="-infbuf -framedrop -vf scale=1280:768" MpvOpt="--demuxer-thread=yes --demuxer-readahead-secs=30 --hls-bitrate=max" LsOpt="--yes-run-as-root" LsQual='best' LsPlayer='mpv' Autofit="--autofit=800x600" Recorder='livestreamer' # livestreamer or ffmpeg #--------------------------------------------------------------------------------------------------------------------------------------- CookieJar="/tmp/Cookies.txt" Curl="curl -s -L -b $CookieJar -c $CookieJar --max-time 10" Hold="-iconic" #-------------------------------------------------------------------------------------- ShowInfo () { let MsgLen=${#BoxMsg}+6 let TitLen=${#BoxTitle}+6 if [ "$TitLen" -gt "$MsgLen" ]; then MsgLen="$TitLen" fi dialog --title "$BoxTitle" --infobox "$BoxMsg" 5 $MsgLen } #-------------------------------------------------------------------------------------------------------------------------------------- function GetLink () { BoxMsg="Retrieving $MovieName info" BoxTitle="$Me $Version $Codename" ShowInfo if [ "$Profile" = "Test" ]; then set -x fi MoviePageUrl=$($Curl -A "$Ua" "$Home$MovieHome" | grep -o 'singleVodUrl.*' | grep -o 'href=".*' | cut -d '"' -f2) # MoviePageUrl=$(echo "$MovieData" | grep 'raiplay/video' | grep -o 'href.*' | cut -d '"' -f2 | grep -v json) VideoUrl=$($Curl -A "$Ua" "$Home$MoviePageUrl" | grep -o '"contentUrl".*' | cut -d '"' -f4) PlayLink } #---------------------------------------------------------------------------------------------------------------------------------------------------------- function PlayLink () { VideoLink=$(echo "$VideoUrl" | tr -d "'}\\\\" | tr -d '"\\' | grep -o 'http../.*' | cut -d ',' -f-1) if [ "$VideoLink" = "" ]; then clear BoxMsg="Sorry, $MovieName is currently unavailable. Try another movie" BoxTitle="$Me $Version $Codename" ShowInfo read < /dev/tty return fi Code404=$($Curl -A "$Ua" --max-time 5 "$VideoLink" | grep EXTM3U) if [ "$Code404" = "" ]; then clear BoxMsg="Sorry, $MovieName is currently unavailable. Try another movie" BoxTitle="$Me $Version $Codename" ShowInfo read < /dev/tty return fi Chan=$(echo "$MovieName" | tr -s ' ' | tr "'" '_') if [ "$Download" = "1" ]; then Chan=$(echo "$Chan" | tr ' ' '_') if ! [ -z "`which ffmpeg 2>/dev/null`" ] && [ "$Recorder" = "ffmpeg" ] ; then Cmd="ffmpeg -user-agent '"$Ua"' -y -i '"$VideoLink"' -vcodec copy -acodec copy $Savedir/$Chan.avi" echo `date` "$Cmd " >> $LogHome/$Me.log xterm -T "$Me by Shorewall" $Hold -e "$Cmd" & BoxMsg="$MovieName is going to be recorded into $Savedir/$Chan.avi by FFmpeg" BoxTitle="$Me $Version $Codename" ShowInfo sleep 3 Download=0 return fi if ! [ -z "`which livestreamer 2>/dev/null`" ] && [ "$Recorder" = "livestreamer" ]; then Cmd="livestreamer --yes-run-as-root --player $LsPlayer -f -o $Savedir/${Chan}.avi 'hlsvariant://$VideoLink' best" echo `date` "$Cmd " >> $LogHome/$Me.log xterm -T "$Me by Shorewall" $Hold -e "$Cmd" & BoxMsg="$MovieName is going to be recorded into $Savedir/$Chan.avi by Livestreamer" BoxTitle="$Me $Version $Codename" ShowInfo sleep 3 Download=0 return fi BoxMsg="Sorry, no FFmpeg nor Livestreamer are installed. The recording function is not available for $Chan" BoxTitle="$Me $Version $Codename" ShowInfo sleep 3 return fi kill $! 2>/dev/null wait $! 2>/dev/null Chan=$(echo "$MovieName" | tr -s ' ' | tr "'" '"') if [ "$Player" = "mpv" ]; then Cmd="mpv $MpvOpt --title='"$Chan"' $Autofit '"$VideoLink"'" echo `date` "$Cmd " >> $LogHome/$Me.log xterm -T "$Me by Shorewall" $Hold -e "$Cmd" & BoxMsg="$MovieName is going to be played using $Player" BoxTitle="$Me $Version $Codename" ShowInfo sleep 3 return fi if [ "$Player" = "livestreamer" ]; then Cmd="livestreamer $LsOpt --player 'mpv --title=$Chan $Autofit' 'hlsvariant://$VideoLink' $LsQual" echo `date` "$Cmd " >> $LogHome/$Me.log xterm -T "$Me by Shorewall" $Hold -e "$Cmd" & BoxMsg="$MovieName is going to be played using $Player" BoxTitle="$Me $Version $Codename" ShowInfo sleep 3 return fi if [ "$Player" = "ffplay" ]; then Cmd="ffplay $FFplayOpt -window_title "$Chan" "$VideoLink"" echo `date` "$Cmd " >> $LogHome/$Me.log xterm -T "$Me by Shorewall" $Hold -e "$Cmd" & BoxMsg="$MovieName is going to be played using $Player" BoxTitle="$Me $Version $Codename" ShowInfo sleep 3 fi if [ "$Player" = "vlc" ]; then Cmd="vlc --meta-title "$Chan" "$VideoLink"" echo `date` "$Cmd " >> $LogHome/$Me.log xterm -T "$Me by Shorewall" $Hold -e "$Cmd" & BoxMsg="$MovieName is going to be played using $Player" BoxTitle="$Me $Version $Codename" ShowInfo sleep 2 fi } #------------------------------------------------------------------------------------------------- CatMovies () { clear BoxMsg="Retrieving movies list for $CatName" BoxTitle="$Me $Version $Codename" ShowInfo CatContent=$($Curl -A "$Ua" "$Home$CatLink" | grep -Ei 'titolo|data-path') ThisCatTitles=$(echo "$CatContent" | grep -o "titolo.*" | cut -d '>' -f2 | cut -d '<' -f1 | sed -e "s|ø|ø|g" -e "s|é|é|g" -e "s|ò|ò|g" -e "s|ù|ù|g" -e "s|'|'|g" -e "s|à|à|g" -e "s|è|è|g") ThisCatLinks=$(echo "$CatContent" | grep -o "data-path.*" | cut -d '"' -f2) unset CatContentMenu Index=0 while read MovieTitle; do let Index++ CatContentMenu=("${CatContentMenu[@]}" $Index "$MovieTitle" ) done <<< "$ThisCatTitles" DefChan="" while [ 1 ]; do REPLY=$(dialog --title "$Me $Version $Codename" --default-item "$DefChan" --ok-label 'Play' --cancel-label 'Go Back' --extra-button --extra-label 'Record' --stdout --menu "Available movies for $CatName: $Index" 22 60 15 "${CatContentMenu[@]}") Button="$?" if [ "$Button" = "3" ]; then Download=1 fi if ! [ "$REPLY" -eq "$REPLY" ] 2>/dev/null; then return fi DefChan="$REPLY" let ChanPos=$REPLY*2-1 MovieName="${CatContentMenu[$ChanPos]}" MovieHome=$(echo "$ThisCatLinks" | sed -n ${REPLY}p) GetLink done } #--------------------------------------------------------------------------------------------------------------------------------------------------------------- # Here online code start #-------------------------------------------------------------------------------------------------------------------------------------------------------------- Home="http://www.raiplay.it" BoxMsg="Retrieving movies categories" BoxTitle="$Me $Version $Codename" ShowInfo sleep 1 CatPage=$($Curl -L -A "$Ua" "$Home/film/" | grep -E 'genere|Tutti|"lazy"') CatNames=$(echo "$CatPage" | grep '"lazy"' | grep -v 'Una Stella' | grep -o "title=.*" | cut -d '"' -f2 | sed -e 's|\&|\&|g') # | tr ' ' '_') CatLinks=$(echo "$CatPage" | grep -v 'Una.Stella' | grep -o "href=.*" | cut -d '"' -f2) Index=0 while read Cat; do let Index++ CatMenu=("${CatMenu[@]}" $Index "$Cat" ) done <<< "$CatNames" CatCnt="$Index" while [ 1 ]; do REPLY=$(dialog --title "$Me $Version $Codename" --default-item "$DefCat" --stdout --cancel-label 'Exit' --menu "Available categories: $CatCnt" 16 50 9 "${CatMenu[@]}") if ! [ "$REPLY" -eq "$REPLY" ] 2>/dev/null; then break fi DefCat="$REPLY" let CatPos=$REPLY*2-1 CatName="${CatMenu[$CatPos]}" CatLink=$(echo "$CatLinks" | sed -n ${REPLY}p) CatMovies done clear echo "Exit on user request" #------------------------------------------------------------------------------------------ exit