SageTV Integration - Movies and TV Shows archiving compatible with XBMC

  Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
bradvido88 Offline
Donor
Posts: 796
Joined: Nov 2008
Reputation: 9
Location: MN
Post: #196
pkscuot Wrote:Just to let you know, I figured out a way to get everything to be stable. I turned off the external JSON and HTTP interfaces (this tool was the only thing using them), and now everything runs correctly. For some reason getting no response to the JSON request is OK, but getting one from Eden isn't. Anyway, this will allow me to limp through until I migrate to something else. I appreciate all the work you've put into this. It had made XBMC usable for us.

BTW, to replace the quick library updates, I updated the XBMC Library Auto Updater to allow you to do some more advanced scheduling. So I now have SAGETV-XBMC running at 10 minutes past and 40 minutes past the hour and then have XBMC updating my library at 15 minutes past and 45 minutes past the hour. I've asked robweber if he wants to see the changes and potentially incorporate them into the main release.

It's a little more brute force, but it does work.

Cool. Looks like that will work for the meantime.
If you want to disable the auto-update from this script, just change the Config.xml
from
<XBMCAutoUpdate enabled="true">
to
<XBMCAutoUpdate enabled="false">

Also, the PVR branches are up-to-date (for Windows at least).
The Eden Beta2 PVR build is available here:
http://www.scintilla.utwente.nl/~marcelg....html#eden

XBMC.MyLibrary (add anything to the library)
ForTheLibrary (Argus TV & XBMC Library PVR Integration)
SageTV & XBMC PVR Integration
(This post was last modified: 2012-02-08 17:33 by bradvido88.)
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,450
Joined: Apr 2004
Reputation: 20
Location: Knoxville, TN
Post: #197
bradvido88, have you seen the thread on the Sage forums regarding Sage and Plex integration? Essentially what they did was write a custom scraper for Plex that talks to a Sage Plugin. This allows the files to be added to the library with all the Sage info. Seems like a pretty smart idea. If we knew someone good with XBMC scrapers, maybe we can get it ported over to XBMC. I do not know how close Plex's and XBMC's scrapers are.

Why are all the other PVR backends a PIA to setup? FTR was promising until I realized it doesn't work with my analog encoder. Most of my son's cartoons are still on non-HD analog channels. Not having that isn't an option. I've tried migrating from Sage, but the other backends have just not cut it at this point.

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
xj-boonie Offline
Junior Member
Posts: 12
Joined: Jul 2012
Reputation: 0
Post: #198
I was a sage user for years but now am trying to live without cable and am using xbmc. But I'd like to be able to access all the shows instill have on sage. Will this let me?

Thanks
Mike
find quote
aaronb Offline
Senior Member
Posts: 204
Joined: Apr 2007
Reputation: 0
Location: Colorado
Post: #199
(2012-07-29 16:43)xj-boonie Wrote:  I was a sage user for years but now am trying to live without cable and am using xbmc. But I'd like to be able to access all the shows instill have on sage. Will this let me?

Thanks
Mike

This should work for your needs. Or if you don't care about having them integrated into the XBMC library I wrote an add-on that will connect to your Sage server and display all of your content with library views and all the metadata
find quote
LehighBri Offline
Fan
Posts: 316
Joined: Jan 2009
Reputation: 0
Post: #200
(2012-07-29 19:52)aaronb Wrote:  
(2012-07-29 16:43)xj-boonie Wrote:  I was a sage user for years but now am trying to live without cable and am using xbmc. But I'd like to be able to access all the shows instill have on sage. Will this let me?

Thanks
Mike

This should work for your needs. Or if you don't care about having them integrated into the XBMC library I wrote an add-on that will connect to your Sage server and display all of your content with library views and all the metadata

Where can I get access to that add on you mention?
find quote
aaronb Offline
Senior Member
Posts: 204
Joined: Apr 2007
Reputation: 0
Location: Colorado
Post: #201
(2012-07-29 20:21)LehighBri Wrote:  
(2012-07-29 19:52)aaronb Wrote:  
(2012-07-29 16:43)xj-boonie Wrote:  I was a sage user for years but now am trying to live without cable and am using xbmc. But I'd like to be able to access all the shows instill have on sage. Will this let me?

Thanks
Mike

This should work for your needs. Or if you don't care about having them integrated into the XBMC library I wrote an add-on that will connect to your Sage server and display all of your content with library views and all the metadata

Where can I get access to that add on you mention?

Headed out right now, but I will post it later this evening
find quote
aaronb Offline
Senior Member
Posts: 204
Joined: Apr 2007
Reputation: 0
Location: Colorado
Post: #202
Here's the addon I wrote. I didn't know how to package it so it requires manual installation, if anyone wants to make it an installable zip that would be awesome. This requires having the SageTV webserver installed. I've tested it with SageTV 6 and 7.

Create a new folder in your addons directory named SageTV, and save this code into Default.py. Lines 7 and 99 need to be edited for your setup with username, password, IP address and port. Line 76 needs your paths for where SageTV files are stored locally and the network address. For the IP stuff in lines 7 and 99 I made it generic, line 76 I left with my info so you can see how to set it up

Lines 9 and 10 that are commented out have some examples of how you can create subdirectories for your shows based on show title, genre, or anything else you want, just perform the search in the Sage web interface and copy/paste the URL into the addon code.

Code:
import urllib,urllib2,re
import xbmc,xbmcplugin,xbmcgui
import os
from xml.dom.minidom import parse

def CATEGORIES():
        strUrl = 'http://user:password@sage IP:port'
        addDir('All Shows', strUrl + '/sage/Recordings?xml=yes',2,'icon.png')
        #addDir('The Daily Show',strUrl + '/sage/Search?searchType=TVFiles&SearchString=Daily%20show&DVD=on&sort2=airdate_asc&TimeRange=0&pagelen=100&sort1=title_asc&filename=&Video=on&search_fields=title&xml=yes',2,'dailyshow.jpg')
        #addDir('Sports',strUrl + '/sage/Search?searchType=TVFiles&Categories=Sports+event&SearchString=&xml=yes',2,'sports.jpg')

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('D:\\SageTV\\','smb://sagetv/SageRecordings/'),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 = 'http://user:password@sage IP:port/sagex/api?command=DeleteFile&1=mediafile:' + fileid
        liz.addContextMenuItems([('Delete', 'PlayMedia(' + strDelete + ')',)])
        liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": plot, "Genre": genre, "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="TV Show", infoLabels={ "Title": name } )
        liz.setIconImage(xbmc.translatePath(os.path.join(os.getcwd().replace(';', ''),'resources','media',iconimage)))
        liz.setThumbnailImage(xbmc.translatePath(os.path.join(os.getcwd().replace('​;', ''),'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]))

Then you need to create a file called addon.xml in that same directory, with the following content:

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.program.SageTV"
       name="SageTV"
       version="1.0.0"
       provider-name="">
  <requires>
    <import addon="xbmc.python" version="1.0"/>
  </requires>
  <extension point="xbmc.python.pluginsource"
            library="default.py">
        <provides>video</provides>
  </extension>
  <extension point="xbmc.addon.metadata">
    <platform>all</platform>
    <summary>SageTV plugin</summary>
    <description>connect to SageTV library</description>
  </extension>
</addon>

you can also create a subdirectory in the addon folder called /resources/media and save images there so that folders have artwork. You'll see in the addon code I have icon.png, dailyshow.png, etc. Put images there and put the appropriate name in the code and your categories you add will get images. I just had the SageTV icon saved as icon.png for the main listing,

I hope this is clear enough, it was my first addon and I was able to write the code but never learned how to properly package it. It should be very straightforward to setup, but let me know if you have questions.

If anyone that wants to package this into an easily installed addon and/or improve the code that would be great
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,450
Joined: Apr 2004
Reputation: 20
Location: Knoxville, TN
Post: #203
aaronb,

This "add-on" works pretty good. I'll see if I can add some settings so users can enter their custom stuff.

Read this before using these builds.
XBMC win32 SVN builds
Changelog
(This post was last modified: 2012-09-27 06:19 by kricker.)
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,450
Joined: Apr 2004
Reputation: 20
Location: Knoxville, TN
Post: #204
Addon created and posted on git hub. New thread created here.

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
pkscout Online
Posting Freak
Posts: 1,098
Joined: Jan 2011
Reputation: 23
Location: Honolulu, HI
Post: #205
Just an FYI that I think the latest update to the sage-x-services in SageTV break this tool. I upgraded yesterday and noticed this evening that shows were not getting moved into XBMC. The log file shows a bunch of errors that lead me to believe something changed with the XML that is delivered. I reverted back to the old sage-x-services stuff and it works fine now.

Since I don't think this tool is being actively maintained any longer, I'd advise against updating your sage-x-services plugin.
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,450
Joined: Apr 2004
Reputation: 20
Location: Knoxville, TN
Post: #206
pkscuot,
You might want to check out this add-on.

Read this before using these builds.
XBMC win32 SVN builds
Changelog
(This post was last modified: 2012-09-27 06:18 by kricker.)
find quote
pkscout Online
Posting Freak
Posts: 1,098
Joined: Jan 2011
Reputation: 23
Location: Honolulu, HI
Post: #207
@kricker, thanks for the suggestion. The thing is, I really like having the stuff from SAGETV integrated into my video library, and it doesn't look like that add-on does that. As far as I can tell there is nothing interesting or necessary with the new sage-x-services, so I can live with what I have.
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,450
Joined: Apr 2004
Reputation: 20
Location: Knoxville, TN
Post: #208
Maybe one day we could get an actual PVR addon for Sage or a scraper that can import the items. Until then, all we have are these "hacks".

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
bradvido88 Offline
Donor
Posts: 796
Joined: Nov 2008
Reputation: 9
Location: MN
Post: #209
(2012-09-27 16:39)kricker Wrote:  Maybe one day we could get an actual PVR addon for Sage or a scraper that can import the items. Until then, all we have are these "hacks".

The problem is none of the XBMC PVR development is focusing on Sage since its future is unknown.

XBMC.MyLibrary (add anything to the library)
ForTheLibrary (Argus TV & XBMC Library PVR Integration)
SageTV & XBMC PVR Integration
find quote
GoodCode Offline
Junior Member
Posts: 14
Joined: Apr 2013
Reputation: 1
Post: #210
I really like this tool...two questions though:

A number of my shows have an (incorrect) SeasonNumber value of "0" in their properties files. It appears that this tool will not attempt to get the Season number from TVDB if any season number exists in the properties file (even "bad seasons"). Is there any way to get around this?

Also, any chance of this project being open-sourced? The log file is very good, but it would be much easier to debug some issues if the source were available....
find quote
Post Reply