Log filename on movie start
#1
I am trying to log a filename on movie start. Here is my first attempt:

python:
# -*- coding: utf-8 -*-

import xbmcaddon
import xbmc, xbmcgui

__addon__      = xbmcaddon.Addon()
__addon_id__   = __addon__.getAddonInfo('id')
__addonname__  = __addon__.getAddonInfo('name')
__icon__       = __addon__.getAddonInfo('icon')
__addonpath__  = xbmc.translatePath(__addon__.getAddonInfo('path'))
__lang__       = __addon__.getLocalizedString


class MyPlayer( xbmc.Player ) :

    def __init__ ( self ):
        xbmc.Player.__init__( self )
        xbmc.log('>>>> ' + __addonname__ + ' <<<< ' + 'init')

    def onPlayBackStarted(self):
        xbmc.log('>>>> ' + __addonname__ + ' <<<< ' + 'onPlayBackStarted')

        if xbmc.Player().isPlayingVideo()==1:
            xbmc.sleep(2000) # do I need it to get file name?
            tag = xbmc.Player().getVideoInfoTag()
            path = tag.getFile() # getPath()
            xbmc.log(path.encode('utf-8'))
            #xbmc.executebuiltin('Notification(' + __addonname__ + ', ' + path.decode('utf-8') + ', 8000, ' + __icon__ + ')')

p=MyPlayer()

while(1):
    xbmc.sleep(500)

I have the following questions:
1) I am getting UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 32: ordinal not in range(128) when trying to xbmc.log. How to fix it? (NFS source is used, file path contains Russian symbols)
2) Do I need to sleep to get movie filename?
3) Do I really need to do while(1)?
4) What should I do to activate my addon at kodi start?
Reply
#2
1) see this post for best practices to avoid UnicodeDecode errors: https://forum.kodi.tv/showthread.php?tid=144677
2) in kodi v17 yes, for kodi v18 sleep shouldn't be needed if you use the onAVStarted method instead: https://codedocs.xyz/xbmc/xbmc/group__py...bdaa77aace
3) nope, you should use the abortRequested() function from the Monitor class https://codedocs.xyz/xbmc/xbmc/group__py...c82b79f1af
4) create a service addon, they get started automatically when kodi starts: https://kodi.wiki/view/Service_add-ons
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#3
Thanks!
3) did I get you correctly - still I will have infinite loop, but instead of (1) I will check for abortRequested?
Reply
#4
see the example code in the wiki link i gave you.
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#5
Thank you.
Got the following code in result - 

python:
class LastPlayed( xbmc.Player ) :

    def __init__ ( self ):
        monitor = xbmc.Monitor()
        xbmc.Player.__init__( self )

        while not monitor.abortRequested():
            if monitor.waitForAbort(10):
                break

    def onPlayBackStarted(self):
        if xbmc.Player().isPlayingVideo()==1:
           ...

LastPlayed()

Is that correct?
Reply

Logout Mark Read Team Forum Stats Members Help
Log filename on movie start0