Help with adding leading '0' to Season/Episode numbers for simple little add-on

Tikipeter

New member
Apr 22, 2014
86
0
0
Hi all.

I'm trying desperately to put together a little Furk related context menu add-on. The idea is you can use it to search for content on 'What The Furk' or Furk's own 'Furk' add-on from anywhere within the Kodi library or other add-ons. It does work at the moment, but I have almost zero python knowledge and just edited phil65's extended info context menu add-on to fit what I needed it to do.

The only major problem I have, is I'm using Kodi's 'info.getSeason()' and 'info.getEpisode()' to grab the season and episode number. They return 1 digit numbers in the 0-9 range. I need to pad these with a leading zero i.e. 's01e07', not s1e7. Can someone point me to a way to achieve this?

I thought I was on the right track with trying to get a grasp of regex, but it's REALLY hard to get my head around, and from what I understand regex is used really for pulling out parts of, or breaking up, strings (really worth learning though, as it would be used a lot with add-on scrapers).

Does some kind soul here knowledgable in this stuff suggest how I am best to add a leading zero when needed?

I'll include below the (very simple) code for the WTF part of the add-on:

Code:
import xbmc
import sys

def main():
    info = sys.listitem.getVideoInfoTag()
    dbid = info.getDbId()
    db_type = info.getMediaType()
    movie_title = info.getTitle()
    movie_year = info.getYear()
    tvshow_title = info.getTVShowTitle()
    tvshow_season = info.getSeason()
    tvshow_episode = info.getEpisode()
    BASE1 = "ActivateWindow(10025,plugin://plugin.video.whatthefurk/?"
    #BASE2 = "RunPlugin(plugin://plugin.video.whatthefurk/?"
    if not dbid:
        dbid = sys.listitem.getProperty("dbid")
    if db_type == "movie":
        url = "%sname=%s (%s)&url=imdb&mode=1008&iconimage=blank&rootname=%s (%s)&imdb=blank&videotype=movies)" % (BASE1, movie_title, movie_year, movie_title, movie_year)
        url = str(url)
    elif db_type == "episode":
        url = "%siconimage=blank&imdb=blank&mode=1008&name=%s S%sE%s&parms=na&rootname=%s S0%sE0%s&start=na&url=url&videotype=tvshows,return)" % (BASE1, tvshow_title, tvshow_season, tvshow_episode, tvshow_title, tvshow_season, tvshow_episode)
        url = str(url)
    xbmc.executebuiltin(url)

if __name__ == '__main__':
    main()
Any help would be greatly appreciated. :) :) :)
 

gujal

Developer
Dec 26, 2013
450
224
43
Try this way
Code:
import xbmc
import sys

def main():
    info = sys.listitem.getVideoInfoTag()
    dbid = info.getDbId()
    db_type = info.getMediaType()
    movie_title = info.getTitle()
    movie_year = info.getYear()
    tvshow_title = info.getTVShowTitle()
    tvshow_season = info.getSeason()
[COLOR="#FF0000"]    if len(tvshow_season) < 2:
        tvshow_season = '0' + tvshow_season[/COLOR]
    tvshow_episode = info.getEpisode()
[COLOR="#FF0000"]    if len(tvshow_episode) < 2:
        tvshow_episode = '0' + tvshow_episode[/COLOR]
    BASE1 = "ActivateWindow(10025,plugin://plugin.video.whatthefurk/?"
    #BASE2 = "RunPlugin(plugin://plugin.video.whatthefurk/?"
    if not dbid:
        dbid = sys.listitem.getProperty("dbid")
    if db_type == "movie":
        url = "%sname=%s (%s)&url=imdb&mode=1008&iconimage=blank&rootname=%s (%s)&imdb=blank&videotype=movies)" % (BASE1, movie_title, movie_year, movie_title, movie_year)
        url = str(url)
    elif db_type == "episode":
        url = "%siconimage=blank&imdb=blank&mode=1008&name=%s S%sE%s&parms=na&rootname=%s S0%sE0%s&start=na&url=url&videotype=tvshows,return)" % (BASE1, tvshow_title, tvshow_season, tvshow_episode, tvshow_title, tvshow_season, tvshow_episode)
        url = str(url)
    xbmc.executebuiltin(url)

if __name__ == '__main__':
    main()
 

Tikipeter

New member
Apr 22, 2014
86
0
0
I can't thank you enough gujal!
It didn't work at first, then I realised I had to convert 'tvshow_season' and 'tvshow_episode' into a string first. Then it worked.
Thank you very much for helping me. :) :) :) :) :)