A fun autoexec.py streaming radio/screensaver startup hack

Discussion of plugin / script development for XBMC4Xbox
Post Reply
DivideByZer0
Posts: 12
Joined: Wed Jun 08, 2016 8:32 pm
Has thanked: 8 times
Been thanked: 4 times

A fun autoexec.py streaming radio/screensaver startup hack

Post by DivideByZer0 » Tue Jul 19, 2016 9:49 am

What it does
This script starts a randomly selected streaming radio station at startup (some examples are provided below.) It also sets the slideshow screensaver to use a large number of images, which I got from a wallpaper torrent, also listed below. It starts a random slideshow of the images a few seconds after XBMC starts and the music starts playing. It's a neat little audiovisual setup for your XBMC, and if you have XBMC as your primary dash, you can boot into this mode with one button! I recommend Confluence Light for use with this setup at 720p; regular Confluence will work but less smoothly at startup.

Here's a video of the script in action, from xbox startup to music/slideshow: https://www.youtube.com/watch?v=EGL7zwus-tI

Details

I wanted to play some streaming music when XBMC started, so I got together a few video game/demoscene/chiptune music streaming radio stations (see links below) and had my autoexec.py pick a random file from the folder when XBMC started. (it wasn't working for me from the startup playlist option)

I also thought it would be cool to download a lot wallpapers and use them as a screensaver. I downloaded a huge wallpaper set (see link below), and converted them to 720p jpgs, which came up to about 7GB. In the process of transferring them to my xbox, I ran up against the 4096 file limit. So, I split the files into 10 directories and tried again. Running a recursive slideshow or starting the screensaver pointed to the image diretories didn't work, the screensaver would take control away and I would have to press a button to return to normal browsing, but nothing would appear on screen. So, apparently ~40,000 images is a little too much for a recursive slideshow.

To work around this I had the autoexec.py script change the setting by editing the slideshowpath line in guisettings.xml to a random folder out of 10 folders containing 4096 images each. So now I have a built-in screensaver that doesn't rely on an external API to get content. I have my screensaver set to start at 1 minute, and I also put a line in the script to start a random slideshow of the current screensaver directory at startup.

By the way, I had tried putting the images in 0 compression RARs to save on file count and transfer time, but the slideshow would always start from the first image of each RAR.

Wallpaper set from: https://www.reddit.com/r/pcmasterrace/c ... allpapers/ (note that all wallpapers are available on imgur)

I used FastStone Image Viewer to batch convert the image files to 720p 16:9 resolution (using "smart cropping") rather than scaling at 90% quality.

You should run a duplicate checker on the images; maybe 1/4 of them are duplicates. The program I used was DupDetector, but it's a little awkward to use and I don't recommend it. I was able to get the full 720p set down to 5.6 gigs and ~31,000 files by removing duplicates.

As a side note, UnleashX can also have its screensaver set to a 4096-image directory and handles it fine loading-wise, although it will chug a little with rendering 720p images. 480p images are much smaller, and I ended up sending over a single folder of 4096 images for UnleashX to use. Note that you need to resize them to 853x480 for them to fill the screen on UnleashX, not 720x480 like I tried the first time...

Streaming radio stations:

Scenesat Radio (Demoscene): http://www.scenesat.com/listenmenu
mine - High bandwidth, max quality - http://www.scenesat.com/listen/normal/max.m3u

Nectarine Demoscene Radio - https://www.scenemusic.net/demovibes/streams/
mine - http://necta.jansenit.com:8000/necta192.mp3.m3u

AI Radio (Video game music) - http://ai-radio.org/streams/
mine - http://ai-radio.org/320.ogg

CGM UK Demoscene Radio - http://www.lmp.d2g.com/
mine - 128kbps mp3 - http://www.lmp.d2g.com:8003/listen.pls

Gyusyubu Radio (music from old Japanese PC games) - http://gyusyabu.ddo.jp:8000/listen.pls

Kohina ("old school game and demo music") - http://www.kohina.com/ (note that there are 2 streams)
mine - http://www.deliancourt.org:8000/fresh.ogg.m3u ("Fresh" stream, DE)
mine - http://stream.nute.net:8000/kohina/stream.ogg.m3u ("Full Playlist" stream, FR)

Let me know if you haven any suggestions for improvement to streaming format for any of these sites, or any streams that you think would go well with this, and I'll update the links in the OP

I have to say that these stations go great with the above image download, try it out! I recommend adding all your stations to your favorites, so that you can quickly switch between them.

I really had a blast with this little project and seeing the end result.


SCRIPT:
(Thanks to Rocky5 with his help cleaning this up!)

Code: Select all


import xbmc
import time
import random
import os
import fileinput

#########################################################################################################
# Paths (change me; no trailing slashes please)
#########################################################################################################
Music_Path = "F:/Music/BGRadio" 
Pictures_Path = "F:/Pictures/Wallpaper/720p"

#########################################################################################################
# Wait a little while for both since the script seems to fail otherwise
#########################################################################################################
time.sleep(1.5)

#########################################################################################################
# Get a random subdirectory of Pictures_Path and set this directory to the slideshow screensaver path
#########################################################################################################
Pictures_Dir_List = os.listdir(Pictures_Path)
Directory_Name = random.choice(Pictures_Dir_List)
New_Screensaver_Path = Pictures_Path + '/' + Directory_Name

Slideshow_XML_Line = '<slideshowpath pathversion="1">' + New_Screensaver_Path + '/</slideshowpath>\n'
GUISettings_Path = fileinput.input( xbmc.translatePath( 'special://profile/guisettings.xml' ), inplace=1)
for line in GUISettings_Path:
   if "slideshowpath" in line:
      line = Slideshow_XML_Line
   sys.stdout.write(line)


#########################################################################################################
# Get a random playback item from the music directory (does not check for file type)
#########################################################################################################
list = os.listdir( Music_Path )
xbmc.executebuiltin( 'PlayMedia(' + Music_Path + '/' + random.choice(list) + ')' )

#########################################################################################################
# Start a slideshow with the new screensaver directory
# 
# NOTE:  This runs into memory issues with starting the screensaver and radio at the same time for regular Confluence at 720p.
#        Confluence Light seems to work fine.  If you're only using this for the screensaver, you can remove the time.sleep call.
#        Users with 128GB of RAM on regular Confluence might be also ok with removing the time.sleep call.
#        7 seconds was about the lowest I could set it on Confluence where it usually wouldn't be interefered with by radio startup. 
#########################################################################################################
#time.sleep(7.5)   #uncomment this line if you're not on a low memory skin!
xbmc.executebuiltin('SlideShow('+ New_Screensaver_Path + ', random)')
This is quick and dirty but here's my original autoexec.py:

DON'T USE THIS VERSION, USE THE ABOVE VERSION WHICH IS BASED ON THE NEXT POST
THIS IS HERE AS AN EXAMPLE OF WHAT NOT TO DO

(it has been fixed to work though)

Code: Select all

import xbmc
import time
import random
import os

# Wait a little while for both since the script seems to fail otherwise
time.sleep(1.5)

# Get a random item from the directory (does not check for file type)
# Use this directory or change it to your directory of choice on both lines
list = os.listdir("E:\\Apps\\XBMC\\BGMusic")
xbmc.executebuiltin( "PlayMedia(\"E:\\Apps\\XBMC\\BGMusic\\" + random.choice(list) + "\")" )

# Get a random subdirectory of dirpath, be sure to add the trailing slashes to your dirpath.  
# This dir should only contain folders (sloppy, I know)

dirpath = "F:\\Pictures\\Wallpaper\\720p"
walldirlist = os.listdir(dirpath)
dirname = random.choice(walldirlist)
pathstring = "<slideshowpath pathversion=\"1\">dirpath + dirname + "\\</slideshowpath>\n"
filePath = "E:\\Apps\\XBMC\\UserData\\guisettings.xml"
text = open(filePath).read()
#xbmc.log(text)
new_text = '\n'.join(pathstring if line.find("slideshowpath") != -1 else line for line in text.splitlines())
open(filePath, 'w').write(new_text)
Last edited by DivideByZer0 on Wed Jul 20, 2016 5:47 pm, edited 23 times in total.

User avatar
Rocky5
Posts: 958
Joined: Sat Feb 08, 2014 5:27 am
Has thanked: 90 times
Been thanked: 248 times

Re: A fun autoexec.py streaming radio/screensaver startup ha

Post by Rocky5 » Tue Jul 19, 2016 12:02 pm

What version of XBMC are you using as 3.5.3 errors when the script is run.
(even when I fix the first syntax error the next section has another)

Code: Select all

ERROR: SyntaxError: ('invalid syntax', ('Q:\\scripts\\autoexec.py', 20, 43, 'pathstring = "<slideshowpath pathversion="1">"+ dirpath + dirname + "\\\\</slideshowpath>\\n"\n'))
Redon your script, hope you dont mind, this one works with 3.5.3.

Code: Select all

import xbmc
import time
import random
import os
import fileinput

#########################################################################################################
# Paths (change me)
#########################################################################################################
Music_Path = "G:/Music/My Music/" 
Pictures_Path = "C:/Images/Backgrounds/"


#########################################################################################################
# Wait a little while for both since the script seems to fail otherwise
#########################################################################################################
time.sleep(1.5)
#########################################################################################################
# Get a random item from the directory (does not check for file type)
#########################################################################################################
list = os.listdir( Music_Path )
xbmc.executebuiltin( 'PlayMedia(' + Music_Path + random.choice(list) + ')' )
#########################################################################################################
# Get a random subdirectory of Pictures_Path.
#########################################################################################################
List_Root_Directory = os.listdir(Pictures_Path)
Directory_Name = random.choice(List_Root_Directory)
New_Path = '<slideshowpath pathversion="1">' + Pictures_Path + Directory_Name + '/</slideshowpath>\n'
GUISettings_Path = fileinput.input( xbmc.translatePath( 'special://profile/guisettings.xml' ), inplace=1)
for line in GUISettings_Path:
	if "slideshowpath" in line:
		line = New_Path
	sys.stdout.write(line)
Download Xbox Softmodding Tool & Extras Disc
XBMC4Kids Mod


Xbox Gamertag = Connxtion
PSN ID = JCRocky5

DivideByZer0
Posts: 12
Joined: Wed Jun 08, 2016 8:32 pm
Has thanked: 8 times
Been thanked: 4 times

Re: A fun autoexec.py streaming radio/screensaver startup ha

Post by DivideByZer0 » Tue Jul 19, 2016 11:55 pm

Thanks, yours is much cleaner (and I learned a little bit from it too!) I had also posted a slightly earlier version of the script somehow and forgot to escape the quotes in "<slideshowpath pathversion="1">", it should have been "<slideshowpath pathversion=/"1/">"; the file must have gotten mixed up since I was editing it over FTP from 2 different machines...

So, sorry about that and thanks for your help, I'll update my posted code to the actual working version!


By the way, if anybody's using that wallpaper torrent, you probably want to run a duplicate checker as well on the images. Maybe 1/4 of the entire set are duplicates; I managed to cut the set down to 5.6 GB and ~31,000 images at 720p.


EDIT:I added startup slideshow functionality, and I added a video of the script here: https://www.youtube.com/watch?v=EGL7zwus-tI

I've found that using Confluence Lite (as opposed to regular Confluence) improved launching reliability a lot with starting music + slideshow at once. I also set Confluence Lite's background image directory to be randomly set by the script in the same way as for the screensaver, and I changed the skin files so that Confluence Lite changes its background every 9 seconds (done by editing the <timeperimage> tag in each view's .xml file in the skin's "720p" folder). So, now random wallpaper are used throughout the app even while the screensaver isn't running.

Post Reply