2015-02-14, 01:21
Hi
I made a small script monitoring the log of kodi for streams you're watching, and automatically downloads them to a local folder. It's made because our provider only keeps the streams for a certain amount of days, and we'd like to have them accessible to watch later. And my kids love to watch the same episode 200 times, and when they want to watch it for the 199th, its taken off.
It consists of 2 scripts currently, an upstart script to make it run as a service, and the download script. That could be merged into the upstart script i guess, but i havent really put an effort in that yet. It shows a gui notification when the download starts, and when it is done. And it checks for already downloaded files, if they're there, it wont download it again.
OS: ubuntu server 14.04
Required software : vlc
Required options in kodi : webserver enabled
Confirmed working with: DR.DK addon, airplay items
upstart script:
place in /etc/init/ and do a chmod +x /etc/init/FILENAMEYOUCHOOSE
the script it calls is :
Cheers
I made a small script monitoring the log of kodi for streams you're watching, and automatically downloads them to a local folder. It's made because our provider only keeps the streams for a certain amount of days, and we'd like to have them accessible to watch later. And my kids love to watch the same episode 200 times, and when they want to watch it for the 199th, its taken off.
It consists of 2 scripts currently, an upstart script to make it run as a service, and the download script. That could be merged into the upstart script i guess, but i havent really put an effort in that yet. It shows a gui notification when the download starts, and when it is done. And it checks for already downloaded files, if they're there, it wont download it again.
OS: ubuntu server 14.04
Required software : vlc
Required options in kodi : webserver enabled
Confirmed working with: DR.DK addon, airplay items
upstart script:
place in /etc/init/ and do a chmod +x /etc/init/FILENAMEYOUCHOOSE
Code:
env USER=bjarke
description "Automatic stream downloader"
author "bjarque"
#start on (filesystem and stopped udevtrigger)
#start on (filesystem)
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [016]
# tell upstart to respawn the process if abnormal exit
respawn
script
exec su -c "exec /home/bjarke/scripts/dl" USER
end script
the script it calls is :
Code:
#!/bin/bash
### CONFIG
path="/home/xbmc/.kodi/temp/" #path to kodi.log directory
dlpath="/home/bjarke/download_files/" # path to download files to
messagebefore="Getting file:" # OSD message when downloading the file
messageafter="Download finished!" # OSD message when done donwloading
port="8080" #kodi port for webserver
### END CONFIG
line="";
tail -f $path/kodi.log | while read -r line; do
if [[ "$line" == *"Opening: htt"* ]]; then
NAME=${line##*"Opening: "}
sleep 10
title3=$(curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" http://localhost:$port/jsonrpc -d '{"jsonrpc":"2.0","method":"Player.GetItem","params":{"playerid":1},"id":"VideoGetItem"}')
title4=${title3##*"label\":\""}
title5=${title4%%"\","*}
FILE="$dlpath$title5.mp4"
if [ ! -f "$FILE" ]
then
curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" http://localhost:$port/jsonrpc -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"'"$messagebefore"'","message":"'"$title5"'"}}'
cvlc $NAME --stop-time=300 --sout="#std{access=file,mux=mp4,dst='$FILE'}" vlc://quit
curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" http://localhost:$port/jsonrpc -d '{"id":1,"jsonrpc":"2.0","method":"GUI.ShowNotification","params":{"title":"'"$messageafter"'","message":"'"$title5"'"}}'
fi
fi
done
Cheers