[RELEASE] SageTV recordings

  Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
LehighBri Offline
Senior Member
Posts: 237
Joined: Jan 2009
Reputation: 0
Post: #11
Making some progress. Add the following code to the bottom of the CATEGORIES method. Sorting still needs to be figured out... but it's a start on the path to having first the directory structure show the show titles, then you can drill into that to see the episodes:

Code:
req = urllib.urlopen(strUrl + '/sage/Recordings?xml=yes')
        content = parse(req)
        uniqueListOfShowTitles = []
        for showlist in content.getElementsByTagName('show'):
          strTitle = ''
          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>','')
              if strTitle not in uniqueListOfShowTitles:
                uniqueListOfShowTitles.append(strTitle)
                addDir(strTitle, strUrl + '/sage/Search?searchType=TVFiles&SearchString=' + strTitle + '&DVD=on&sort2=airdate_asc&TimeRange=0&pagelen=100&sort1=title_asc&filename=&Video=on&search_fields=title&xml=yes',2,'icon.png')
(This post was last modified: 2012-08-23 17:45 by LehighBri.)
find quote
dinki Offline
Member
Posts: 65
Joined: Jun 2008
Reputation: 0
Post: #12
I've tried modifying the CATEGORIES function like this:

Code:
def CATEGORIES():

        strUrl = 'http://' + __settings__.getSetting("sage_user") + ':' + __settings__.getSetting("sage_pass") + '@' + __settings__.getSetting("sage_ip") + ':' + __settings__.getSetting("sage_port")
        addDir('All Shows', strUrl + '/sage/Recordings?xml=yes',2,'icon.png')
        addDir('Safety Patrol',strUrl + '/sage/Search?searchType=TVFiles&SearchString=Safety%20Patrol&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')
    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')
    
    req = urllib.urlopen(strUrl + '/sage/Search?SearchString=&searchType=TVFiles&Video=on&xml=yes')
    content = parse(req)
    for showlist in content.getElementsByTagName('show'):
        strTitle= ''
        strTitleSearch = ''
        strCheckTitle = ''    
        for shownode in showlist.childNodes:
            # Get the title of the show

            if (shownode.nodeName == 'title') and (shownode.nodeName != strCheckTitle):
                strTitle = shownode.toxml()
                    strTitle = strTitle.replace('<title>','')
                    strTitle = strTitle.replace('</title>','')
                          strTitle = strTitle.replace('&amp;','&')
                          strTitleSearch = strTitle.replace(' ','%20')
                          strCheckTitle = StrTitle
                          addDir(strTitle,strUrl + '/sage/Search?searchType=TVFiles&SearchString=' + strTitleSearch + '&DVD=on&sort2=airdate_asc&TimeRange=0&pagelen=100&sort1=title_asc&filename=&Video=on&search_fields=title&xml=yes',2,'dailyshow.jpg')

The first few lines were just a test to see if I could get the folders to appear. They did and it works great. I then tried copying a portion from VIDEOLINKS function to try and pull the title names from a generic show-all-recordings type query on the sage server. I'm doing a check to make sure we only send the title once to the addDir function. I'm getting an error but I'm not sure where. Can someone spot what I'm doing wrong? I'm a hacker, not a programmer, so any help would be great.
find quote
kricker Offline
Team-XBMC QA Specialist
Posts: 3,308
Joined: Apr 2004
Reputation: 16
Location: Knoxville, TN
Post: #13
LehighBri,

That works well. Looks like we need to do some fixing of special characters like "&" though. Right now they show up as &amp;

Read this before using these builds.
XBMC win32 SVN builds
Changelog
find quote
LehighBri Offline
Senior Member
Posts: 237
Joined: Jan 2009
Reputation: 0
Post: #14
I fixed the ampersand in the title issue and also sorted the shows initially in alphabetical order. Try this (just copy over your existing CATEGORIES function)

Code:
def CATEGORIES():
        strUrl = 'http://' + __settings__.getSetting("sage_user") + ':' + __settings__.getSetting("sage_pass") + '@' + __settings__.getSetting("sage_ip") + ':' + __settings__.getSetting("sage_port")
        addDir('All Shows', strUrl + '/sage/Recordings?xml=yes',2,'icon.png')
        req = urllib.urlopen(strUrl + '/sage/Recordings?xml=yes')
        content = parse(req)
        uniqueListOfShowTitles = []
        for showlist in content.getElementsByTagName('show'):
          strTitle = ''
          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;','&')
              if strTitle not in uniqueListOfShowTitles:
                uniqueListOfShowTitles.append(strTitle)

        uniqueListOfShowTitles.sort()
        for strTitle in uniqueListOfShowTitles:
            urlToShowEpisodes = strUrl + '/sage/Search?searchType=TVFiles&SearchString=' + urllib2.quote(strTitle.encode("utf8")) + '&DVD=on&sort2=airdate_asc&TimeRange=0&pagelen=100&sort1=title_asc&filename=&Video=on&search_fields=title&xml=yes'
            print "ADDING strTitle=" + strTitle + "; urlToShowEpisodes=" + urlToShowEpisodes
            addDir(strTitle, urlToShowEpisodes,2,'icon.png')
find quote
dinki Offline
Member
Posts: 65
Joined: Jun 2008
Reputation: 0
Post: #15
@LehighBri ... I'm trying to use your modification but am having trouble due to a special character in one of the program names. The title contains the é character. I'm getting this error:

Code:
13:27:55 T:1232   ERROR: Error Type: <type 'exceptions.UnicodeEncodeError'>
13:27:55 T:1232   ERROR: Error Contents: 'ascii' codec can't encode character u'\xe9' in position 18: ordinal not in range(128)
13:27:55 T:1232   ERROR: Traceback (most recent call last):
                                              File "C:\Users\Donny\AppData\Roaming\XBMC\addons\plugin.video.SageTV\default.py", line 159, in <module>
                                                CATEGORIES()
                                              File "C:\Users\Donny\AppData\Roaming\XBMC\addons\plugin.video.SageTV\default.py", line 32, in CATEGORIES
                                                print "ADDING strTitle=" + strTitle + "; urlToShowEpisodes=" + urlToShowEpisodes
                                              File "<string>", line 6, in write
                                            UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 18: ordinal not in range(128)
13:27:55 T:6424   ERROR: XFILE::CDirectory::GetDirectory - Error getting plugin://plugin.video.SageTV
13:27:55 T:6424   ERROR: CGUIMediaWindow::GetDirectory(plugin://plugin.video.SageTV) failed

*EDIT* Figured out how to sanitize the content. You need to:

Code:
import unicodedata

and add to the section where the & are fixed:
Code:
strTitle = unicodedata.normalize('NFKD', strTitle).encode('ascii','ignore')
(This post was last modified: 2012-08-23 20:47 by dinki.)
find quote
LehighBri Offline
Senior Member
Posts: 237
Joined: Jan 2009
Reputation: 0
Post: #16
Great. Thoughts on how to fix the date sorting piece? I can sort by title in XBMC, ascending, descending, but when I choose sort by date, nothing happens.
find quote
dinki Offline
Member
Posts: 65
Joined: Jun 2008
Reputation: 0
Post: #17
Does XBMC even recognize 'aired date' as a date? That might be why it's not sorting.

Noticed another special character that will need to be handled: '&quot;' Also, does anyone know how to keep the view as 'Media info' instead of the default 'list' view?

I may be wrong, but can't we get more information from SageX instead of the Nielm's web server? I think we might be able to pull more meta data that way and perhaps even get the fan art to use as the icon.png.
(This post was last modified: 2012-08-23 21:12 by dinki.)
find quote
LehighBri Offline
Senior Member
Posts: 237
Joined: Jan 2009
Reputation: 0
Post: #18
(2012-08-23 21:12)dinki Wrote:  I may be wrong, but can't we get more information from SageX instead of the Nielm's web server? I think we might be able to pull more meta data that way and perhaps even get the fan art to use as the icon.png.

The only requirement here is to assume the sagex plugin is installed. It won't work without it. I am very familiar with how to do that as I spend significant time building the Plex-SageTV Agent to enable integration there (which uses the sagex calls).

If we take that approach, then the skies the limit, and we can easily pull in all metadata, all images, etc.

We would also have access to the entire SageTV API here: http://download.sage.tv/api/index-all.html

And here's the python code for the Plex-SageTV agent that pulls various metadata from Sage (see line 251 for example for urls that could be used for the images): http://code.google.com/p/sagetv-for-plex..._init__.py
find quote
dinki Offline
Member
Posts: 65
Joined: Jun 2008
Reputation: 0
Post: #19
What has been done here works, but I would love to see a much better integration with XBMC. It would be great if an add on could monitor the Sage recording directory and pull those files into the XBMC TV Shows listings with all meta data. I know that programs without season/episode information would be a problem but I think you guys had a workaround in the Plex scanner?
find quote
LehighBri Offline
Senior Member
Posts: 237
Joined: Jan 2009
Reputation: 0
Post: #20
We did (e.g. we used "year" for the season # for example when one didn't exist). What you're talking about would be a SageTV-specific scraper. I have no clue where to start but I learned the Plex API/framework pretty easily. Is there a "simple" scraper that we could look at that could be used as a basis. Once the basic "plumbing" is in place, the Plex agent logic should be very transferrable (at least in concept).
find quote
Post Reply