Kodi Community Forum

Full Version: Help and Questions with an addon
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
First off, I'm intoxicated, this is more of a 'I know how to string words together.' then 'I can form complete, grammer worthy sentences.'
Alright now to the point. Learned python 3 days ago, along with bash scripting, java, and improving on my C++ in the following weeks, so my mind is all over the place.
Addon: Connects to tvdb, based on the imdbnumber return from a json rpc return of the tvshow library, then also checks the episode for that show, does some nice checks and tells me what I'm missing. Nice and simple.
Uses windowXML for flexibilty, but is built up on Zag's http://forum.kodi.tv/showthread.php?tid=209948
Now while it works, I get a "Working..." loading message in the corner that I need to escape/backspace first to use the addon. I read in zags forum that someone else had the issue but either I got bored and was skimming through to fast, or no one posted an answer to it. Any clue?

https://www.dropbox.com/s/e5sda1e9rj50j3...4.png?dl=0
Notice the loading in the corner...

Also from my kodi.log:
Code:
17:50:21 T:2627918656  NOTICE: -->Python Interpreter Initialized<--
17:50:29 T:3045456256   ERROR: GetDirectory - Error getting plugin://plugin.program.hello.gui/
17:50:29 T:3045456256   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.program.hello.gui/) failed
17:50:29 T:2528074560  NOTICE: Thread BackgroundLoader start, auto delete: false
17:50:35 T:2638932800   ERROR: CPythonInvoker(14, /storage/.kodi/addons/plugin.program.hello.gui/addon.py): script didn't stop in 5 seconds - let's kill it
...stuff in between thats my fault. prints and such....
17:51:34 T:2638932800  NOTICE: Thread JobWorker start, auto delete: true
17:51:50 T:3045456256  NOTICE: Samba is idle. Closing the remaining connections
17:51:51 T:2740640576  NOTICE: Thread BackgroundLoader start, auto delete: false
17:52:08 T:2627918656  NOTICE: Previous line repeats 4 times.
17:52:08 T:2627918656  NOTICE: Thread JobWorker start, auto delete: true
17:52:17 T:2740640576  NOTICE: Thread BackgroundLoader start, auto delete: false
17:52:27 T:2740640576  NOTICE: Previous line repeats 1 times.
17:52:27 T:2740640576  NOTICE: Thread LanguageInvoker start, auto delete: false
I have no idea what is the bacground loader stuff or whats with the "CGUIMediaWindow:" stuff.


The tvdb also has a habit of not adding firstaired into the tags, I've learned this from my previous project with it, just curious on what would be a normal fix if I was using datetime.strptim, instead of checking if it exists or adding a predefined date, I chose the day tv was invented for a laugh.
Also say I was filtering by dates, and for those of us who acquire tv shows before they air (eg. supergirl leak and the such) I can only thing of just making a list, and adding them to the end.

And a random question, say I add color using [COLOR] tags when using 'addItem' why does it get rid of the focus color, for now I just use the color tag on some asterisks to tell if its missing or not.
And if anyones feeling really kind, they should visit http://www.vladstudio.com/terms/ and breakdown whether or not I can release a screensaver preloaded using their wallpaper clocks, which are beautiful btw, if I can't would I be allow to add inside the settings, a preview with a download button?

How the thing looks atm though =D
https://www.dropbox.com/s/w9p5ofju0dxvh4...5.png?dl=0

Code:
import xbmcaddon, xbmc, xbmcgui
import json, os, collections, urllib
import datetime, time, random, re
from xml.dom.minidom import parse, parseString
from collections import OrderedDict

ACTION_PREVIOUS_MENU = 10
ACTION_MOVE_LEFT = 1
ACTION_MOVE_RIGHT = 2
ACTION_NAV_BACK = 92

Addon = xbmcaddon.Addon('plugin.program.hello.gui')

__scriptname__ = Addon.getAddonInfo('name')
__path__ = Addon.getAddonInfo('path')


Excluded the tvdb query as its an extreme mess
but as a warning since this is my "Hello World" the rest of the code is still a mess and connsists of random idea's, of which most where typed on my phone using a ssh and nano ... , and copy pasting =P

the default.py:

def get_Kodi_TVShows():
    tvid_dict = OrderedDict()
    query = {
        'jsonrpc': '2.0',
        'id': 0,
        'method': 'VideoLibrary.GetTVShows',
        'params':{
        'properties': ['title', 'imdbnumber']
        }
    }
    response = json.loads(xbmc.executeJSONRPC(json.dumps(query)))
    
    
    
    for tvshow in response.get('result', {}).get('tvshows', []):
        new_dict = (("tvshowid", tvshow['tvshowid']),
                    ("imdbnumber", tvshow['imdbnumber']))
        new_dict = OrderedDict(new_dict)
        tvid_dict[tvshow['title']] = new_dict
    return tvid_dict

def get_Kodi_episodes(tvshowid):
    query = {
        'jsonrpc': '2.0',
        'id': 0,
        'method': 'VideoLibrary.GetEpisodes',
        'params':{ 'tvshowid': tvshowid,
        'properties': ['title', 'episode', 'season', 'uniqueid']
        }
    }
    response = json.loads(xbmc.executeJSONRPC(json.dumps(query)))

    episodes_dict = OrderedDict(
        (episode['title'], episode['uniqueid'])
    for episode in response.get('result', {}).get('episodes', [])
        )
    return episodes_dict

class TestGUI(xbmcgui.WindowXML):

    def onInit(self):
        self.tv_show_id = get_Kodi_TVShows()
        self.background = self.getControl (30004)
        self.background.setImage('bg.jpg')
        self.bg1 = self.getControl(30008)
        self.bg1.setImage('Shows.png')
        self.bg2 = self.getControl(30007)
        self.bg2.setImage('Episodes.png')
        self.bg1 = self.getControl(30009)
        self.bg1.setImage('ListBackground.png')
        self.bg2 = self.getControl(300010)
        self.bg2.setImage('ListBackground.png')
        self.ctl = self.getControl(30005)
        self.ctl2 = self.getControl(30006)
        for k in sorted(self.tv_show_id):
            tvshowinfo = self.tv_show_id[k]
            list1 = xbmcgui.ListItem(str(k), label2=str(tvshowinfo['tvshowid']))
            self.ctl.addItem(list1)
        self.setFocus(self.ctl)

    def onAction(self, action):
        if action == ACTION_PREVIOUS_MENU:
            self.close()
        if action == ACTION_MOVE_LEFT:
            self.setFocus(self.ctl)
        if action == ACTION_MOVE_RIGHT:
            self.setFocus(self.ctl2)
        if action == ACTION_NAV_BACK:
            self.close()

    def onClick(self, controlID):
        if controlID == 30005:
            sel_Show = self.ctl.getSelectedItem()
            self.ctl2.reset()
            episode_info = get_Kodi_episodes(int(sel_Show.getLabel2()))
            #right here we need to get the tvdb and compare with what we have in the library.
            tvdbshowid = sel_Show.getLabel()
            tvdbshowid = self.tv_show_id[str(tvdbshowid)]['imdbnumber']
            tvdb_info = Get_TVDB_eps(tvdbshowid)
            for alleps in tvdb_info:
                FullEpisodeName = tvdb_info[alleps]['episodename']
                if (FullEpisodeName in episode_info):
                    Color='ffa9a9a9'
                else:
                    FullEpisodeName='[COLOR=ffff0000]**[/COLOR]' + FullEpisodeName + '[COLOR=ffff0000]**[/COLOR]'
                self.ctl2.addItem(FullEpisodeName)
if __name__ == '__main__':
    testgui = TestGUI("TestGUI.xml", __path__, "default")
    testgui.doModal()
    del testgui

let me know if you need the tvdb code and the GUI xml.
Edit1: the images didn't seem to work in the tags from drop box so i got rid of them.
you've written a script, not a plugin.
you need to modify your addon.xml to reflect that.
Yes, I actually went through and read the top posts, one of them being, know the difference, I've rewrote the add on, and linked it to a hot key, and now am using 'ListItem' selected item, is that a good idea? I'm not sure the practices since most the stuff I found are a few years old. I'm planning on having two parts of the script, one that, like above shows all shows, and their episodes, and one that gets them based on the list Item deal, that will only show missing in a dialog window.