About Me

My photo
I know the last digit of PI

Thursday, July 23, 2015

OpeneElec Kodi hacking - creating music catalog

Systemd CIFS mount

/storage/.config/system.d/storage-music-rock.mount
[Unit]
 Description=cifs mount script
 Requires=network-online.service
 After=network-online.service
 Before=kodi.service

 [Mount]
 What=//192.168.0.31/MusicRock
 Where=/storage/music/rock
 Options=username=myusername,password=mypassword,rw
 Type=cifs

 [Install]
 WantedBy=multi-user.target
Important: this file must be renamed to mountpoint.mount where mountpoint, is the FULL path where the share will be mounted. Slashes "/" MUST BE REPLACED with dashes "-" with .mount as extension. This means, if we want mount to "/storage/music/rock" (see above "Where=/storage/music/rock") then this file must be renamed to 'storage-music-rock.mount'. This is only for the filename! not for the What= and Where= sections!

Script that maps file by the first two letters

/storage/.config/create_symb_links.sh chmod +s /storage/.config/create_symb_links.sh
#!/bin/bash
displayUsage() { 
  echo "Scans source directory and create symbolic links based on the file first two letters" 
  echo -e "\nUsage:\n$0 [src-dir] [links-dir]\n  src-dir\tsource directory to be scanned\n  links-dir\tfull path to target directory where symbolic links will be created\n\n" 
  echo -e "e.g.:\n $0 /storage/music/rock /storage/music/rock_links/\n\n"
  echo -e "Let's have 3 files:\n    /storage/music/rock/rock1\n    /storage/music/rock/rock2\n    /storage/music/rock/metal\n"
  echo -e "then inside /storage/music/rock_links/ you will have following files:\n"
  echo -e "    /storage/music/rock_links/RO/rock1\n    /storage/music/rock_links/RO/rock2\n    /storage/music/rock_links/ME/metal\n"
} 


if [[ -z $1 ]]; then
  displayUsage
  exit 1 
fi

if [[ -z $2 ]]; then
  displayUsage
  exit 1 
fi

dir=$1
links=$2
currdir=`pwd`

rm -Rf $links

cd $dir

mkdir -p $links
for f in *
do 
  prefix=`echo $f | cut -c 1,2 | tr [:lower:] [:upper:]`
  mkdir -p $links/$prefix
  ln -s "$dir/$f" "$links/$prefix/$f"
done

cd $currdir

Service for creating music catalog

/storage/.config/system.d/catalog-music-rock.service
[Unit]
Description=Create musics catalog
Requires=storage-music-rock.mount
After=storage-music-rock.mount
Before=kodi.service

[Service]
Type=oneshot
ExecStartPre=/bin/bash -c 'echo "Creating music catalog ..."'
ExecStart=/bin/bash -c '/storage/.config/create_symb_links.sh  /storage/music/rock /storage/music/rock_links'
StandardOutput=tty

[Install]
WantedBy=multi-user.target

Enabling mount and services

systemctl enable storage-music.mount
systemctl enable storage-music-rock.mount
systemctl enable catalog-music-rock.service

No comments: