Add movie to the database through a custom window
#1
my addon:
From a kodi video links, with the context menu I open a custom window. In this window there is a button to play the video link from the original kodi playlist.
Simulating the same effect as the info window ('' i '' key on the keyboard).
Image


Confluence skin:
In the original skin the "Play" button in the 'info' window, starts playing the video and can add this video to the kodi database, so Kodi can assign the HD / SD image and can tag as watched, can save The position that the user stopped watching the video ....
Image
Image
------------- ################ ------------

In my addon example, my button "Play movie": if I use the function "def player (url, title, iconimage):"

xbmcplugin.setResolvedUrl (int (sys.argv [1]), True, listitem)

Can not play the video from the custom window

---
If I use the function "def player_NotResolved (url, title, iconimage):"

xbmcPlayer = xbmc.Player ()
xbmcPlayer.play (item = url, listitem = listitem)


Plays the video but does not add it to the kodi database, so it does not mark the video as automatically watched.

--------------------------------

How to play a video and add it to the kodi database automatically as it was done on this skin confluence screen?


I can mark as assisted, via listitem. But I'd like you to do this automatically as in skin confluence by adding it to the kodi database.
it is possible? how to make?


my example:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import xbmc, xbmcplugin, xbmcgui, xbmc, xbmcaddon
import urllib, urllib2, re, HTMLParser, os
#########################################################################
addon_id = 'plugin.video.filmes.example'
G_header = 'Filmes'
selfAddon = xbmcaddon.Addon(id=addon_id)
addonfolder = selfAddon.getAddonInfo('path')
myFanart = addonfolder + '/resources/fanart.jpg'
#########################################################################
addon_dir = xbmc.translatePath( selfAddon.getAddonInfo('path') )
sys.path.append(os.path.join( addon_dir, 'resources', 'lib' ) )

try:
    import json
except:
    import simplejson as json



#########################################################################

def mainList():
    xbmcplugin.setContent(int(sys.argv[1]), 'movies')
    addLink('[...]Video 00 - [...]', 'http://www.vidsplay.com/wp-content/uploads/2017/05/pizza.mp4', 1, 'http://www.vidsplay.com/wp-content/uploads/2017/05/pizza-screenshot.jpg', titulo='Video000', idxItem='0', plot='test0')
    
    addLink('[...]Video 01 - [...]', 'http://www.vidsplay.com/wp-content/uploads/2017/05/us_postal.mp4', 1, 'http://www.vidsplay.com/wp-content/uploads/2017/05/us_postal-screenshot.jpg', titulo='Video001', idxItem='1', plot='test1')

    addLink('[...]Video 02 - [...]', 'http://www.vidsplay.com/wp-content/uploads/2017/05/bbqchicken.mp4', 1, 'http://www.vidsplay.com/wp-content/uploads/2017/05/bbq_chicken-screenshot.jpg', titulo='Video002', idxItem='2', plot='test2')
    
    addLink('[...]Video 03 - [...]', 'http://www.vidsplay.com/wp-content/uploads/2017/05/hamburger.mp4', 1, 'http://www.vidsplay.com/wp-content/uploads/2017/05/hamburger-screenshot.jpg', titulo='Video003', idxItem='3', plot='test3')
    
    
def addLink(name, url, mode, iconimage, titulo='', idxItem='', total=1, plot=''):
    u = sys.argv[0]+'?url='+urllib.quote_plus(url)+'&mode='+str(mode)+'&name='+urllib.quote_plus(name)+'&titulo='+urllib.quote_plus(titulo)+'&idxItem='+urllib.quote_plus(idxItem)+'&iconimage='+urllib.quote_plus(iconimage)+'&plot='+urllib.quote_plus(plot)
    
    ok = True
    liz = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
    liz.setPath(url)
    liz.setProperty('IsPlayable', 'true')

    liz.setInfo(type="Video", infoLabels={"Title": titulo, "Plot": plot})

    contextMenuItems = []
    myMenu = [
        ('[COLOR blue]Custom Infos[/COLOR]', 'XBMC.RunPlugin({0}?url={1}&mode=2&iconimage={2}&titulo={3}&name={4}&idxItem={5})'.format(sys.argv[0], urllib.quote_plus(url), iconimage, titulo, name, idxItem) )    
    ]    
    contextMenuItems = contextMenuItems + myMenu
    liz.addContextMenuItems(contextMenuItems)

    ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=False, totalItems=total)
    return ok

def player(url, titulo, iconimage):
    listitem = xbmcgui.ListItem(name, iconImage='DefaultVideo.png', thumbnailImage=iconimage)
    listitem.setPath(url)
    listitem.setInfo( type="Video", infoLabels={ "Title": titulo} )
    listitem.setProperty('mimetype', 'video/mp4')
    listitem.setProperty('IsPlayable', 'true')
    
    xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listitem)


def player_NotResolved(url, titulo, iconimage):
    listitem = xbmcgui.ListItem(name, iconImage='DefaultVideo.png', thumbnailImage=iconimage)
    listitem.setPath(url)
    listitem.setInfo( type="Video", infoLabels={ "Title": titulo} )
    listitem.setProperty('mimetype', 'video/mp4')
    listitem.setProperty('IsPlayable', 'true')
    
    xbmcPlayer = xbmc.Player()
    xbmcPlayer.play(item=url, listitem=listitem)


def log(texto):
    xbmc.log('[DEBUG - %s]: %s' %(G_header, texto), xbmc.LOGNOTICE)
    
def msg(aviso):
    dialog = xbmcgui.Dialog()
    ok = dialog.ok(G_header, aviso)
#=########################################################################################################=#
#                                               GET PARAMS                                                 #
#=########################################################################################################=#
def get_params():
    param = []
    paramstring = sys.argv[2]
    if len(paramstring) >= 2 :
        params = sys.argv[2]
        cleanedparams = params.replace('?', '')
        if (params[len(params) - 1] == '/') :
            params = params[0:len(params) - 2]
        pairsofparams = cleanedparams.split('&')
        param = {}
        for i in range(len(pairsofparams)) :
            splitparams = {}
            splitparams = pairsofparams[i].split('=')
            if (len(splitparams)) == 2:
                param[splitparams[0]] = splitparams[1]              
    return param
    
params = get_params()
url = None
name = None
mode = None
iconimage = None
titulo = None
idxItem = None

    
try:
    url = urllib.unquote_plus(params['url'])
except:
    pass

try:
    name = urllib.unquote_plus(params['name'])
except:
    pass

try:
    mode = int(params['mode'])
except:
    pass

try:
    iconimage = urllib.unquote_plus(params['iconimage'])
except:
    pass

try:
    titulo = urllib.unquote_plus(params['titulo'])
except:
    pass
    
try:
    idxItem = urllib.unquote_plus(params['idxItem'])
except:
    pass
    
try:
    plot = urllib.unquote_plus(params['plot'])
except:
    pass

#=###########################################################################################################=#
#                                                 Window Info                                                 #
#=###########################################################################################################=#
class TestWindow(xbmcgui.WindowDialog):
    def __init__(self):
        background = xbmcgui.ControlImage(120, 40, 1040, 600, 'ContentPanel.png')
        self.addControl(background)


        self.btnWatch = xbmcgui.ControlButton(310, 580, 160, 40, 'Play movie', alignment=0x00000006, font='font12')
        self.addControl(self.btnWatch)

        self.btnClose = xbmcgui.ControlButton(560, 580, 160, 40, 'Close', alignment=0x00000006, font='font12')
        self.addControl(self.btnClose)

    def onControl(self, control):
        if control == self.btnClose:
            self.close()

        if control == self.btnWatch:
            self.close()
            player_NotResolved(url, titulo, iconimage)


#=###########################################################################################################=#
#                                                   MODES                                                     #
#=###########################################################################################################=#
if mode == None or url == None or len(url) < 1 :
    mainList()

elif mode == 1 :
    player(url, titulo, iconimage)
    
elif mode == 2 :
    window = TestWindow()
    window.doModal()
    
    
###################################################################################
xbmcplugin.endOfDirectory(int(sys.argv[1]),  cacheToDisc=False)
Reply
#2
If you implement playback by any way, other than xbmcplugin.setResolvedUrl(), you need to monitor and update information about media library items being played from your own code. E.g. track in background, how much of a movie has been played and update playcount info via JSON-RPC if a certain threshold is exceeded, e.g. 95%.
Reply
#3
(2017-08-25, 12:58)Roman_V_M Wrote: If you implement playback by any way, other than xbmcplugin.setResolvedUrl(), you need to monitor and update information about media library items being played from your own code. E.g. track in background, how much of a movie has been played and update playcount info via JSON-RPC if a certain threshold is exceeded, e.g. 95%.

How to read and edit playcount via JSON-RPC, am I not succeeding at this?

This is the table: 'files' from the file: MyVideos99.db
Image
The first line was inserted via 'xbmcPlayer.play'
The second line was inserted via 'setResolvedUrl'

------------
If the file has already been added to the playlist via 'setResolvedUrl', I can read the playcount through this code:

Code:
query = {"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": { "properties": [ "playcount", "runtime", "title" ], "playlistid": 1}, "id": 1}

response = json.loads(xbmc.executeJSONRPC(json.dumps(query)))
log(str(response))

-----------
But if the file was played via 'xbmcPlayer' I did not succeed in reading and editing the information via JSON-RPC. I'm trying this code:

Code:
query = {"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": { "properties": [ "playcount" ], "movieid": 1}, "id": 1}

response = json.loads(xbmc.executeJSONRPC(json.dumps(query)))
log(str(response))

In my case, what is the correct way to edit playcount via JSON-RPC, How to edit this table: 'files', through JSON-RPC? Could someone help me?
Thank's
Reply

Logout Mark Read Team Forum Stats Members Help
Add movie to the database through a custom window0