[SOLVED] Python: How to play just ONE random video from a folder?
#2
Since I don't like the above solution, I'm starting with a new script but as I fear, the python interpreter has some problem with common syntax.

I'm selecting the name of the videos to be played from a txt, needed for generating a list and point a variable to the right entry (for now just the first [0]).

My code:
Code:
import xbmc, imp

pvideo = open("/home/effe/Imagens/Italia/list.txt").readlines(); num = 0; curvideo = "'"+pvideo[num]+"'"
def main():
    monitor = xbmc.Monitor()
    if monitor.waitForAbort(10):
        return

    while True:
    xbmc.executebuiltin("xbmc.PlayMedia({0})".format(curvideo))
    xbmc.executebuiltin('xbmc.PlayerControl(playpause)')
    xbmc.executebuiltin("Action(Fullscreen)")
        if monitor.waitForAbort(300):
            break
if __name__ == '__main__':
    main()

The log is pretty clear, there is an issue with the file name, where there are spaces after the last character:

Code:
19:26:50 T:140083018942400  NOTICE: DVDPlayer: Opening: '/home/effe/Imagens/Italia/A Glimpse of Italy.mp4
                                            '
19:26:50 T:140083018942400 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
19:26:50 T:140081075521280  NOTICE: Thread DVDPlayer start, auto delete: false
19:26:50 T:140081075521280  NOTICE: Creating InputStream
19:26:50 T:140081075521280   ERROR: CDVDPlayer::OpenInputStream - error opening ['/home/effe/Imagens/Italia/A Glimpse of Italy.mp4
                                            ']
19:26:50 T:140081075521280  NOTICE: CDVDPlayer::OnExit()
19:26:50 T:140083018942400   ERROR: PlayMedia could not play media: '/home/effe/Imagens/Italia/A Glimpse of Italy.mp4
                                            '
19:26:50 T:140083018942400  NOTICE: CDVDPlayer::CloseFile()
19:26:50 T:140083018942400  NOTICE: DVDPlayer: waiting for threads to exit
19:26:50 T:140083018942400  NOTICE: DVDPlayer: finished waiting
19:26:50 T:140083018942400  NOTICE: CDVDPlayer::CloseFile()


Problem is the normal rstrip() or a replace (" " with "") doesn't works and the spaces are still here.

If I use directly a complete path to the file on my variable
Code:
curvideo = '/home/effe/Imagens/Italia/A Glimpse of Italy.mp4'
Kodi will accept it and will works as expected.
Any tips?
Reply


Messages In This Thread
RE: Python: How to play just ONE random video from a folder? - by effe - 2015-09-03, 00:45
Logout Mark Read Team Forum Stats Members Help
[SOLVED] Python: How to play just ONE random video from a folder?0