Sunday, November 8, 2015

Adding content, but keeping it out of 'Recently Added'

Sometimes when adding content your library, you might want to keep it out of the 'Recently Added List' - if you're adding older seasons or building a back-catalog.

To keep it out of Recently Added change the modified time on the files to an older date. You can do this to multiple files with a command like this:

# find . -exec touch -t 201410101010 {} \;

(-t is the time, so this dates is 10th October, 2014 10:10am)

Tuesday, October 27, 2015

VLC init

Daemonize VLC for CCTV Mosaic
https://github.com/salbahra/Security-Camera-Viewer/blob/master/VLC-init

Wednesday, October 14, 2015

Kodi CCTV pop ups #2

I previously talked a using Kodi to show CCTV pop-ups, but I wanted to extend this to show on all active Kodi nodes (I have 4).

(Caveat - I'm no programmer, so most of this stuff is a hack, I'm sure there are better ways to do this, but this works to start with).

The first challenge was finding which nodes were active, to avoid timeouts to nodes which may be suspended. I found a package called 'avahi' which does local network discovery, so with a bit of tweaking, I was able to use this to spit out a list IP's


$ avahi-browse -raptl 2>/dev/null | egrep '_xbmc-jsonrpc.*192' | awk '{split($0,a,";"); print a[8]}' | sort | uniq

then it was a case of looping through the IP's and making the JSON RPC call to each Kodi node:

for line in iter(proc.stdout.readline, ''):
        str = '/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Addons.ExecuteAddon","params":{"addonid":"script.securitycam","params":{"cam":"replace_with_your_cam_IP"}}}'
        req = urllib2.Request('http://' + line.replace("\n", "")  + str)
        try: f = urllib2.urlopen(req)
        except urllib2.URLError as e:
                print e.reason
        except urllib2.HTTPError as e:
                print e.reason
        print f.read()


As mentioned, there are probably tidier ways to do this, but it's a minimum solution right now.

Monday, October 12, 2015

Kodi command line screenshot

I keep forgetting how to do this, so making a note of it here to keep record

$ kodi-send --action="TakeScreenshot"

On OpenElec this dumps it out to Samba 'Screenshots' share for handy pickup.

Sunday, April 5, 2015

Kodi & CCTV Pop-ups

I wanted to be able to alert CCTV snapshots onto my Kodi systems

I found this Security Cam Overlay script, which is brilliant:
http://forum.kodi.tv/showthread.php?tid=182540

You can call the script remotely with the following JSON RPC call:
http://kodi_ip:80/jsonrpc?request={"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"addonid":"script.securitycam"},"id":"1"}}

But if you've got multiple cameras, and want to be able to pass the camera IP by JSON RPC you need to make a few changes:


#url       = __addon__.getSetting('url')

arg = sys.argv[1].split('=')
cam = arg[1]

url = "http://" + cam + "/Streaming/Channels/1/Picture" 

And then you can call the API but pass through the CCTV camera IP address:

http://kodi_ip:80/jsonrpc?request={"jsonrpc":"2.0","id":1,"method":"Addons.ExecuteAddon","params":{"addonid":"script.securitycam","params":{"cam":"camera_ip_address"}}}

This means you can call the JSON RPC from motion detector or other triggers, specifying the camera you want to see.


Kodi mysql backups

When you've got multiple XBMC/Kodi nodes all sharing same media library, it's good to use MySQL as a single database, but also means you're putting all eggs in 1 basket, so you're only a disk or dodgy upgrade away from losing the library data.

I have a little backup script:
#!/bin/sh

DIR=/path/db_backup
DATE=i$(date "+%d%m%y")

mysqldump -u root -pyour_pwd --all-databases > $DIR/db_backup_$DATE.sql
gzip $DIR/db_backup_$DATE.sql


And an archiver
find  /root/db_backup -mtime +14 -exec rm {} \;
Might be safer ways of doing this - so make sure you've got the path right ;)

CCTV Mosaic

I use some Hikvision CCTV cameras, and wanted to stream a 4-in-1 view from my Kodi system. VLC provides this functionality with it's mosaic feature, so it can be configured to take 4 streams in, combine them, and stream them back out again.

I got most of my configuration from this blog - http://alex.mamchenkov.net/2014/11/27/vlc-mosaic-multiple-rstp-streams/

However, I had to lower the resolution on my inputs to get it to work. Soeven though the cameras support high resolution, I configured the cameras 'Sub Stream' to a 640x480 MJPEG stream, given that I will have them only taking up 1/4 of the screen.

My config looks like this:

new channel1 broadcast enabled
setup channel1 input "rtsp://user:password@camera1/Streaming/Channels/2"
setup channel1 output #mosaic-bridge{id=1,height=540,width=960}

new channel2 broadcast enabled
setup channel2 input "rtsp://
user:password@camera2/Streaming/Channels/2"
setup channel2 output #mosaic-bridge{id=2,height=540,width=960}

new channel3 broadcast enabled
setup channel3 input "rtsp://
user:password@camera3/Streaming/Channels/2"
setup channel3 output #mosaic-bridge{id=3,height=540,width=960}

new channel4 broadcast enabled
setup channel4 input "rtsp://
user:password@camera4/Streaming/Channels/2"
setup channel4 output #mosaic-bridge{id=4,height=540,width=960}

new mosaic broadcast enabled
setup mosaic input file:///home/myhome/mosaic/bg.jpg
setup mosaic option image-duration=-1
setup mosaic option image-fps=10/1
setup mosaic option mosaic-rows=2
setup mosaic option mosaic-cols=2
setup mosaic option mosaic-position=1
setup mosaic output #transcode{sfilter=mosaic,vcodec=mp4v,vb=4096,acodec=none,fps=10/1,scale=1}:rtp{dst=myserverip,port=50000,sdp=rtsp://myserverip:50000/cctv.sdp}

control channel1 play
control channel2 play
control channel3 play
control channel4 play
control mosaic play


(Just replacing user/password and camera IPs where appropriate and also replace myserverip for the system you will run VLC on)

Then run vlc against the config file:
 /usr/bin/vlc -I dummy --vlm-conf /path/to/your/file/hikvision_mosaic.conf --mosaic-width 1920 --mosaic-order 1,2,3,4 --mosaic-height 1080

You're now ready to watch your stream by pointing your favourite client at:
rtsp://myserverip:50000/cctv.sdp

To view the stream from XBMC/Kodi you need to create a plain text file eg ;'cctv_montage.strm' and place the above URL here in 1 line (rtsp://myserverip:50000/cctv.sdp)

I've got some work to do to auto-start or daemonize this, but this is main part done.

XBMC update library

Another small script to call Update Library on your XBMC/Kodi system, useful to call as a post-exec after other jobs or downloads.

#!/bin/sh

curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Scan", "id": "myScipt"}' -H 'content-type: application/json;' http://your_ip:8090/jsonrpc > /dev/null 2>&1

exit 0

uTorrent API

I use uTorrent from time to time on my Linux system, but don't like too many stray seeds, so here's a nice little script to stop seeding torrents, just run it from cron at your desired frequency.

It uses the PHP API, from here:
https://github.com/tboothman/utorrent-php-api
http://forum.utorrent.com/topic/23307-php-api-for-the-webui/


#!/usr/bin/php

<?php

require_once("/var/www/webui_api.php");
$host = "your_ip";
$port = "8080";
$user = "user";
$pass = "pwd";

$utorrent = new \uTorrent\Api($host, $port, $user, $pass);
$torrents = $utorrent->getTorrents();

foreach($torrents as $torrent) {
        if ($torrent[UTORRENT_TORRENT_STATUS] == 201 && $torrent[UTORRENT_TORRENT_PROGRESS] == 1000) {
                $utorrent->torrentStop($torrent[UTORRENT_TORRENT_HASH]);
        }

}

?>