[RELEASE] SageTV recordings
#40
Kricker et al - see below for an updated version of this plugin that includes the following:

1. Changed "All Shows" to "[All Shows]" so that this naturally sorts as the first item (above entries like "60 Minutes")
2. Added in my suggestion above around including partial (aka Live TV) recordings so you can watch live recordings
3. Added initial POSTER ART support (it needs to be expanded, but this is a start)... it should be noted that you must have the sagex JSON APIs installed to be able to get this to work

Test it out and let me know what you think. Would love to get this into the github at some point (or feel free to give me access and I can do myself if you like).

Enjoy!

Code (this is the entire default.py file):
Code:
import urllib,urllib2,re
import xbmc,xbmcplugin,xbmcgui,xbmcaddon
import os
import unicodedata
from xml.dom.minidom import parse

__settings__ = xbmcaddon.Addon(id='plugin.video.SageTV')
__language__ = __settings__.getLocalizedString
__cwd__      = __settings__.getAddonInfo('path')

# SageTV recording Directories for path replacement
sage_rec = __settings__.getSetting("sage_rec")
sage_unc = __settings__.getSetting("sage_unc")

# SageTV URL based on user settings
strUrl = 'http://' + __settings__.getSetting("sage_user") + ':' + __settings__.getSetting("sage_pass") + '@' + __settings__.getSetting("sage_ip") + ':' + __settings__.getSetting("sage_port")

def CATEGORIES():

        iconImage = xbmc.translatePath(os.path.join(__cwd__,'resources','media','icon.png'))
        addDir('[All Shows]', strUrl + '/sage/Recordings?xml=yes',2,iconImage)
        req = urllib.urlopen(strUrl + '/sage/Recordings?xml=yes')
        content = parse(req)
        dictOfTitlesAndMediaFileIds = {}
        for showlist in content.getElementsByTagName('show'):
          strTitle = ''
          strMediaFileId = ''
          for shownode in showlist.childNodes:
            # Get the title of the show
            if shownode.nodeName == 'title':
              strTitle = shownode.toxml()
              strTitle = strTitle.replace('<title>','')
              strTitle = strTitle.replace('</title>','')
              strTitle = strTitle.replace('&amp;','&')
              strTitle = strTitle.replace('&quot;','"')
              strTitle = unicodedata.normalize('NFKD', strTitle).encode('ascii','ignore')
            # Get the mediafileid of the show
            if shownode.nodeName == 'airing':
              for shownode1 in shownode.childNodes:
                if shownode1.nodeName == 'mediafile':
                  strMediaFileId = shownode1.getAttribute('sageDbId')
                  
            if(strTitle<>""):
                dictOfTitlesAndMediaFileIds[strTitle] = strMediaFileId
            
        for strTitle in dictOfTitlesAndMediaFileIds:
            urlToShowEpisodes = strUrl + '/sage/Search?searchType=TVFiles&SearchString=' + urllib2.quote(strTitle.encode("utf8")) + '&DVD=on&sort2=airdate_asc&partials=both&TimeRange=0&pagelen=100&sort1=title_asc&filename=&Video=on&search_fields=title&xml=yes'
            print "ADDING strTitle=" + strTitle + "; urlToShowEpisodes=" + urlToShowEpisodes
            imageUrl = strUrl + "/sagex/media/poster/" + dictOfTitlesAndMediaFileIds[strTitle]
            print "ADDING imageUrl=" + imageUrl
            addDir(strTitle, urlToShowEpisodes,2,imageUrl)

def VIDEOLINKS(url,name):
        #Videolinks gets called immediately after adddir, so the timeline is categories, adddir, and then videolinks
        #Videolinks then calls addlink in a loop
        #This code parses the xml link
        req = urllib.urlopen(url)
        content = parse(req)    
        for showlist in content.getElementsByTagName('show'):
          strTitle = ''
          strEpisode = ''
          strDescription = ''
          strGenre = ''
          strAirdate = ''
          strMediaFileID = ''
          for shownode in showlist.childNodes:
            # Get the title of the show
            if shownode.nodeName == 'title':
              strTitle = shownode.toxml()
              strTitle = strTitle.replace('<title>','')
              strTitle = strTitle.replace('</title>','')
              strTitle = strTitle.replace('&amp;','&')
            # Get the episode name
            if shownode.nodeName == 'episode':
              strEpisode = shownode.toxml()
              strEpisode = strEpisode.replace('<episode>','')
              strEpisode = strEpisode.replace('</episode>','')
              strEpisode = strEpisode.replace('&amp;','&')
            # Get the show description
            if shownode.nodeName == 'description':
              strDescription = shownode.toxml()
              strDescription = strDescription.replace('<description>','')
              strDescription = strDescription.replace('</description>','')
              strDescription = strDescription.replace('&amp;','&')
            # Get the category to use for genre
            if shownode.nodeName == 'category':
              strGenre = shownode.toxml()
              strGenre = strGenre.replace('<category>','')
              strGenre = strGenre.replace('</category>','')
              strGenre = strGenre.replace('&amp;','&')
            # Get the airdate to use for Aired
            if shownode.nodeName == 'originalAirDate':
              strAirdate = shownode.toxml()
              strAirdate = strAirdate.replace('<originalAirDate>','')
              strAirdate = strAirdate.replace('</originalAirDate>','')
              strAirdate = strAirdate[:10]
              # now that we have the title, episode, genre and description, create a showname string depending on which ones you have
              # if there is no episode name use the description in the title
            if len(strEpisode) == 0:
              strShowname = strTitle+' - '+strDescription
              strPlot = strDescription
              # else if there is an episode use that
            elif len(strEpisode) > 0:
              if name == 'All Shows' or name == 'Sports':
                strShowname = strTitle+' - '+strEpisode
              elif name != 'All Shows' and name != 'Sports':
                strShowname = strEpisode
              strPlot = strDescription
            if shownode.nodeName == 'airing':
              for shownode1 in shownode.childNodes:
                if shownode1.nodeName == 'mediafile':
                  strMediaFileID = shownode1.getAttribute('sageDbId')
                  for shownode2 in shownode1.childNodes:
                    if shownode2.nodeName == 'segmentList':
                      shownode3 =  shownode2.childNodes[1]
                      strFilepath = shownode3.getAttribute('filePath')
                      addLink(strShowname,strFilepath.replace(sage_rec, sage_unc),strPlot,'',strGenre,strAirdate,strTitle,strMediaFileID)

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

def addLink(name,url,plot,iconimage,genre,airdate,showtitle,fileid):
        ok=True
        liz=xbmcgui.ListItem(name)
        strDelete = strUrl + '/sagex/api?command=DeleteFile&1=mediafile:' + fileid
        liz.addContextMenuItems([('Delete Show', 'PlayMedia(' + strDelete + ')',)])
        datesplit = airdate.split('-')
        try:
            date = datesplit[2]+'.'+datesplit[1]+'.'+datesplit[0]
        except:
            date = "01.01.1900"
        liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": plot, "Genre": genre, "date": date, "aired": airdate, "TVShowTitle": showtitle } )
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz,isFolder=False)
        return ok


def addDir(name,url,mode,iconimage):
        u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
        ok=True
        liz=xbmcgui.ListItem(name)
        liz.setInfo(type="video", infoLabels={ "Title": name } )
        liz.setIconImage(iconimage)
        liz.setThumbnailImage(iconimage)
        #liz.setIconImage(xbmc.translatePath(os.path.join(__cwd__,'resources','media',iconimage)))
        #liz.setThumbnailImage(xbmc.translatePath(os.path.join(__cwd__,'resources','media',iconimage)))
        ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
        return ok
        
              
params=get_params()
url=None
name=None
mode=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

if mode==None or url==None or len(url)<1:
        print ""
        CATEGORIES()
      
elif mode==1:
        print ""+url
        INDEX(url)
        
elif mode==2:
        print ""+url
        VIDEOLINKS(url,name)

xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_TITLE)
xbmcplugin.setContent(int(sys.argv[1]),'episodes')
xbmcplugin.endOfDirectory(int(sys.argv[1]))
Reply


Messages In This Thread
[RELEASE] SageTV recordings - by kricker - 2012-08-22, 17:07
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-22, 20:30
RE: [RELEASE] SageTV recordings - by mzup - 2012-09-05, 15:12
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-22, 20:49
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 15:43
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 16:02
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 16:38
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 16:42
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 17:57
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 18:30
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 20:42
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 21:12
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 21:27
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 21:58
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 22:05
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 22:13
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 22:16
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 22:16
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 22:18
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 22:22
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 22:33
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 22:44
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-23, 22:53
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 23:11
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-23, 23:54
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-28, 04:17
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-28, 17:30
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-28, 17:36
RE: [RELEASE] SageTV recordings - by LehighBri - 2012-08-28, 22:27
RE: [RELEASE] SageTV recordings - by dinki - 2012-08-29, 20:24
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-05, 20:48
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-29, 22:40
RE: [RELEASE] SageTV recordings - by aaronb - 2012-08-30, 01:29
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-30, 02:26
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-30, 02:31
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-30, 02:54
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-30, 03:41
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-30, 15:24
RE: [RELEASE] SageTV recordings - by kricker - 2012-08-31, 03:04
RE: [RELEASE] SageTV recordings - by erhan75 - 2012-08-31, 04:02
RE: [RELEASE] SageTV recordings - by aaronb - 2012-08-31, 05:35
RE: [RELEASE] SageTV recordings - by Skirge01 - 2012-09-04, 22:46
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-04, 22:55
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-04, 23:14
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-05, 15:46
RE: [RELEASE] SageTV recordings - by mzup - 2012-09-05, 18:23
New release - by LehighBri - 2012-09-05, 16:00
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-05, 16:03
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-12, 03:37
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-12, 03:46
RE: [RELEASE] SageTV recordings - by g-man - 2012-09-12, 19:45
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-12, 19:47
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-12, 20:45
RE: [RELEASE] SageTV recordings - by g-man - 2012-09-13, 03:14
RE: [RELEASE] SageTV recordings - by g-man - 2012-09-13, 04:46
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-13, 05:41
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-13, 14:49
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-13, 16:55
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-13, 20:08
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-13, 15:50
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-13, 15:54
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-13, 20:34
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-13, 20:54
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-13, 21:31
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-14, 03:51
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-14, 14:41
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-14, 16:47
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-14, 19:17
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-14, 19:42
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-14, 19:40
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-14, 21:59
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-14, 22:16
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-15, 02:49
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-15, 03:01
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-15, 04:06
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-15, 04:31
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-15, 05:43
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-15, 15:29
RE: [RELEASE] SageTV recordings - by dinki - 2012-09-17, 14:48
[RELEASE] SageTV recordings - by kricker - 2012-09-17, 04:23
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-18, 06:22
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-18, 06:30
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-19, 05:32
RE: [RELEASE] SageTV recordings - by pvrnorth - 2012-09-21, 15:39
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-21, 16:00
RE: [RELEASE] SageTV recordings - by pvrnorth - 2012-09-25, 15:27
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-26, 23:23
RE: [RELEASE] SageTV recordings - by urisavor - 2012-09-30, 15:10
RE: [RELEASE] SageTV recordings - by kricker - 2012-09-30, 18:31
RE: [RELEASE] SageTV recordings - by urisavor - 2012-09-30, 21:29
RE: [RELEASE] SageTV recordings - by dinki - 2012-10-01, 00:39
RE: [RELEASE] SageTV recordings - by urisavor - 2012-10-01, 01:07
RE: [RELEASE] SageTV recordings - by urisavor - 2012-10-01, 01:50
RE: [RELEASE] SageTV recordings - by kricker - 2012-10-01, 01:54
RE: [RELEASE] SageTV recordings - by urisavor - 2012-10-01, 02:09
RE: [RELEASE] SageTV recordings - by urisavor - 2012-10-01, 02:37
RE: [RELEASE] SageTV recordings - by kricker - 2012-10-01, 02:42
RE: [RELEASE] SageTV recordings - by kchase56 - 2012-10-03, 03:14
RE: [RELEASE] SageTV recordings - by kchase56 - 2012-10-23, 20:41
RE: [RELEASE] SageTV recordings - by skl111 - 2012-10-07, 07:52
RE: [RELEASE] SageTV recordings - by skl111 - 2012-10-07, 23:45
RE: [RELEASE] SageTV recordings - by kricker - 2012-10-07, 16:26
RE: [RELEASE] SageTV recordings - by kricker - 2012-10-11, 22:53
RE: [RELEASE] SageTV recordings - by kricker - 2012-10-12, 02:27
RE: [RELEASE] SageTV recordings - by pvrnorth - 2012-10-13, 04:18
RE: [RELEASE] SageTV recordings - by hoep - 2012-10-14, 11:41
RE: [RELEASE] SageTV recordings - by hoep - 2012-10-14, 15:48
RE: [RELEASE] SageTV recordings - by hoep - 2012-10-16, 21:26
RE: [RELEASE] SageTV recordings - by hoep - 2012-10-16, 21:42
RE: [RELEASE] SageTV recordings - by hoep - 2012-10-17, 21:02
RE: [RELEASE] SageTV recordings - by kricker - 2012-10-17, 21:17
RE: [RELEASE] SageTV recordings - by kricker - 2012-10-24, 17:41
RE: [RELEASE] SageTV recordings - by kricker - 2012-10-24, 18:25
RE: [RELEASE] SageTV recordings - by kricker - 2012-11-26, 22:25
RE: [RELEASE] SageTV recordings - by fventura - 2012-12-14, 04:13
RE: [RELEASE] SageTV recordings - by kricker - 2012-12-14, 06:58
RE: [RELEASE] SageTV recordings - by fventura - 2012-12-14, 07:02
RE: [RELEASE] SageTV recordings - by fventura - 2012-12-14, 07:22
RE: [RELEASE] SageTV recordings - by kricker - 2012-12-14, 17:24
RE: [RELEASE] SageTV recordings - by setherd - 2013-01-11, 06:08
RE: [RELEASE] SageTV recordings - by kricker - 2013-01-11, 06:18
RE: [RELEASE] SageTV recordings - by setherd - 2013-01-12, 14:27
RE: [RELEASE] SageTV recordings - by setherd - 2013-01-14, 03:37
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-12, 05:13
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-12, 16:44
RE: [RELEASE] SageTV recordings - by kricker - 2013-01-12, 17:17
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-12, 18:23
RE: [RELEASE] SageTV recordings - by kricker - 2013-01-12, 18:31
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-12, 18:39
RE: [RELEASE] SageTV recordings - by kricker - 2013-01-12, 18:50
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-12, 18:53
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-12, 23:18
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-13, 00:55
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-13, 15:21
RE: [RELEASE] SageTV recordings - by kricker - 2013-01-14, 02:21
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-14, 15:17
RE: [RELEASE] SageTV recordings - by kricker - 2013-01-14, 03:50
RE: [RELEASE] SageTV recordings - by setherd - 2013-01-14, 07:16
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-15, 15:18
RE: [RELEASE] SageTV recordings - by mzup - 2013-01-15, 19:12
RE: [RELEASE] SageTV recordings - by crw190 - 2013-02-19, 23:57
RE: [RELEASE] SageTV recordings - by crw190 - 2013-02-20, 01:47
RE: [RELEASE] SageTV recordings - by kricker - 2013-02-20, 01:58
RE: [RELEASE] SageTV recordings - by crw190 - 2013-02-20, 02:18
RE: [RELEASE] SageTV recordings - by crw190 - 2013-02-20, 06:28
RE: [RELEASE] SageTV recordings - by crw190 - 2013-02-20, 14:46
RE: [RELEASE] SageTV recordings - by crw190 - 2013-02-20, 15:02
RE: [RELEASE] SageTV recordings - by crw190 - 2013-02-20, 15:55
RE: [RELEASE] SageTV recordings - by sflamm - 2013-10-29, 01:17
RE: [RELEASE] SageTV recordings - by dinki - 2013-10-29, 03:17
RE: [RELEASE] SageTV recordings - by kricker - 2013-10-29, 02:51
RE: [RELEASE] SageTV recordings - by sflamm - 2013-10-30, 19:03
Version 1.5.0 Released - by LehighBri - 2013-12-10, 21:27
RE: [RELEASE] SageTV recordings - by dinki - 2013-12-10, 21:35
RE: [RELEASE] SageTV recordings - by queonda - 2014-02-13, 04:12
RE: [RELEASE] SageTV recordings - by Slack - 2014-02-04, 02:25
RE: [RELEASE] SageTV recordings - by mzup - 2014-03-09, 15:26
RE: [RELEASE] SageTV recordings - by mzup - 2014-03-09, 15:56
RE: [RELEASE] SageTV recordings - by mzup - 2014-03-09, 19:34
RE: [RELEASE] SageTV recordings - by nstocke - 2014-06-13, 16:33
RE: [RELEASE] SageTV recordings - by nstocke - 2014-06-13, 17:41
RE: [RELEASE] SageTV recordings - by crw190 - 2014-07-23, 16:47
RE: [RELEASE] SageTV recordings - by crw190 - 2014-07-23, 23:24
RE: [RELEASE] SageTV recordings - by UgaData - 2014-10-02, 16:18
RE: [RELEASE] SageTV recordings - by UgaData - 2014-10-02, 16:29
RE: [RELEASE] SageTV recordings - by cumak - 2014-11-16, 05:07
RE: [RELEASE] SageTV recordings - by waylo - 2015-02-07, 08:57
RE: [RELEASE] SageTV recordings - by waylo - 2015-03-10, 17:06
Logout Mark Read Team Forum Stats Members Help
[RELEASE] SageTV recordings2