Cron XBMC - Help Wanted

  Thread Rating:
  • 1 Votes - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
backspace Offline
Senior Member
Posts: 139
Joined: Mar 2012
Reputation: 1
Post: #16
Hi Rob,
Yes a script would work. But it is more to change the genre of music according to the time. When I last was playing around I found that I would be adding songs to the end of the queue.
I guess executing two commands in one timer would work. ie timer1 (at say 3pm) play playlist1. Timer2 (at say 5pm) clear queue (playlist1 could still have songs/videos to play) Then play playlist2.
Does that make sense?
find quote
robweber Offline
Posting Freak
Posts: 865
Joined: Sep 2009
Reputation: 26
Post: #17
Oh, ok. I think I know what you mean. Basically you want a script that you can call at different times of day that will queue up different types of music, while also clearing out the current playlist.

The way you describe it is how I would do it. When the timer starts I would stop the currently playing song (if player is playing), then clear the playlist, load new playlist, and then start playing. Let me know if you need any help with the script.
find quote
backspace Offline
Senior Member
Posts: 139
Joined: Mar 2012
Reputation: 1
Post: #18
Hi Rob,
I dont know much about python (actually all I know is that is code) so a point or two in the right direction would be greatly appreciated Smile
(I learn best by taking some code that works and pulling it apart and seeing why it works, maybe changing a bit here and there to see what happens)

(as I don't know much about py) would something like this work?
<job name="Test" expression="30 * * * *"command="Playlist.Clear","(Partymode(special://profile/playlists/music/playlist1.xsp))" show_notification="true" />
find quote
robweber Offline
Posting Freak
Posts: 865
Joined: Sep 2009
Reputation: 26
Post: #19
(2012-11-05 01:03)backspace Wrote:  Hi Rob,
I dont know much about python (actually all I know is that is code) so a point or two in the right direction would be greatly appreciated Smile
(I learn best by taking some code that works and pulling it apart and seeing why it works, maybe changing a bit here and there to see what happens)

(as I don't know much about py) would something like this work?
<job name="Test" expression="30 * * * *"command="Playlist.Clear","(Partymode(special://profile/playlists/music/playlist1.xsp))" show_notification="true" />

It's a little more complicated than the command you have written. The CronXBMC addon can only run 1 command at a time, and it must be a built in XBMC method - not a JSON RPC method. In order to accomplish what you want you'll need both a python script, and a Cron call. The Cron call would look like this:

Code:
<job name="Playlist" command="RunScript(ABSOLUTE PATH TO/playlist.py)" expression="30 * * * *" show_notification="true" />

This would then call the playlist.py file somewhere on your system (for testing I just threw it in the music playlist folder) . This script kills the current music, loads up a new xsp playlist and starts it using JSON methods. I tried it out and it works just fine. Do notice that in the Player.Open call you need to provide the path to the smart playlist without the .xsp extension on it. This threw me off the first time testing it.

Code:
import xbmc
import json
import urllib

#function to execute the JSON calls
def getJSON(query,params):
    #execute the json request
    json_response = xbmc.executeJSONRPC('{ "jsonrpc" : "2.0" , "method" : "' + query + '" , "params" : ' + params + ' , "id":1 }')

    json_object = json.loads(json_response)

    #return nothing if there was an error
    if(json_object.has_key('result')):
        return json_object['result']
    else:
        return None


playlist_id = '0' #audio is always 0
player_id = '0' #audio player is always 0
playlist_file = 'Test'

#stop whatever is playing
getJSON('Player.Stop','{"playerid":' + player_id + '}')

#clear the playlist
getJSON('Playlist.Clear','{"playlistid" :' + playlist_id + '}')

#set partymode
getJSON('Player.SetPartymode','{"playerid":' + player_id + ',"partymode":true}')

#open the new playlist
getJSON('Player.Open','{ "item": { "partymode": "special://musicplaylists/' + playlist_file + '" } }')

#start the playlist (this may not be necessary, the OPEN method might call it for you)
getJSON('Player.PlayPause','{"playerid":' + player_id + '}')

Some modifications might be necessary to get it to work for you but this is a good working start.
find quote
backspace Offline
Senior Member
Posts: 139
Joined: Mar 2012
Reputation: 1
Post: #20
(2012-11-05 17:48)robweber Wrote:  Some modifications might be necessary to get it to work for you but this is a good working start.
A little fiddling to get it right but works like a charm Smile Thanks

Now to get someone to finish the GUI for this... Smile
find quote
dspolleke Offline
Junior Member
Posts: 2
Joined: Jan 2013
Reputation: 0
Post: #21
Shameless bump. I would love this feature to work i am urine xbmc on à raspberry pi in my bedroom and i would like to add à sleep timer function and an alarm clock function. I wouldnlike to be woken by an audio or video file. Is there Amy wat i could be of Amy help?
find quote
robweber Offline
Posting Freak
Posts: 865
Joined: Sep 2009
Reputation: 26
Post: #22
Setting up an audio timer is certainly something this addon could do for you. The main piece that needs to be implemented is some custom gui windows. Alot of the information can be rendered using built in XBMC gui elements (like the job listing), but a custom window is needed to actually add/edit jobs.

There is another scheduler type addon written by giftie. It appears complete. It took a different route than mine, using the addon settings to specify jobs/commands instead of through a program interface. This works great because it eliminates the custom window requirement, but also limits you to only the number of jobs that exist in the addon settings as they are hardcoded. It might work for what you are wanting to do though.

https://github.com/Giftie/service.scheduler.git
find quote
Ferrari Offline
Junior Member
Posts: 8
Joined: Nov 2012
Reputation: 0
Post: #23
Dear all
I downloaded the "Cron XBMC" script and I installed it xbmc running under ubunti 12.04.
I modified the cron.xml file as following (I want run a shell script)
<cron>
<job name="TEST" command="System.Exec(/home/ferrari/test)" expression="*/5 * * * *" show_notification="true"/>
</cron>
the shell script is
#! /bin/bash
touch /home/ferrari/test.txt

It works correctly. Every five minutes the file test.txt is created in the ferrari folder.

Then I tried the same in xbmc installed in Raspberry-pi with OpenElec. Ofcourse I changed the pathname in the XML file as following:
<cron>
<job name="TEST" command="System.Exec(/storage/ferrari/test)" expression="*/5 * * * *" show_notification="true"/>
</cron>

and I changed also the script

#! /bin/bash
touch /storage/ferrari/test.txt

I changed the permission of folders:

chmod 777 storage
cd storage
chmod 777 ferrari

The service works (every five minutes the notification si shown on the screen) but the file test.txt is not created.

the tail of xbmc log file is

12:00:00 T:2953208928 NOTICE: service.cronxbmc: running command TEST
12:00:00 T:2953208928 NOTICE: service.cronxbmc: TEST will run again on 01-21-2013 12:05
12:00:00 T:3043398160 NOTICE: ProcessMessage: Failed to suspend AudioEngine before launching external program
12:00:00 T:3043398160 FATAL: ProcessMessage: Failed to restart AudioEngine after return from external player
12:05:00 T:2953208928 NOTICE: service.cronxbmc: running command TEST
12:05:00 T:2953208928 NOTICE: service.cronxbmc: TEST will run again on 01-21-2013 12:10
12:05:00 T:3043398160 NOTICE: ProcessMessage: Failed to suspend AudioEngine before launching external program
12:05:00 T:3043398160 FATAL: ProcessMessage: Failed to restart AudioEngine after return from external player
12:10:00 T:2953208928 NOTICE: service.cronxbmc: running command TEST
12:10:00 T:2953208928 NOTICE: service.cronxbmc: TEST will run again on 01-21-2013 12:15
12:10:00 T:3043398160 NOTICE: ProcessMessage: Failed to suspend AudioEngine before launching external program
12:10:00 T:3043398160 FATAL: ProcessMessage: Failed to restart AudioEngine after return from external player

Have you any solution about it ?
How can I fix the error ?

Thank you very much for your help and cooperation
find quote
robweber Offline
Posting Freak
Posts: 865
Joined: Sep 2009
Reputation: 26
Post: #24
Try using "chmod -R 777" on the ferrari folder. Also make sure your bash script is set to chmod +x for whatever user xbmc runs under on openelec. I've seen weird file permissions issues on openelec systems before since they try very hard to keep everything locked down and as appliance-like as possible. Good for the average user, but tricky when trying to do anything advanced.
find quote
Ferrari Offline
Junior Member
Posts: 8
Joined: Nov 2012
Reputation: 0
Post: #25
Dear all,

>Try using "chmod -R 777" on the ferrari folder. Also make sure your bash script is set to chmod +x for whatever user xbmc runs under on >openelec. I've seen weird file permissions issues on openelec systems before since they try very hard to keep everything locked down >and as appliance-like as possible. Good for the average user, but tricky when trying to do anything advanced.

OK!!! It works!!

Thank you very much!!
find quote
Kr0nZ Offline
Member
Posts: 50
Joined: Apr 2011
Reputation: 1
Post: #26
Here my first attempt at creating a GUI for this:
Keep in mind this is the first time I've ever tried xbmc skinning, I used the gmail checker addon as a base

So far you can add/delete/modify cron jobs
[Image: auhzWa9.png]

and my code is here on github (GUI branch)
https://github.com/Kr0nZ/cronxbmc/commit...9c9e1b?w=1

Also the plugin wants to open a folder, I can't see where in the code where it does this, maybe someone knows why?
The gmail addon doesn't try to open any folders it just loads straight to the window
(This post was last modified: 2013-01-26 01:43 by Kr0nZ.)
find quote
robweber Offline
Posting Freak
Posts: 865
Joined: Sep 2009
Reputation: 26
Post: #27
(2013-01-26 01:02)Kr0nZ Wrote:  Here my first attempt at creating a GUI for this:
Keep in mind this is the first time I've ever tried xbmc skinning, I used the gmail checker addon as a base

So far you can add/delete/modify cron jobs

and my code is here on github (GUI branch)
https://github.com/Kr0nZ/cronxbmc/commit...9c9e1b?w=1

Also the plugin wants to open a folder, I can't see where in the code where it does this, maybe someone knows why?
The gmail addon doesn't try to open any folders it just loads straight to the window

Wow, this is already looking good. I tested it out on my system and it definitely works. Thanks for doing the work on this. I think I fixed the "open folder" issue you were seeing, I already sent a pull request to your GUI branch. I may also start to cleanup the service.py portion a little to update it for Frodo behaviors. With a finished interface this could probably make it to the main repo for general use.

On small error I found when doing a test. It looks like the cron timers area gets focus when the program opens. If you don't have any timers yet that window can't get focus because there is nothing there. This makes it so you can't navigate with a remote or keyboard. You can't even close the program as the main xbmc window must keep focus. Once you have a timer set it works. Here is the error

Code:
09:24:33 T:1296   ERROR: Control 120 in window 13000 has been asked to focus, but it can't
(This post was last modified: 2013-01-26 17:34 by robweber.)
find quote
backspace Offline
Senior Member
Posts: 139
Joined: Mar 2012
Reputation: 1
Post: #28
You guys are making me excited!
Keep it up Smile
find quote
robweber Offline
Posting Freak
Posts: 865
Joined: Sep 2009
Reputation: 26
Post: #29
@Kr0nZ - i see you've merged the pull request for the code changes. Let me know if you have any further updates to the code, feel free to send me a pull request to my gui_testing branch. Again, thanks a lot for the work you've done so far.
find quote
Kr0nZ Offline
Member
Posts: 50
Joined: Apr 2011
Reputation: 1
Post: #30
Yeh, thnx, your pull fixed that open folder problem I was getting.
I also fixed the losing focus issue, now it should focus to the left controls whenever focus is lost.

Heres what I got done so far.
I've added this Cron expression maker. I haven't completely tested it yet, but it seems to be functional.
[Image: zUoEvIf.png]

I still need to redo the 'modify job' window, tidy up the main window a little, and add a window to choose example commands to run.

Let me know of any changes other features you want added.
(This post was last modified: 2013-02-02 10:06 by Kr0nZ.)
find quote