PDA

View Full Version : python adjustments


thor918
2006-05-20, 21:12
hi just poking around in the python api,
and was a little amazed about something.
it seems we have api to turn the playlist shuffle on, but non to turn it off.
and it would be nice if the randomize playlist was exposed too.

:)

shuffle example:
http://home.no.net/thor918/xbmc/stuff/shuffle.spy

Nuka1195
2006-05-20, 21:53
can you compile your own?

if so i think you just need to send it to the existing unshuffle() function. in pyplaylist.cpp copy all the shuffle() stuff and change it to unshuffle() or i can send you the pyplaylist.cpp file.

it compiles, but i haven't tested it.

thor918
2006-05-20, 22:05
sure can compile.
but sourcechanging :p i'm not sure if i'm so good at.
but if it works, post the patch file.

if it's as simple as you say, i may give it ago.
can't see where you get the unshuffle from.
what file did you find that it was that?

Nuka1195
2006-05-20, 22:24
shuffle() and unshuffle() are in playlist.cpp.

pyplaylist.cpp already includes playlist.h so all i did was copy the existing shuffle() and change it to unshuffle().

i can send you pyplaylist.cpp, but it isn't hard to change.

i can't test it right now. if you could test it and it works you could submit the patch or i can whichever works for you. it's just the one file. i won't submit it until i know it works.

it goes in xbmc\lib\libpython\xbmcmodule\

here's a link to the file. pyplaylist.cpp (http://www.filefactory.com/get/v3/h.php?f=15cc32&b=4&c=665de5965608222f)

thor918
2006-05-20, 22:27
i see it now ;)
wonder where the random function is.
perhaps that is more work to do.

Nuka1195
2006-05-20, 22:30
i edited the link above.

what's the difference between random and shuffle?

thor918
2006-05-20, 22:34
hehe.
well random, will make the media in the playlist randomized positions,
while the shuffle will not touch the playlist, just jump.

so if you use the randomize function, the next in the playlist, will be the next song listed.

----
i have edited the file now. added unshuffle + unshuffle doc
i'm compiling a fresh build right now.

Nuka1195
2006-05-20, 22:48
a quick look, the only difference between randomize() in fileitem.cpp and shuffle() is m_bshuffled = true;

i'm thinking your descriptions are reversed. since selecting shuffle on load for playlists, the lists are shuffled.

so i guess a randomize() could be added to playlist.cpp??? it would be shuffle() minus m_bshuffled = true;? or maybe include fileitem.h

i could see the use for that. i'm not sure what's the best way to do it though.

thor918
2006-05-21, 00:14
you where right it was the oposite descriptions on those two.
anyway, the unshuffle seems to work here. ;)
but both seems to delay in updating.
if i use the shuffle/unshuffle in gui, the change takes effect at once, but doing it trough python, it will take one "play next" before it will do what it supose to do.

Nuka1195
2006-05-21, 01:10
it may need to be reset()?

if you submit a patch, the pydoc for unshuffle should be moved down just above the unshuffle object. i messed that up.

thor918
2006-05-21, 04:25
for some reson, my cvs software gives error when i try to make patch file.something must be wrong with my setup.
but i was able to create a diff file.

http://home.no.net/thor918/xbmc/stuff/unshuffle.diff

Nuka1195
2006-05-21, 07:39
edit: deleted, bad change.

Nuka1195
2006-05-21, 18:28
i tested the shuffle and unshuffle and it appears to take effect immediately.

how did you test it?

thor918
2006-05-22, 00:04
i tested this using these:
http://home.no.net/thor918/xbmc/stuff/shuffle.spy
http://home.no.net/thor918/xbmc/stuff/unshuffle.spy
http://10.0.1.9/xbmccmds/xbmchttp?command=getcurrentlyplaying
http://10.0.1.9/xbmccmds/xbmchttp?command=playnext

well after what i can read off, there is something wrong.
but since your tests shows it's working on spot, i'm a little unshure.
here is some data i wrote down.
http://home.no.net/thor918/xbmc/stuff/shuffletests2.txt

well from my testings now. the shuffle sems to be right on, but the unshuffle is not.
but maby i'm just doing the tests wrong.

Nuka1195
2006-05-22, 00:17
this is what i used.
i queued three songs to the now playing and stopped playback. i then ran the following script.
import xbmc

plist = xbmc.playlist(0)
plist.shuffle()
xbmc.player().play(plist)
print xbmc.player().getplayingfile()
xbmc.player().playnext()
print xbmc.player().getplayingfile()
xbmc.player().playnext()
print xbmc.player().getplayingfile()
xbmc.player().stop()

i alway got shuffled results.

i then tried the unshuffle and it always started playing the first song and ordered them properly. so i think it works right. do you want me to submit a patch?

by the way do you know how to get the following to work for playlist(), i couldn't.

use playlist[int position] or --getitem--(int position) to get a playlistitem.

thor918
2006-05-22, 00:37
why didn't i think of testing like that.hehe
it was easier to see if it is right now.
even esier if you use a spy file to do it.
the result is printed to the browser then.
http://home.no.net/thor918/xbmc/stuff/shuffleunshuffletest2.spy

wait.just looking on it some more.

thor918
2006-05-22, 00:56
you see if just the shuffle/unshuffle is called and your not loading the playlist "xbmc.player().play(plist)".
the output will change.
the loading of playlist will result in first song in playlist is selected.

what i was thinking of was toggeling on off the shuffling, without changing the currently playing song. like in the gui, when you are turning the shuffle on off, the song currently playing does not change before the user for example pushes a button.

if you see on the test:

shuffle

smb://10.0.1.47/p/complete/musikk/2004 - frail (192kb)/04 - take my heart away.mp3
smb://10.0.1.47/p/complete/musikk/2004 - frail (192kb)/10 - because i'm dead.mp3
smb://10.0.1.47/p/complete/musikk/2004 - frail (192kb)/04 - take my heart away.mp3

unshuffle

smb://10.0.1.47/p/complete/musikk/2004 - frail (192kb)/07 - natural scilence.mp3

look at the last shuffled file.
*04 is playing,
*unshuffle command is called,
*next song button is pushed.

04. next song should be 05
but it selected 07

but still it seems like it's just unshuffle that is not right on.
do you see what i'm talking about now?

Nuka1195
2006-05-22, 02:18
yes, i understand now. as i said before or meant to, the player needs to be reset. i thought i did it, but it was late and i ended up resetting the whole xbox. :)

i look into it some more, may need a developer though.

Nuka1195
2006-05-22, 02:58
what the code is doing is i think:

1. get's the currently playing song.
2. shuffles/unshuffles
3. cycles through the playlist to find the same song.
4. sets the currently playing song to this.

i think if you tested some more you would find that the shuffle isn't necessarily playing the next correct song either.

could this be done in python?

i'll look some more, but a developer probably would have to change this.

here's (http://www.wikiupload.com/download_page.php?id=3039) a script that has one button and allows you to shuffle/unshuffle the playlist.

queue a few items first then run the script. i used the web server to view the playlist.