how to play smart playlist directly?

  • Hi,

    by default, if you add your smart playlist (of music) to the favorites, it opens a window of the playlist. I'm looking for a way to play it directly.

    what i did so far:

    edited favorites.xml

    instead of openwindow, i changed it to

    >PlayMedia("special://profile/playlists/music/Soundtracks.xsp")

    this works when clicking on it on the screen.

    but when i try to play it via yatse remote:

    Play: ListItem type must be audio or video type. The type can be specified by using ListItem::getVideoInfoTag or ListItem::getMusicInfoTag, in the case of playlist entries by adding #KODIPROP mimetype value.

    it gives me this error.

    Any idea how to make it work?


    Play: ListItem type must be audio or video type. The type can be specified by using ListItem::getVideoInfoTag or ListItem::getMusicInfoTag, in the case of playlist entries by adding #KODIPROP mimetype value.

  • Code
    import xbmc
    xbmc.executebuiltin( "PlayMedia(special://profile/playlists/music/Soundtracks.xsp)" )
    xbmc.executebuiltin( "PlayerControl(repeatall)" )

    save as Soundtracks.py and use that to start your playlist

  • thats great thanks!

    and is there then a way to add soundracks.py to favorites?

    is there any preffered folder to keep it, like userdata/scripts


    edit: it doesnt want to run, do I need some addon?

    tvpc:~/.kodi/userdata/scripts # python soundtracks.py

    Traceback (most recent call last):

    File "/storage/.kodi/userdata/scripts/soundtracks.py", line 1, in <module>

    import xbmc

    ModuleNotFoundError: No module named 'xbmc'

    Edited once, last by vanja (May 17, 2023 at 5:45 PM).

  • tvpc:~/.kodi/userdata/scripts # python soundtracks.py

    Traceback (most recent call last):

    File "/storage/.kodi/userdata/scripts/soundtracks.py", line 1, in <module>

    import xbmc

    ModuleNotFoundError: No module named 'xbmc'

    it's working for me..no addons needed

    just run these 2 commands

    Code
    dos2unix /storage/.kodi/userdata/scripts/soundtracks.py
    chmod +x /storage/.kodi/userdata/scripts/soundtracks.py

    Just clicking on it from file manager should work..you can add to favourites from there...

    Edited once, last by Mario77: Merged a post created by Mario77 into this post. (May 17, 2023 at 9:56 PM).

  • it's working for me..no addons needed

    just run these 2 commands

    Code
    dos2unix /storage/.kodi/userdata/scripts/soundtracks.py
    chmod +x /storage/.kodi/userdata/scripts/soundtracks.py

    Just clicking on it from file manager should work..you can add to favourites from there...

    actually yes, clicking from the file manager works!

    I didnt even try that, I tried executing it from ssh shell - this fails with the error above.

    but when I add it to favorites (from file manager which works and plays) - the favorite does not work.

    when I play favourite soundracks.py

    info <general>: Creating Demuxer

    2023-05-19 15:03:35.785 T:875870 error <general>: Open - error probing input format, special://profile/scripts/soundtracks.py

    2023-05-19 15:03:35.785 T:875870 error <general>: OpenDemuxStream - Error creating demuxer

    2023-05-19 15:03:35.785 T:875870 info <general>: CVideoPlayer::OnExit()

    2023-05-19 15:03:35.901 T:875715 error <general>: EXCEPTION: Kodi is not playing any file

    2023-05-19 15:03:35.979 T:875687 info <general>: CVideoPlayer::CloseFile()

    2023-05-19 15:03:35.979 T:875687 info <general>: VideoPlayer: waiting for threads to exit

    2023-05-19 15:03:35.979 T:875687 info <general>: VideoPlayer: finished waiting

    so the python script that only works within file manager of kodi is not usable to me, as I am using some home automation, integration with openhab, and i want to execute certain kodi favourites in certain scenarios....so I need it to work from favourites.


    To make a smart playlist play directly, you will need to set a #KODIPROP tag on the list item. This can be done by adding something like this to your favorites.xml:

    <item>
      <label>Soundtracks</label>
      <special>PlayMedia("special://profile/playlists/music/Soundtracks.xsp")#KODIPROP=audio</special>
    </item>

    how can I add such item to favourites.xml ?

    i tried adding it inside favourites bracket:

    Code
    <favourites>    
    <favourite something/favourite>
    <item>
    <label>Soundtracks</label>
    <special>PlayMedia("special://profile/playlists/music/Soundtracks.xsp")#KODIPROP=audio</special>
    </item>
    </favourites>

    and outside:

    Code
    <favourites>    
    <favourite something/favourite>
    </favourites>
    <item>
    <label>Soundtracks</label>
    <special>PlayMedia("special://profile/playlists/music/Soundtracks.xsp")#KODIPROP=audio</special>
    </item>

    but it didnt work, it just gets ignored, not showing on favorites list...


    so to cut the story short, I'm trying to execute XSP playlist directly, without switching on the KODI screen (TV display is OFF). so it cannot be done by clicking on the screen favorites button or file manager...

    Edited 2 times, last by vanja: Merged a post created by vanja into this post. (May 19, 2023 at 12:17 PM).

  • quick workaround

    create also Soundtracks.sh in same folder of Soundtracks.py with this line

    Code
    kodi-send --action='RunScript("path/to/your/soundtracks.py")'

    then add favorite manually like this

    Code
    <favourite name="soundtracks">System.Exec(/path/to/your/Soundtracks.sh)</favourite>

    tested - working


    you can also try this might also work - not tested

    Edit: you can probably also start your playlist from the soundtracks.sh by changing line to

    Code
    kodi-send --action="PlayMedia(/some/path/to/a/file/Soundtracks.xsp)"

    I tried executing it from ssh shell - this fails with the error above.

    You can't do that it won't work as you need to run it internally so for testing in ssh you run

    Code
    kodi-send --action='RunScript("path/to/your/soundtracks.py")'

    Edited 2 times, last by Mario77: Merged a post created by Mario77 into this post. (May 19, 2023 at 1:24 PM).

  • wow, thanks a lot man! alot of useful stuff!

    managed to get the .sh file working, and I can execute it from ssh shell, it plays the xsp file!

    but when i add it to favorites (the .sh System.Exec as you suggested) it fails with some errors about audio sink...it seems it trys to play on wrong sound card or something like that...

    I'm very close now, I could even script it to execute the soundtrack.sh remotely, even though its a unneccesary complication...it would be better if it worked via favorites..

    i cannot believe i can execute the script from the remote machine but kodi is not capable of executing the script from favorites


    info <general>: CAESinkALSA - Unable to open device "surround21:CARD=PCH,DEV=0" for playback

    2023-05-19 18:18:03.868 T:880151 warning <general>: Pulseaudio module module-allow-passthrough not loaded - opening PT devices might fail

    2023-05-19 18:18:03.869 T:880151 info <general>: Found 2 Lists of Devices

    2023-05-19 18:18:03.869 T:880151 info <general>: Enumerated ALSA devices:

    2023-05-19 18:18:03.869 T:880151 info <general>: Device 1

    cut

    2023-05-19 18:18:03.869 T:880151 info <general>: Device 2

    cut

    2023-05-19 18:18:03.878 T:880152 info <general>: CAESinkALSA::InitializeHW - Your hardware does not support AE_FMT_FLOAT, trying other formats

    2023-05-19 18:18:03.878 T:880152 info <general>: CAESinkALSA::InitializeHW - Using data format AE_FMT_S32NE

    2023-05-19 18:18:03.885 T:880142 warning <general>: CGUIWindowManager - HandleAction - ignoring action 122, because topmost modal dialog closing animation is running


    EDIT: forget it, found the solution

    Cannot get script to run from favourites.xml - Kodi - CoreELEC Forums

    it seems there is a problem with .sh scripts, but .py scripts work fine from the favorites!

    So i just added py script that plays xsp as:

    <favourite name="Bla">RunScript(/storage/.kodi/userdata/playlists/music/bla.py)</favourite>

    (this is the same py script that you suggested in the first place!

    I guess adding it to favorites via right click is wrong, who knows what he did instead of RunScript.

    thanks again for your help!

    Edited 2 times, last by vanja: found solution (May 19, 2023 at 4:29 PM).

  • OK, one last question, sorry to bother but it seems you know a lot :)

    Is there a way to add party mode to favorites?

    I found some way, if you edit party mode rules, then in creates PartyMode.xsp directly in profile folder.

    I am trying to play this playlist, but it does not behave same as clicking party mode on the side menu...

    this playlist (that I defined which sources to use) looks static, its always the same songs, and more then 10 songs...

    while, when clicking on party mode on the side menu, i get random 10 songs every time...

    EDIT: If I edit further the rule, to randomize the list, and limit it to 10, then at first it looks like party mode, but its not. after 10 songs play, thats it :)

    So I dont know whats the point of calling it PartyMode.xsp when it doesnt behave like party mode...

    EDIT2: there is an addon that can activate party mode on startup or on screensaver, but I want a button to activate it when I want (when a button on the wall is pressed, script is executed etc...)

    i tail the kodi log when party mode is fired, it runs some mqsql query to the library, picks 10 songs and says party mode activated...there must be a way to trigger it

    found it:

    import xbmc

    xbmc.executebuiltin('PlayerControl(PartyMode)')

    love it :)

    Edited 3 times, last by vanja (May 19, 2023 at 8:57 PM).

  • I guess adding it to favorites via right click is wrong, who knows what he did instead of RunScript.

    Probably favorites is just added as PlayMedia by default..so your first issue is solved?

    you need something like this for partymode in your Soundtracks.py no need of addons:

    Code
    import xbmc
    xbmc.executebuiltin( "PlayerControl(Partymode(/some/path/to/a/file/Soundtracks.xsp))" )

    Edited once, last by Mario77 (May 19, 2023 at 9:55 PM).

  • Probably favorites is just added as PlayMedia by default..so your first issue is solved?

    you need something like this for partymode in your Soundtracks.py no need of addons:

    Code
    import xbmc
    xbmc.executebuiltin( "PlayerControl(Partymode(/some/path/to/a/file/Soundtracks.xsp))" )

    well, sort of. everything works on the kodi gui itself (py or sh scripts as favorites) but 3rd party apps that connect via API do not handle it well. (like yatse, openhab...)

    I guess they expect some media in favorites, and RunScript just breaks them. yatse claims invalid favourite, and some of them it cannot even see....at some point they even crash kodi by attempting to "play" scripts or whatnot.

    so I gave up and I am doing kodi-send --action='RunScript and Playmedia - from remote machine, its good enough

  • well, sort of. everything works on the kodi gui itself (py or sh scripts as favorites) but 3rd party apps that connect via API do not handle it well. (like yatse, openhab...)

    I guess they expect some media in favorites, and RunScript just breaks them. yatse claims invalid favourite, and some of them it cannot even see....at some point they even crash kodi by attempting to "play" scripts or whatnot.

    so I gave up and I am doing kodi-send --action='RunScript and Playmedia - from remote machine, its good enough

    ok so if you r doing kodi send you can still use party mode...here you go:

    Quote

    kodi-send --action="PlayerControl(Partymode(/some/path/to/a/file/Soundtracks.xsp))"

  • yes works great cheers

    And to add something...this will play directly from favourites no need of .sh or .py files

    Code
    <favourite name="my partymode playlist" thumb="/path/to/your/thumb.jpg">PlayerControl(Partymode(/storage/.kodi/userdata/playlists/music/your_smart_playlist.xsp))</favourite>