zondag 5 maart 2017

Kodi ubuntu / linux: autoplay mp3 on USB using udev

Kodi ubuntu / linux autoplay hot-pluggable devices like USB, using udev:

Ideal for building custom music players 

sudo apt-get install kodi-eventclients-kodi-send


ACTION=="add", KERNELS=="usb*", SUBSYSTEMS=="usb," DRIVERS=="usb",   \
RUN+="/usr/bin/systemd-run /storage/autoplay.sh /dev/%k"


#/storage/autoplay.sh chmod +x /storage/autoplay.sh
sleep 10

MP=$(grep "^${1} " /proc/self/mounts | cut -d ' ' -f 2)

shopt -s globstar
shopt -s nullglob
if [! -f ${MP}/pl.m3u ]
for f in ${MP}/*.mp3 ${MP}/**/*.mp3 ${MP}/**/**/*.mp3  ;
    if [[ $f != *"*.mp3"*  ]];
then echo "$f" >> "${MP}/pl.m3u" ; fi ; done ;
fi ;
/usr/bin/kodi-send  --action="PlayMedia(\"${MP}/pl.m3u\")

zondag 21 februari 2016

Kodi web interface: Favorite Shortcuts

For some reason i needed to link buttons to play the next and previous favorite, using the Web Interface with Kodi.

How it works:
Copy the default web interface from the global kodi addons folder to your user addon folders, modify addon.xml.

Modify index.html,
add  to the body tag  onload="favid=0;" just to be sure that javascript won't cry.

make some div or span onclick="favid=gotofav(favurl,favid+1);"

or any favorite ID you wish :-)

or do it in jQuery if you desire so, i currently can't be bothered researching howto.

Modify xbmc.launcher.js to include a new js file with this contents:
favurl='jsonrpc?request={"jsonrpc":"2.0", "method":"Favourites.GetFavourites", "params": { "properties": ["window","path","thumbnail","windowparameter"] }, "id": 1 }';
function gotofav(favurl){

$.getJSON(favurl, function( data ) {
  var items = [];
  $.each( data, function( ke, va ) {
      $.each( va, function( key, vall ) {
          if (key=='favourites'){

if (favid < 1){


if (favid >vall.length){ favid=0;}      

        $.each( vall, function( keyz, valz ) {

        if (favid==keyz){
            if (valz['type'] == 'media'){
      'context': this,
      'method': 'Player.Open',
      'id': '1',
      'params': {
        'item': {
          'file': valz['path']

        if (valz['type'] == 'window'){
      'context': this,
      'method': 'GUI.ActivateWindow',
      'id': '1',
      'params': {
        "window": "videos",
          "parameters": [valz['windowparameter']]
        if (valz['type'] == 'script'){
      'context': this,
      'method': 'Addons.ExecuteAddon',
      "wait": false,
      'id': '1',
      'params': {
          'addonid': valz['path']

    //            }

 return favid;

 It's not as pretty as can be,  but it works great :-).

dinsdag 17 maart 2015

Teddy woofpaw Wordpress Installer android app

Installing wordpress on your webhost has never been so easy, as with Teddy Woofpaw wordpress installer.

Download, Install & start the wordpress installer app on your android device. (search google play for teddy wordpress installer).

Input the credentials provided by your webhost: Domain name, ftp hostname, ftp user, ftp password & click install.

Step 3:
Enter the mysql user and password,

Done! Wordpress is up and running!

Step 4:

Official wordpress app can now be installed and used to connect to your site.

Current limitation:
will always be installed to the domain root.

Encountering a problem?
Determining the correct folder for the ftp uploads is done simply by trying to open certain folders in the right order.

The order in which the app tries to enter folders is this:

domains \  _usersupplieddomain_ \  html \ htdocs \ public_html \ www \ wwwroot

This ensures support for all modern webhosts.
Please let me know if your webhost uses an incompatible folder layout on the ftpserver, and provide me a screenshot (via email (click the keyboard) or here in the comment section), i'd be happy to update the app.

Geek talk; Technical explanation of how the app works
When the user submits the data, the app connects with the ftp.
In slow mode (max compatible), next: the app uploads http://wordpress.org/latest.zip.
Then, the app uploads an php script (click to see it).
After uploading is complete, the app opens a webview, visits the url to the php script.
In fast mode, the php script downloads http://wordpress.org/latest.zip.
The php script unzips the wordpress zip file and puts everything in place.
The php script deletes itself, and sends the webview in the app user to the wordpress first-run script with a header redirect.

maandag 16 maart 2015

Wordpress installer PHP script

Example PHP script for installing wordpress in the root of your domain.
This exact script is used in my new upcoming android app Wordpress Installer.
You can save it in a file, upload it to your host and run it in your browser.
It will download Wordpress, unzip the wordpress archive, launch the wordpress first-run script, afterwards this script will delete itself.
the $wpextr variable can be changed to install into a subfolder. Use a leading and a trailing slash.


// www.bartbosma.eu
// 2015
function rrmdir($dir) {
   if (is_dir($dir)) {
     $objects = scandir($dir);
     foreach ($objects as $object) {
       if ($object != "." && $object != "..") {
         if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
$url = "https://wordpress.org/latest.zip";
$destination = "wordpress_latest.zip";   
if (!file_exists($destination)){
    if (function_exists("curl_init")){   
    $fp = fopen ($destination, 'w+');
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
    curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_AUTOREFERER, true );

    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 100 );
    curl_setopt( $ch, CURLOPT_FILE, $fp );
    curl_exec( $ch );
    curl_close( $ch );
  fclose( $fp );
    if (!file_put_contents($destination, fopen($url, "r"))){
        die("Cant download file..");   
if (filesize($destination) > 0) {$succes= true;echo "Archive download succes.<br />";}else{$succes=false;}

    echo "Archive already exists, no download required<br />";

if ($succes==true)
$zip = new ZipArchive;
if ($zip->open($destination) === TRUE) {
    #echo $_SERVER['DOCUMENT_ROOT'].$wpextr;
    echo 'Archive extracted succes';

if ($handle = opendir($_SERVER['DOCUMENT_ROOT'].$wpextr.'wordpress')) {
    while (false !== ($fileName = readdir($handle))) {
        if ($fileName!==".." ||$fileName!==".")     @rename($_SERVER['DOCUMENT_ROOT'].$wpextr."wordpress/".$fileName, $_SERVER['DOCUMENT_ROOT'].$wpextr.$fileName);

header("Location: http://".$_SERVER['HTTP_HOST'].$wpextr."/wp-admin/install.php");

} else {
    echo 'ExtractTo function: Opening the wordpress zip file failed. Your webhost seems ancient.';
// www.bartbosma.eu xD

maandag 9 maart 2015

Android HTPC TVMC hdmistick ultimate guide tutorial

So, you stumbled upon those android HDMI sticks, and now you wonder how to set it up for epic HTPC usage, and what software to use.

I'll explain what i did.

First i bought the hardware.
I bought:
Rikomagic 802 version 3.
This version has some small wifi bugs, requiring a hard reboot occasionally, with a minute pauze after powerdown.

I added:
externally powered USB hub with support for all different types of SD cards (brand Icidu).
External USB blu-ray player.
External USB HDD for MP3/photos.
Instead of powering the HDMI stick with the TV it's USB slot, i decided to use an old USB DC adapter (from some phone).

Setting up the software to interact together nicely, requires some proper effort, but nothing too fancy.
Controlling the device can be done with a keyboard that includes multimedia keys like play / stop / back.
Using the TAB button and the windows keys, you have enough to set up the device for remote control.

The first remote control app you (not mandatory) need on both your HDMI stick as your android phone, is RemoDroid:
Determining the IP address to connect to, on the HDMI device, simply goto wifi settings and click your wifi network. Your IP should popup.
Now, unfortunately remodroid is kinda slow, so if you want to, like, play games on your hdmi stick, there are some specialist stores selling nice USB/bluetooth remote control devices, tailored for Android specifically.

Next, installing TVMC is the easiest way to go:
It comes with all the nice plugins preconfigured.
Icefilms and NavX are my recommendations.

Ofcourse there are tons of repositorys with nice plugins, ill list the most common, you can set these up as file sources in TVMC; system > file manager > add source:




Good, now you could basically watch any tv show/movie, have subtitles in your preferred language (in TVMC goto addons and install subtitle addon).

TVMC on android has some minor hardware-keyboard bugs. Backspace won't work, delete key (also multimedia back key) acts like backspace instead.
But who cares, since we will remote control the device with the official XBMC remote app:
(which became outdated, search for KODI instead in the play store for alternatives)

Or if you are exrtemely special, you can use an Apple phone:
However i strongly suggest that Apple users also buy an Apple HDMI stick. They are very rare, but keep looking and maybe one day you might find one.

Before this TVMC remote control app works, you need to goto settings in TVMC and enable the remote control setting.

If you are dutch, you could also install the xot-uzg plugin:

Installing SambaDroid APP allows you to manage / sync your external USB hard drive its MP3 database with your linux/windows workstation, which you probably use to collect MP3 files:

There are some andoid apps which allow one to collect mp3 files aswell, like goSeek:

an example sync from workstation to miniHTPC script for use in windows: (you can create a .bat file with this text in it, or open an terminal via start-search "cmd":)

robocopy  "E:\My Music\sort" \\SAMBADROID\usb\USB_disk0\OneTouch4\user\mp3 /R:1 /MIR /Z /DCOPY:T /FFT

Syncing from the device to your windows workstation, use the same command, but just name the local folder last.

Sometimes the drive ID will change depending on your hdmistick, you can just add multiple commands with multiple drive ids like DISK3 etc
Ofcourse a local NAS drive is much prefered.

There is just one problem now.
You need to turn on your TV before you can play music from your HTPC device.
Fixing this requires one more investment.
It's unfortunately a device not often used thus not for sale at most stores, search engines or ebay will pick it up when you search for stuff like HDMI to HDMI + audio extractor.
One brand that i know of is DeLOCK, searching delock HDMI extractor should give you results.
DON'T buy an USB soundcard. it WON'T work.

Perhaps you want TVMC to launch automatically whenever you turn on the device, simply get an app like autostart:

MAMCWES, The most secure mysqli php class wrapper i've ever seen.

This post is all about...... mamcwes (GPL v3)

What's that?

Easy to use PHP class for MySQL interaction, optionally allowing linking between multiple database user logins (with custom user rights on your databases/tables) and custom userlevels.

For who is it?

PHP writers / developers / coders generally.

What does it do, how does it differ from other mysqli classes?

Its an mysqli wrapper providing extensive security protection.
Basically, the required credentials for the mysqli connection are loaded only very briefly into the php memory, inside the class call. It is fully impossible for people to get the mysql login credentials.

Furtermore, it allows you to login as multiple mysql users based on your custom userlevel table, useful for hard-restricting permissions to the database, providing even more security.

How does it work?

$this->gl_conf_ulvl in the mysqlcfgdata.inc.php is the userlevel setting. Default it loads from $_SESSION['rdmstring'].
One should use the escstr function to parse any kind of user input.
Looking at the class (functions) name(s), it won't be too hard figuring out how to make the DB connection / calls.

Usage example:
First add your database connection login to the cfg file. @session_start();
$_SESSION['us0rlv0l']=1; # userlevel, optionally set by your own login script. will be used to select login data (array) id from config file.

#For more protection you could use:

#$_SESSION[${$_SESSION['rdmstring']}]=1; # userlevel

$mysqlerrordie=0;# 1 to terminate php execution on mysql error.
#$olddir=getcwd(); #optional
include "mysql.class.5.php"; # note: when you put the class in another folder, use chdir("classes"); first to navigate to that folder. go back with chdir($olddir); if needed.

$sql=@new MYSQL();
SELECT badword
FROM `badwords` WHERE `badword` = '".$sql->escstr(customvalidatefunction($_POST['badword']))."'"

if (isset($r) && $sql->count_rows($r) > 0){
foreach($sql->db_array2($r) as $item){ #also available are db_array, db_object(2) and db_assoc(2), whereas the 2 means more then 1 entry can be fetched, thus requiring processing via foreach loop.
echo $item[0];

Basically, if you build your own userlogin system with this class, you first connect with a readonly mysql user that retrieves your user table, retrieves the userlevel of the logged in person, and than you can use that userlevel variable to select the desired mysql user credentials (permissions) for that userlevel, while the userlevel will always be stored in a random Session variable.
Untracable and ultrasecure.


mamcwes 0.2 (English)

maandag 13 januari 2014

Using Android in your car, full guide


So today, i'd like to write about utilising your android tablet/phone in your car.

What could one possibly want?

  • (Offline) navigation to adresses in your phone its address book & realtime traffic jam avoidance
  • Watching TV (either via DVB-T, preloading via wifi or via 3g/4g online streaming)
  • Listening to real FM/DAB+ radio
  • Skype videochat (via 3g/4g)
  • Playing music via bluetooth to car radio
  • Realtime onboard diagnostic displays (requiring bluetooth)
  • Handsfree calling
  • Rearview camera
  • Play games

What's best for your wallet basically depends on if your current car radio is capable of bluetooth.
Because if it isn't, you could even take out the whole thing, hook the tablet/phone output to a basic amplifier.
If you have an old casette player, you can buy a special fake casette with a mini-jack connection.

If your car radio is bluetooth capable, good. You can send music to the car radio via bluetooth. The bluetooth default password is usually 1234 or 0000.

Navigation is done best via google maps. Even offline navigation. It has an option to download maps for offline use.
You will need free space on your device.
Let your route be calculated with wifi still enabled so that any traffic jams will be avoided.

Watching TV /listening radio via DVB-T:
First, you will want to check if your area has any decent DVB-T coverage.
If so, you would want some specific usb device.

For example:

These devices require android 4.0.3
You need this app:

Watching series/movies via wifi or 3g/4g streaming:
 You will want to follow my android HTPC guide on this blog, the part about XBMC.
To avoid roaming costs, XBMC plugins 1channel and icefilms include the option to download movies/episodes.
Ofcourse there are endless apps for streaming TV, but all i can say is i strongly recommend using1channel and icefilms XBMC plugin.

Listening to real FM/DAB+ radio
so you took out the piece of junk broken radio that some guy left there in your epic classic car..
Listening true FM can be done via different methods.
First, you could simply buy a tablet with a build in FM receiver.
For example, Lenovo A1000 is a nice budget pick.

Second option, there is a cheap app, but with very limited device compatibility.

List of device compatibility

Next, there are some special devices for sale:
Lingo iVy via USB
TechniSat DAB radio DAB+, FM via Bluetooth

Skype videochat
Nothing hard about this, just make sure you buy a tablet/phone with a front camera that also supports a sim card, obviously.

Realtime onboard diagnostic displays
So, your car is from after 1996? Congratulations, there is an ODB connector hidden somewhere.
Buy an ELM327 bluetooth device (take good care not to buy a fake one), plug it in, connect,
install the app Torque:

Rearview camera
Its easy if your phone/tablet android version is atleast 2.3. Just enable wifi hotspot in your tablet/phone, buy a cheap wifi camera, log it in your network.
Now just create a shortcut to your browser on your mainscreen, which instantly visits the camera its local url.

So, maybe you would want to both charge your phone and plug in a DVB-T and/or FM USB dongle?
Simply buy the smallest hub you can find, and get an mini-usb male to usb female adapter.

All you need now is a proper mount/location for the desired configuration in your car.