Kodi Community Forum
AutoResumer - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: AutoResumer (/showthread.php?tid=24848)



AutoResumer - User 23297 - 2007-02-15

Hi, after seeing Staley87's script to autoresume playback after a reboot (ResumeX), I decided to make my own based on some of his code. Well I've got it mostly working, but I have a small problem. In the section of the code where it writes all the current files in the playlist to data.xml, instead of the filenames it adds what's below.

Data.xml:
Code:
<data>
    <window>10020</window>
    <volume>100.0</volume>
    <time>8.78000041703</time>
    <plspos>0</plspos>
    <plsize>45</plsize>
    <plistfile0><xbmc.PlayListItem object at 0x0118E050></plistfile0>
    <plistfile1><xbmc.PlayListItem object at 0x0118E050></plistfile1>
    <plistfile2><xbmc.PlayListItem object at 0x0118E050></plistfile2>
    <plistfile3><xbmc.PlayListItem object at 0x0118E050></plistfile3>
    <plistfile4><xbmc.PlayListItem object at 0x0118E050></plistfile4>
    <plistfile5><xbmc.PlayListItem object at 0x0118E050></plistfile5>
    <plistfile6><xbmc.PlayListItem object at 0x0118E050></plistfile6>
    <plistfile7><xbmc.PlayListItem object at 0x0118E050></plistfile7>
    <plistfile8><xbmc.PlayListItem object at 0x0118E050></plistfile8>
    <plistfile9><xbmc.PlayListItem object at 0x0118E050></plistfile9>
    <plistfile10><xbmc.PlayListItem object at 0x0118E050></plistfile10>
    <plistfile11><xbmc.PlayListItem object at 0x0118E050></plistfile11>
    <plistfile12><xbmc.PlayListItem object at 0x0118E050></plistfile12>
    <plistfile13><xbmc.PlayListItem object at 0x0118E050></plistfile13>
    <plistfile14><xbmc.PlayListItem object at 0x0118E050></plistfile14>
    <plistfile15><xbmc.PlayListItem object at 0x0118E050></plistfile15>
    <plistfile16><xbmc.PlayListItem object at 0x0118E050></plistfile16>
    <plistfile17><xbmc.PlayListItem object at 0x0118E050></plistfile17>
    <plistfile18><xbmc.PlayListItem object at 0x0118E050></plistfile18>
    <plistfile19><xbmc.PlayListItem object at 0x0118E050></plistfile19>
    <plistfile20><xbmc.PlayListItem object at 0x0118E050></plistfile20>
    <plistfile21><xbmc.PlayListItem object at 0x0118E050></plistfile21>
    <plistfile22><xbmc.PlayListItem object at 0x0118E050></plistfile22>
    <plistfile23><xbmc.PlayListItem object at 0x0118E050></plistfile23>
    <plistfile24><xbmc.PlayListItem object at 0x0118E050></plistfile24>
    <plistfile25><xbmc.PlayListItem object at 0x0118E050></plistfile25>
    <plistfile26><xbmc.PlayListItem object at 0x0118E050></plistfile26>
    <plistfile27><xbmc.PlayListItem object at 0x0118E050></plistfile27>
    <plistfile28><xbmc.PlayListItem object at 0x0118E050></plistfile28>
    <plistfile29><xbmc.PlayListItem object at 0x0118E050></plistfile29>
    <plistfile30><xbmc.PlayListItem object at 0x0118E050></plistfile30>
    <plistfile31><xbmc.PlayListItem object at 0x0118E050></plistfile31>
    <plistfile32><xbmc.PlayListItem object at 0x0118E050></plistfile32>
    <plistfile33><xbmc.PlayListItem object at 0x0118E050></plistfile33>
    <plistfile34><xbmc.PlayListItem object at 0x0118E050></plistfile34>
    <plistfile35><xbmc.PlayListItem object at 0x0118E050></plistfile35>
    <plistfile36><xbmc.PlayListItem object at 0x0118E050></plistfile36>
    <plistfile37><xbmc.PlayListItem object at 0x0118E050></plistfile37>
    <plistfile38><xbmc.PlayListItem object at 0x0118E050></plistfile38>
    <plistfile39><xbmc.PlayListItem object at 0x0118E050></plistfile39>
    <plistfile40><xbmc.PlayListItem object at 0x0118E050></plistfile40>
    <plistfile41><xbmc.PlayListItem object at 0x0118E050></plistfile41>
    <plistfile42><xbmc.PlayListItem object at 0x0118E050></plistfile42>
    <plistfile43><xbmc.PlayListItem object at 0x0118E050></plistfile43>
    <plistfile44><xbmc.PlayListItem object at 0x0118E050></plistfile44>
    <playing>G:\music\Strapping Young Lad\City\01 - Velvet Kevorkian.mp3</playing>
</data>

I can't figure out why it's doing it like that. Here's the code that writes that file:
Code:
        elif not os.path.exists(DATAFILE) and xbmc.Player().isPlayingAudio():#If data not found, and xbmc is playing something
            #Get some variables
            self.window = xbmcgui.getCurrentWindowId()
            self.volume = xbmc.getInfoLabel("Player.Volume")
            self.volume = re.sub("dB", '', self.volume)
            self.volume = 100.00 + float(self.volume)/60.00*100.00
            self.time = xbmc.Player().getTime()
            self.plist = xbmc.PlayList(0)
            self.plsize = self.plist.size()
            self.place = self.plist.getposition()
            self.playing = xbmc.Player().getPlayingFile()
            #Write Data.xml
            f = open(DATAFILE, "wb")
            f.write("<data>\n")
            f.write("\t<window>"+str(self.window)+"</window>\n")
            f.write("\t<volume>"+str(self.volume)+"</volume>\n")
            f.write("\t<time>"+str(self.time)+"</time>\n")
            f.write("\t<plspos>"+str(self.place)+"</plspos>\n")
            f.write("\t<plsize>"+str(self.plsize)+"</plsize>\n")
            if self.plsize != "-":
                for i in range (0 , self.plsize):
                    f.write("\t<plistfile"+str(i)+">"+str(self.plist[i])+"</plistfile"+str(i)+">\n")
            f.write("\t<playing>"+str(self.playing)+"</playing>\n")
            f.write("</data>\n")
            f.close()
            #Make music fade out
            z = 100
            while z > 50:
                z = z - 2.5
                xbmc.executebuiltin("XBMC.SetVolume("+str(z)+")")
                time.sleep(.075)#seconds
            xbmc.Player().stop()
            xbmc.executebuiltin("XBMC.SetVolume(100)")
            #Shutdown
            #xbmc.shutdown()

Any help would be much appreciated. Thanks.


- Nuka1195 - 2007-02-15

You writing the object.

self.plist[i].getfilename()

http://home.no.net/thor918/xbmc/xbmc.html

Look at the playlistitem


- matthuisman - 2007-02-15

kwkard Wrote:Hi, after seeing Staley87's script to autoresume playback after a reboot (ResumeX), I decided to make my own based on some of his code. Well I've got it mostly working, but I have a small problem. In the section of the code where it writes all the current files in the playlist to data.xml, instead of the filenames it adds what's below.

Data.xml:
Code:
<data>
    <window>10020</window>
    <volume>100.0</volume>
    <time>8.78000041703</time>
    <plspos>0</plspos>
    <plsize>45</plsize>
    <plistfile0><xbmc.PlayListItem object at 0x0118E050></plistfile0>
    <plistfile1><xbmc.PlayListItem object at 0x0118E050></plistfile1>
    <plistfile2><xbmc.PlayListItem object at 0x0118E050></plistfile2>
    <plistfile3><xbmc.PlayListItem object at 0x0118E050></plistfile3>
    <plistfile4><xbmc.PlayListItem object at 0x0118E050></plistfile4>
    <plistfile5><xbmc.PlayListItem object at 0x0118E050></plistfile5>
    <plistfile6><xbmc.PlayListItem object at 0x0118E050></plistfile6>
    <plistfile7><xbmc.PlayListItem object at 0x0118E050></plistfile7>
    <plistfile8><xbmc.PlayListItem object at 0x0118E050></plistfile8>
    <plistfile9><xbmc.PlayListItem object at 0x0118E050></plistfile9>
    <plistfile10><xbmc.PlayListItem object at 0x0118E050></plistfile10>
    <plistfile11><xbmc.PlayListItem object at 0x0118E050></plistfile11>
    <plistfile12><xbmc.PlayListItem object at 0x0118E050></plistfile12>
    <plistfile13><xbmc.PlayListItem object at 0x0118E050></plistfile13>
    <plistfile14><xbmc.PlayListItem object at 0x0118E050></plistfile14>
    <plistfile15><xbmc.PlayListItem object at 0x0118E050></plistfile15>
    <plistfile16><xbmc.PlayListItem object at 0x0118E050></plistfile16>
    <plistfile17><xbmc.PlayListItem object at 0x0118E050></plistfile17>
    <plistfile18><xbmc.PlayListItem object at 0x0118E050></plistfile18>
    <plistfile19><xbmc.PlayListItem object at 0x0118E050></plistfile19>
    <plistfile20><xbmc.PlayListItem object at 0x0118E050></plistfile20>
    <plistfile21><xbmc.PlayListItem object at 0x0118E050></plistfile21>
    <plistfile22><xbmc.PlayListItem object at 0x0118E050></plistfile22>
    <plistfile23><xbmc.PlayListItem object at 0x0118E050></plistfile23>
    <plistfile24><xbmc.PlayListItem object at 0x0118E050></plistfile24>
    <plistfile25><xbmc.PlayListItem object at 0x0118E050></plistfile25>
    <plistfile26><xbmc.PlayListItem object at 0x0118E050></plistfile26>
    <plistfile27><xbmc.PlayListItem object at 0x0118E050></plistfile27>
    <plistfile28><xbmc.PlayListItem object at 0x0118E050></plistfile28>
    <plistfile29><xbmc.PlayListItem object at 0x0118E050></plistfile29>
    <plistfile30><xbmc.PlayListItem object at 0x0118E050></plistfile30>
    <plistfile31><xbmc.PlayListItem object at 0x0118E050></plistfile31>
    <plistfile32><xbmc.PlayListItem object at 0x0118E050></plistfile32>
    <plistfile33><xbmc.PlayListItem object at 0x0118E050></plistfile33>
    <plistfile34><xbmc.PlayListItem object at 0x0118E050></plistfile34>
    <plistfile35><xbmc.PlayListItem object at 0x0118E050></plistfile35>
    <plistfile36><xbmc.PlayListItem object at 0x0118E050></plistfile36>
    <plistfile37><xbmc.PlayListItem object at 0x0118E050></plistfile37>
    <plistfile38><xbmc.PlayListItem object at 0x0118E050></plistfile38>
    <plistfile39><xbmc.PlayListItem object at 0x0118E050></plistfile39>
    <plistfile40><xbmc.PlayListItem object at 0x0118E050></plistfile40>
    <plistfile41><xbmc.PlayListItem object at 0x0118E050></plistfile41>
    <plistfile42><xbmc.PlayListItem object at 0x0118E050></plistfile42>
    <plistfile43><xbmc.PlayListItem object at 0x0118E050></plistfile43>
    <plistfile44><xbmc.PlayListItem object at 0x0118E050></plistfile44>
    <playing>G:\music\Strapping Young Lad\City\01 - Velvet Kevorkian.mp3</playing>
</data>

I can't figure out why it's doing it like that. Here's the code that writes that file:
Code:
        elif not os.path.exists(DATAFILE) and xbmc.Player().isPlayingAudio():#If data not found, and xbmc is playing something
            #Get some variables
            self.window = xbmcgui.getCurrentWindowId()
            self.volume = xbmc.getInfoLabel("Player.Volume")
            self.volume = re.sub("dB", '', self.volume)
            self.volume = 100.00 + float(self.volume)/60.00*100.00
            self.time = xbmc.Player().getTime()
            self.plist = xbmc.PlayList(0)
            self.plsize = self.plist.size()
            self.place = self.plist.getposition()
            self.playing = xbmc.Player().getPlayingFile()
            #Write Data.xml
            f = open(DATAFILE, "wb")
            f.write("<data>\n")
            f.write("\t<window>"+str(self.window)+"</window>\n")
            f.write("\t<volume>"+str(self.volume)+"</volume>\n")
            f.write("\t<time>"+str(self.time)+"</time>\n")
            f.write("\t<plspos>"+str(self.place)+"</plspos>\n")
            f.write("\t<plsize>"+str(self.plsize)+"</plsize>\n")
            if self.plsize != "-":
                for i in range (0 , self.plsize):
                    f.write("\t<plistfile"+str(i)+">"+str(self.plist[i])+"</plistfile"+str(i)+">\n")
            f.write("\t<playing>"+str(self.playing)+"</playing>\n")
            f.write("</data>\n")
            f.close()
            #Make music fade out
            z = 100
            while z > 50:
                z = z - 2.5
                xbmc.executebuiltin("XBMC.SetVolume("+str(z)+")")
                time.sleep(.075)#seconds
            xbmc.Player().stop()
            xbmc.executebuiltin("XBMC.SetVolume(100)")
            #Shutdown
            #xbmc.shutdown()

Any help would be much appreciated. Thanks.

Hi! I like the fade out. Im assuming your making a version of the script that can be run from the scripts menu and save all the data and shutdown xbox etc. Helps save memory this way :-D,

I see allot of my script is in there, so a little thanks in a readme or something like that if the script is released would be considerate :-D


- User 23297 - 2007-02-15

Hi stanley, I'm the same as mrbelvedere on X-S, and yes I am giving credit to you for your code Smile No worries! I appreciate your help.

Anyway, I've got this bad boy just about done, just working out a few of the kinks, should be able to finish it tonight, if all goes well.

Nuka1195, thanks for your suggestion, that makes perfect sense now, I've already modified the code, just gotta test it tonight. I'll keep everyone posted.


- matthuisman - 2007-02-15

Oh hey!, Sweet! Let us know how it goes, i think for the Y in Viz, keymap to a new .py file with the save data and shutdown in it! it will be allot more easy :-D


- User 23297 - 2007-02-16

stanley87 Wrote:Oh hey!, Sweet! Let us know how it goes, i think for the Y in Viz, keymap to a new .py file with the save data and shutdown in it! it will be allot more easy :-D

Actually, the way I have the script coded, it can all be contained into 1 script. Just set autoexec.py to run AutoResumer, and set Y in keymap.xml (or any other way you want to launch it.) to do the same and voila. I've been having an issue with keymap though, I think I mau have a syntax error. In keymap.xml I have Y under visualizations set to:
Code:
xbmc.executescript("Q:\\scripts\\AutoResumer.py")
but it doesn't get launched. The menu for picking the visualization preset doesn't come up anymore, which is what that line replaces. Do I need single-quotes (') or double-quotes (") or back-ticks(`)? And, if I remember reading correctly, I need the double-backslashes (\\), is that correct?


- matthuisman - 2007-02-16

kwkard Wrote:Actually, the way I have the script coded, it can all be contained into 1 script. Just set autoexec.py to run AutoResumer, and set Y in keymap.xml (or any other way you want to launch it.) to do the same and voila. I've been having an issue with keymap though, I think I mau have a syntax error. In keymap.xml I have Y under visualizations set to:
Code:
xbmc.executescript("Q:\\scripts\\AutoResumer.py")
but it doesn't get launched. The menu for picking the visualization preset doesn't come up anymore, which is what that line replaces. Do I need single-quotes (') or double-quotes (") or back-ticks(`)? And, if I remember reading correctly, I need the double-backslashes (\\), is that correct?

Double backslash is correct.
single or double quotes should be ok

xbmc.executescript("Q:\\scripts\\AutoResumer.py")

This should be:xbmc.executescript("Q:\\scripts\\AutoResumer\\AutoResumer.py")
or something like that, unless your .py is just in the scripts folder.


- jmarshall - 2007-02-16

No need for \\ in a xml file. Just a single \ will do


- User 23297 - 2007-02-16

Ok, I've got the script working, but I can't seem to call it from within fullscreen visualizations.

Here's what I have in autoexec.py:
Code:
xbmc.executescript("Q:\scripts\AutoResumer\default.py")
That works, so I copied into keymap.xml:
Code:
<Visualisation>
    <remote>
      <left>PreviousPreset</left>
      <right>NextPreset</right>
      <up>IncreaseRating</up>
      <down>DecreaseRating</down>
      <back>LockPreset</back>
      <title>Info</title>
      <select>XBMC.ActivateWindow(VisualisationPresetList)</select>
      <menu>XBMC.ActivateWindow(MusicOSD)</menu>
      <start>OSD</start>
      <info>ShowPreset</info>
    </remote>

    <gamepad>
      <A>Pause</A>
      <B>Stop</B>
      [b]<Y>xbmc.executescript("Q:\scripts\autoexec.py")</Y>[/b]
      <black>ShowPreset</black>
      <white>Info</white>
      <start>XBMC.ActivateWindow(MusicOSD)</start>
      <back>LockPreset</back>
      <leftanalogtrigger>AnalogRewind</leftanalogtrigger>
      <rightanalogtrigger>AnalogFastForward</rightanalogtrigger>
      <dpadleft>SkipPrevious</dpadleft>
      <dpadright>SkipNext</dpadright>
      <dpadup>NextPreset</dpadup>
      <dpaddown>PreviousPreset</dpaddown>
    </gamepad>
  </Visualisation>

But that doesn't work, I can't execute it from fullscreen visualization mode. Any ideas?


- Nuka1195 - 2007-02-16

Quote:
xbmc.executescript("Q:\scripts\AutoResumer\default.py")

You sure that works? You need to escape the backslashes in the script.

Code:
xbmc.executescript("Q:\\scripts\\AutoResumer\\default.py")

but try
Code:
XBMC.RunScript(Q:\scripts\AutoResumer\default.py)
in the keymap


- User 23297 - 2007-02-16

Thank you for the help Nuka, that did the trick. Here is an exact copy from my autoexec.py:
Code:
xbmc.executescript("Q:\scripts\AutoResumer\default.py")
which works perfectly and now here is what's from keymap.xml:
Code:
XBMC.RunScript(Q:\scripts\AutoResumer\default.py)
which also now works perfectly.

So it would seem to me that when executing a script from python you need xbmc.executescript and double-quotes(") and when from keymap.xml you need XBMC.RunScript with no quotes.

Hopefully that should clear it up for anyone else who runs across this problem too.

Everything's done, I would like to release this for everyone, do I need a certain number of posts before I can post attachments? If attachments are disabled altogether, I will just put the code in a post.


- Nuka1195 - 2007-02-16

hmm, i'm surprised your script works without escaping the backslashes.