Idea: Pause download package when video is playing.
|
31st Jan, 2013, 10:46 PM
Post: #1
|
|||
|
|||
Pause download package when video is playing.
Hi! I'm new to the forum altough i have been reading it for quite a while.
I have been working the last days in a script that detects when XBMC starts playing stuff and uses the signal SIGSTOP to pause all proceses related to downloads and then, when the video stops playing, it uses the signal SIGCONT to resume them. I have created the following folder ~/.xbmc/addons/script.service.procmanager where I store my script with the addon.xml file, the script is as follows: http://pastebin.com/VmkqecST I had to call the startall.py and stopall.py with sudo rights because the downloads are managed by other users and xbian user dosen't have the rights to manage them (I added those files with visudo so that i don't need a password to execute them with sudo). The startall.py and stopall.py are as follows: http://pastebin.com/aSJnS0Tx What I did to get the PID of each process related to downloads, is to add each user that started that kind of process to a common group "download" so, for example, sabnzbd is executed by user sabnzbd which is a member of the group download, same for transmission, couchpotato and sickbeard, they all belong to the group download. I just get the process list of that group of users and then i send a sigstop to each process. The problem with this script is that i can't manage to autostart it within xbmc, my addon.xml looks as follows http://pastebin.com/H5Tp2hRm I'm new to python so I'm not sure if what I've done is right, the default.py script is a copy paste of things I found around internet. According to what I've read, the addon.xml will tell XBMC which script to start and when, but it dosen't seem to work. I found information regarding a workaround involving autoexec.py file, which I couldn't find. I would really appreciate some help here as I don't know how to continue or how to debug this process. |
|||
1st Feb, 2013, 06:31 PM
Post: #2
|
|||
|
|||
RE: Pause download package when video is playing.
<extension point="xbmc.service" library="default.py" start="startup|login">
this line is not good, you have to choice either startup or login, in this case, you can choose startup <extension point="xbmc.service" library="default.py" start="startup"> don't look at the rest. and your pyhton file must be name default.py or change it in addon.xml to correspond to your file name. but default.py is a quite standard in xbmc. Please read rules and do a search before you post! . FAQs . How to post log file? . Looking for answers? Please start here |
|||
2nd Feb, 2013, 01:12 AM
Post: #3
|
|||
|
|||
RE: Pause download package when video is playing.
I have done what you told me but it dosen't seem to get executed, I checked the XBMC log file and couldn't find anything.
The script name is default.py. Any other ideas? |
|||
2nd Feb, 2013, 02:07 AM
Post: #4
|
|||
|
|||
RE: Pause download package when video is playing.
Your code look strange :
PHP Code: while(1): #Do this in order to know when video isn't playing will never go out, and put a sleep somewhere, something like : PHP Code: while not xbmc.abortRequested(): and why call python function with os.system, it' python in python so call the python function directly, and import your files. and do a print somewhere at the beginning to see if service is started, it'll appear in xbmc.log and instead of use ps, you can take a look here : https://github.com/xbianonpi/xbian-config-bash/wiki/Services but you have to update xbian config if you are on alpha4 and a python wrapper for xbian-config is done here : https://github.com/xbianonpi/xbian-config-python/blob/master/resources/lib/xbianconfig.py Read a bit more you code, but i think you can't override player like you do to do this, if you override player like this, it will react only if you call your player from your script but maybe i'm wrong, need to be tested. eidt : no, sure i'm wrong, it should work also. here's a basic code (not tested at all) PHP Code: import threading,time Please read rules and do a search before you post! . FAQs . How to post log file? . Looking for answers? Please start here |
|||
2nd Feb, 2013, 11:47 AM
Post: #5
|
|||
|
|||
RE: Pause download package when video is playing.
Thank you very much for your help!
I will make the script print something in order to see it in the log, regarding the while loop, I didn't find any other way of telling the "onPlayBackEnded" function when XBMC wasn't playing video, I thought it would work that way, if video is playing funcion "onPlayBackStarted" is called and the While loop keeps VIDEO = 1 until video stops playing, then the whole script get's executed again. I had to call that python function with os.system because I have to execute it with sudo, and i don't know how i can do that without executing XBMC as root. In order to execute the python function that closes services with sudo, I configure it with Visudo so i can avoid password input. I'm going to see if it is actually getting executed. EDIT: It dosn't seem to get executed at startup. Here is the log file: http://pastebin.com/TdwtfYPD Near line 100 scripts get executed. I have added the following lines to the default.py: http://pastebin.com/VmkqecST I'm unsure if thats the right way of doing it, I found the xbmc.log method here: http://mirrors.xbmc.org/docs/python-docs/xbmc.html#-log |
|||
3rd Feb, 2013, 10:40 AM
Post: #6
|
|||
|
|||
RE: Pause download package when video is playing.
Just an update.
I have followed what you told me and i realised i was placing the script in the wrong place! I had it in /home/xbian/.xbmc/addons/ I supposed that i had to store it there because XBMC logs are stored within the same directory, but i still don't know why the correct place is /usr/local/share/xbmc/addons/ Now i have managed to pause downloads when playback starts, but it seems that "onPlayBackEnded" isn't getting called when playback stops, I have yet to fix that issue, will try it tomorrow! Here is my script, I replaced the while loop as you told, I now undrestand what you told me! Thank you! Code: import xbmc |
|||
3rd Feb, 2013, 07:44 PM
Post: #7
|
|||
|
|||
RE: Pause download package when video is playing.
you should place your script here :
/home/xbian/.xbmc/addons/ and it should work with this. i've done some services, and they runs from there the path /usr/local/share/xbmc/addons/ is normally reserved for default xbmc addon and shouldn't be modified (will be erased at each xbmc update). otherwise, it was in my plan to integrate it with xbian-config-python, but not on the first version. my first idea was to start service when xbmc screesaver is on, and stop when screensaver is off. Please read rules and do a search before you post! . FAQs . How to post log file? . Looking for answers? Please start here |
|||
4th Feb, 2013, 04:31 AM
Post: #8
|
|||
|
|||
RE: Pause download package when video is playing.
The screensaver edition is better I think: Sometimes I stop a movie for a short while. With the playbackEnd all services should 'start to stop' as soon as I resume and that would probably cause some slowness....
+2 for the idea and the work you've been putting into it. Those things make XBian/XBMC better |
|||
4th Feb, 2013, 04:40 AM
Post: #9
|
|||
|
|||
RE: Pause download package when video is playing.
Thank you very much!
Great idea, you are right, making it stop|start downloads according to the screensaver is the best solution! I don't know why, but I'm sure that my script is only activated when I put it in /usr/local/share/xbmc.. when I moved the script folder there it started to work. Will check it later when I arrive home. |
|||
4th Feb, 2013, 06:31 AM
Post: #10
|
|||
|
|||
RE: Pause download package when video is playing.
i've done a mistake,
this is : xbmc.abortRequested and not xbmc.abortRequested() Please read rules and do a search before you post! . FAQs . How to post log file? . Looking for answers? Please start here |
|||
4th Feb, 2013, 09:19 AM
Post: #11
|
|||
|
|||
RE: Pause download package when video is playing.
Thank you! I have it fully working as I wanted it to.
I implemented the scripts to be called upon screensaver start|stop and when XBMC gets closed. It seems to be working flawlessly. It seemed I had a mistake in the addon.xml file which I corrected when moving it to /usr/home/share, when I moved it back to /home/xbian as you told it kept working. The final script is: http://pastebin.com/2mCLmAeB PHP Code: import xbmc |
|||
4th Feb, 2013, 09:46 PM
Post: #12
|
|||
|
|||
RE: Pause download package when video is playing.
great,
but Code: def __init__ (self): and you can put more than 5000 in xbmc.sleep because it break if xbmc is aborted Please read rules and do a search before you post! . FAQs . How to post log file? . Looking for answers? Please start here |
|||
5th Feb, 2013, 11:28 AM
Post: #13
|
|||
|
|||
RE: Pause download package when video is playing. | |||
5th Feb, 2013, 09:24 PM
Post: #14
|
|||
|
|||
RE: Pause download package when video is playing.
Quote:Saw my script being killed because it was longer than 5 seconds 'inactive'. Or is that only with boot-scripts/services? Don't understand what you mean. Script is ended when it reached end of the script. Thread stay alive after, but in this case (no thread), you have to do a sleep at the end otherwise monitoring will stop when reached the end. What i want to tell, is that you can put more than 5 sec in xbmc.sleep, if you put 1 minute, and xbmc stop is requested, it will go out from xbmc.sleep, even if the minutes was not achieved. not really a big problem in this case to put 3 sec, but if you put 1 minutes or more, there are less loop. Please read rules and do a search before you post! . FAQs . How to post log file? . Looking for answers? Please start here |
|||
6th Feb, 2013, 05:48 AM
Post: #15
|
|||
|
|||
RE: Pause download package when video is playing.
Sorry for not posting earlier, I had a problem with the Hard drive used by the Raspberry (I'm still fixing it).
Regarding the script, I set it to 1minute (60000) and deleted the init function and it worked as you told! Thank you very much for your help |
|||
« Next Oldest | Next Newest »
|