OSMC Raspberry Pi Media Player scripting to make auto random playlists.

NB need to rename the name of USB stick to whatever is in the script for e.g. ZIP ZIP

Connect the Pi to the ethernet. You’ll need to have a keyboard plugged in to move around the Pi menu.

On the Pi find out what its IP address is – this info can be found on the Pi buried under
System/System Info/Summary – get to it from the Gear Wheel icon if you have the Kodi skin installed…

use the Keyboard arrow keys to navigate and enter and escape to go in and out of menu items.

. . . . . . . . . . . . .

On a mac open Terminal enter

ssh osmc@192.168.1.**

(**= whatever the Pi’s IP is)
user: osmc pass: osmc 

(password wont show up in  terminal)
then type
cd /home/osmc/.kodi/userdata/
then type

sudo nano autoexec.py

This opens up a little nano editor – you many need to delete already exisiting script.
Copy in the text from the autoexec.py below – remember to edit the script to set the name of the USB stick to whatever your usb is called.
(N.b. watch out for curly quotes, Pi wants straight quotes. Copying the script from here gives the wrong type of quotes, you can fix by pasting into TextEdit, setting the text to plain text and retyping the quotes  -make sure you do all of them. )

Then hit ctrl x to save, it will ask you to press ‘Y’ (for yes)

Then hit ENTER, to get back to the regular terminal window

Use the arrow keys on the Pi to reboot it.

. . . . . . . . . . . . .

Here’s my autoexec.py script that came from the OSMC forum.
It pulls videos from a USB stick and creates a random playlist that loops. – So the videos are always in the same order. If the Pi is rebooted then the playlist regenerates.

. . . . . . . . . . . . .

# Autoplay videodirectory
import os, xbmc

# set path to directory you want to play..
# for example if my USB stick is called KINGSTON then…


videoList = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)

for fname in dirList:
videoList.add(path + “\\” + fname)

# shuffle playlist

# put playlist on repeat

# play playlist

. . . . . . . . . . . . . .

Ian made an different autoexec.py script that will autoloads and shuffle a preexisiting playlist called

. . . . . . . . . . . . . .

# Autoplay videodirectory
import os, xbmc

import xbmc

. . . . . . . . . . . . . . .

You need to make the playlist in the the KODI interface – hahahaha if you can figure out how to do that, heres a guide.


Make playlist

Go to Movies/Enter Files Section of the KODI interface.

Select Add Videos It will bring up the Add Video Source sub Window

choose Browse then Go to Root Filesystem /Media you should see yourUSBstickName

Select it then hit ok hit OK

then in the Set Content sub window select This directory contains hit RTN or Enter and choose Movies

Then select Choose information provider then select Local information only

then choose OK

then when the window comes up with Do you want to refresh information for all items within this path choose No.

It will take you to a list of all the files on the USB stick. Then choose Go to playlist. Hopefully you will see a video playlist with just the movies in it. You can select a movie and by pressing C bring up the Context menu that will let you remove, play etc the movie from that playlist. ESC closes the context menu. On the L hand side  (use arrow keys to navigate) you should see SAVE which will give you a chance to give the playlist a useful name. Phew!

. . . . . . . . . . . . . . . .

Other rando KODI, Pi keyboard controls

SPACE = Play / Pause


ESC  or BCKSPCE- show hide menu

Select a playlist – you need to be in the VIDEOS section

Delete a playlist- you need to be in the VIDEOS section –  select it in the Categories/Playlists, select the Playlist hit DEL . Or select it hit C to get context menu then Browser into

. . . . . . ..

This guide assumes you have installed the OSMC Raspberry Pi disc image

Pi filler is simple Software that lets you fill up your SD card with a disc image