Manromen/script.TraktUtilities — Issue #112: Absolute ordering - conversion to season and episode
Author: mizaki
Created: 2011-12-19 17:44:53+00:00
State: open

Trakt does not support the scrobbling of absolute (or DVD) ordering. It would be nice if TU could convert to SE. I have hacked the original scrobbler addon to convert absolute. I'll paste the code below which is not nice and the method probably worse. There may be a better way but currently I believe there is no inbuilt method to retrieve the ordering of a source.

default.py: line 81+
```Python
if len(xbmc.getInfoLabel("VideoPlayer.TVshowtitle")) >= 1: # TvShow
sType = "TVShow"
Debug("Found TV Show", False)

# format: title, year, season, episode, tvdbid
showname = xbmc.getInfoLabel("VideoPlayer.TvShowTitle")
showname = showname.replace(",", '')
year_for_id = xbmc.getInfoLabel("VideoPlayer.Year")
showID = getID(sType, xbmc.getInfoLabel("VideoPlayer.TvShowTitle"), year_for_id)
isAbsolute = getAbsolute(xbmc.getInfoLabel("VideoPlayer.TvShowTitle"), year_for_id)
if isAbsolute == True:
# Grab episode info from TheTVDB as Trakt does not store absolute numbers (yet?)
episodeNumber = xbmc.getInfoLabel("VideoPlayer.Episode")
responce = urllib2.urlopen('http://www.thetvdb.com/api/89650AFEDB3B66C8/series/' + showID + '/absolute/' + episodeNumber)
TVDBres = responce.read()
#Debug("TVDB Ep: " +TVDBres)
Ep = str(re.findall('\(\d+)\<\/EpisodeNumber\>',TVDBres))
Ep = Ep.strip('[\']')
Sea = str(re.findall('\(\d+)\<\/SeasonNumber\>',TVDBres))
Sea = Sea.strip('[\']')
title = (showname +
',' + xbmc.getInfoLabel("VideoPlayer.Year") +
',' + addPadding(Sea) +
',' + addPadding(Ep))
else:
title = (showname +
',' + xbmc.getInfoLabel("VideoPlayer.Year") +
',' + addPadding(xbmc.getInfoLabel("VideoPlayer.Season")) +
',' + addPadding(xbmc.getInfoLabel("VideoPlayer.Episode")))
```

resources/utilites.py:
```Python
def getAbsolute(title, year=False):
#Debug("Absolute check for: "+title, False)
isAb = ""

# Get idShow
queryid = "select idShow from tvshow where lower(c00) = lower('" + title + "') limit 1"
res = xbmc.executehttpapi("queryvideodatabase(" + queryid + ")")
showID = str(re.findall('(.*?)',res)) # find it
showID = showID.strip('[\']')
#Debug("queryid: " + queryid)
#Debug("showID: " +showID)
# Get idPath
querypathID = "select idPath from tvshowlinkpath where idShow='" + showID + "' limit 1"
res = xbmc.executehttpapi("queryvideodatabase(" + querypathID + ")")
showPathID = str(re.findall('(.*?)',res)) # find it
showPathID = showPathID.strip('[\']')
#Debug("queryid: " + querypathID)
#Debug("showPathID: " +showPathID)
# Get path
queryPath = "select strPath from path where idPath='" + showPathID + "' limit 1"
res = xbmc.executehttpapi("queryvideodatabase(" + queryPath + ")")
showPath = str(re.findall('(.*?)',res)) # find it
showPath = showPath.strip('[\']')
#Debug("queryid: " + queryPath)
#Debug("showPath: " +showPath)
# Get file path settings
querySettings = "select strSettings from path where idPath='" + showPathID + "' limit 1"
res = xbmc.executehttpapi("queryvideodatabase(" + querySettings + ")")
showPathSettings = str(re.findall('(.*?)',res)) # find it
showPathSettings = showPathSettings.strip('[\']')
#Debug("showPathSettings:"+showPathSettings)
#Debug("querySettings: " + querySettings)

# Check settings isn't blank. If so look up info from root path
if (showPathSettings == ''):
# Linux only? \ for Windows?
showPath = showPath[:len(showPath)-1]
trimTVtitle = showPath.rfind(os.sep)-len(showPath)
# Debug("Path: " +showPath)
showPath = showPath[:trimTVtitle+1]
#Debug("Path trim length: " + str(trimTVtitle))
querySettings = "select strSettings from path where strPath='" + showPath + "' limit 1"
#Debug("Root query: " + querySettings)
res = xbmc.executehttpapi("queryvideodatabase(" + querySettings + ")")
showPathSettings = str(re.findall('(.*?)',res)) # find it
showPathSettings = showPathSettings.strip('[\']')
#Debug("showPathSettings for root dir:"+showPathSettings)
# Check if absoulte is true
abso = str(re.findall('.*absolutenumber.\svalue\=.(\w+).',showPathSettings))
abso = abso.strip('[\']')
#Debug("abso: " +abso)
if (abso == "true"):
isAb = True
else:
isAb = False
Debug("Using absolute for:" + title + " is " + str(isAb), False)
return isAb
```

In summary it looks up the path of the show. If the show is using the same settings as the root source it's empty. If it's empty it looks up the root source and gets the info from there.