Skip to content

Instantly share code, notes, and snippets.

@chrisross
Last active November 26, 2018 16:51
Show Gist options
  • Save chrisross/bb83c1b51c3ad138327e to your computer and use it in GitHub Desktop.
Save chrisross/bb83c1b51c3ad138327e to your computer and use it in GitHub Desktop.
This script scans for connected usb media, selects the first one and creates a playlist from the USB's top-level directory. Connect to the same network as the raspberry pi and scp the script to /home/osmc/.kodi/userdata (this may vary depending on OS). This is meant for a Raspberry Pi used as a media player, with OSMC installed.
# Autoplay videodirectory
import os, xbmc, time
usb_dir = "/media" # path of external media
delay = 10 # seconds to delay media player
# Collect directories (USBs) in usb directory
usb_list = []
for fname in os.listdir(usb_dir):
fpath = os.path.join(usb_dir, fname)
if os.path.isdir(fpath):
usb_list.append(fpath)
usb_list.sort()
path = usb_list[0]
dir_list = os.listdir(path)
dir_list.sort()
video_list = xbmc.PlayList(xbmc.PLAYLIST_VIDEO)
video_list.clear()
for fname in dir_list:
video_list.add(path + "\\" + fname)
# shuffle playlist
# video_list.unshuffle()
# put playlist on repeat
xbmc.executebuiltin("xbmc.playercontrol(RepeatAll)")
# delay play
time.sleep(delay)
# play playlist
xbmc.Player().play(video_list)
scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -q ./autoexec.py osmc@192.168.43.132:/home/osmc/.kodi/userdata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment