mythtvstruct.py :  » Game-2D-3D » XBMC-MythTV » xbmcmythtv » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » XBMC MythTV 
XBMC MythTV » xbmcmythtv » mythtvstruct.py
#
# NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE
#
# The classes in this file store data in UTF-8 format.  The method accessors
# should convert to the GUI encoding where necessary.  See the title(),
# subtitle(), and description() methods for examples.
#
# NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE : NOTE
#

from singleton import getInstance
import datetime
import mythtv
import sre
import time
import mythtvutil
import string
import socket

#from libs/libmythtv/programinfo.h
FL_COMMFLAG  = 0x01
FL_CUTLIST   = 0x02
FL_AUTOEXP   = 0x04
FL_EDITING   = 0x08
FL_BOOKMARK  = 0x10

gRecStatusTrans = \
{ \
    '-5': 88, # Deleted
    '-4': 89, # Stopped
    '-3': 90, # Recorded
    '-2': 91, # Recording
    '-1': 92, # WillRecord
    '0' : 93, # Unknown
    '1' : 94, # ManualOverride
    '2' : 95, # PreviousRecording
    '3' : 96, # CurrentRecording
    '4' : 97, # EarlierShowing
    '5' : 98, # TooManyRecordings
    '6' : 99, # Cancelled
    '7' :100, # Conflict
    '8' :101, # LaterShowing
    '9' :102, # Repeat
    '10':103, # Overlap
    '11':104, # LowDiskSpace
    '12':105, # TunerBusy
}

gRecSchedTypeTrans = \
{ \
    1 :111, # Once
    2 :112, # Daily
    3 :113, # Channel
    4 :114, # Always
    5 :115, # Weekly
    6 :116, # Find One
    7 :117, # Override
    8 :118, # Don't Record
    9 :119, # Find Daily
    10:120, # Find Weekly
}

gRecSchedTypeLongTrans = \
{ \
    1 :135, # Once
    2 :136, # Daily
    3 :137, # Channel
    4 :138, # Always
    5 :139, # Weekly
    6 :140, # Find One
    7 :141, # Override
    8 :142, # Don't Record
    9 :143, # Find Daily
    10:144, # Find Weekly
}

gRecSchedDupInTrans = \
{ \
    1 :149, # Current recordings
    2 :150, # Previous recordings
    3 :151, # Both
    4 :152, # New episodes
    15:153, # All
}

gRecSchedDupMethodTrans = \
{ \
    1 :145, # None
    2 :146, # Subtitle
    4 :147, # Description
    6 :148, # Subtitle and Description
}

def debug( str ):
    mythtvutil.debug( mythtvutil.DEBUG_MYTH, str )

def ctime2MythTime( mylong ):
    try:
        return time.strftime("%Y%m%d%H%M%S", time.localtime(float(mylong)))

    except Exception, ex:
        debug("Error Getting new time: " + str(mylong))
        debug(str(ex))

class Channel( object ):
    """
    Abstract base class to represent a channel in the mythtv system.
    """
  
    def chanid( self ):
        raise NotImplementedError, "Abstract base class"
    def channum( self ):
        raise NotImplementedError, "Abstract base class"
    def callsign( self ):
        raise NotImplementedError, "Abstract base class"
    def name( self ):
        raise NotImplementedError, "Abstract base class"
    def icon( self ):
        raise NotImplementedError, "Abstract base class"

class ChannelFromQuery( Channel ):
    """
    Implementation of a Channel object obtained from a query to the channel
    table in the mythtv database.
    """
    def __init__( self, data ):
        self.__data = dict( data )
        # make sure icon() returns a reasonable value when it is not
        # available
        if not self.__data.has_key( 'icon' ) or \
            not self.__data['icon'] or \
            self.__data['icon'] == "none":
            self.__data['icon'] = None
    def chanid( self ):
        return int( self.__data['chanid'] )
    def channum( self ):
        return self.__data['channum']
    def callsign( self ):
        return self.__data['callsign']
    def name( self ):
        return self.__data['name']
    def icon( self ):
        return self.__data['icon']

class Program( object ):
    """Base class to represent some kind of television program
    in the mythtv system.  This might be a recorded or scheduled
    programs."""

    def title( self ):
        raise Exception, "Abstract base class"
    def subtitle( self ):
        raise Exception, "Abstract base class"
    def description( self ):
        raise Exception, "Abstract base class"
    def category( self ):
        raise Exception, "Abstract base class"
    def chanid( self ):
        raise Exception, "Abstract base class"
    def chanstr( self ):
        raise Exception, "Abstract base class"
    def origairdate( self ):
        raise Exception, "Abstract base class"
    def callsign( self ):
        raise Exception, "Abstract base class"
    def starttime( self ):
        raise Exception, "Abstract base class"
    def endtime( self ):
        raise Exception, "Abstract base class"
    def starttimeAsTime( self ):
        starttime = self.starttime()
        if str(starttime[4:5]) == "-":
            return datetime.datetime(int(starttime[0:4]), int(starttime[5:7]), int(starttime[8:10]), int(starttime[11:13]), int(starttime[14:16]) )
        else:
            return datetime.datetime(int(starttime[0:4]), int(starttime[4:6]), int(starttime[6:8]), int(starttime[8:10]), int(starttime[10:12]) )
    def endtimeAsTime( self ):
        endtime = self.endtime()
        if str(endtime[4:5]) == "-":
            return datetime.datetime(int(endtime[0:4]), int(endtime[5:7]), int(endtime[8:10]), int(endtime[11:13]), int(endtime[14:16]) )
        else: 
            return datetime.datetime(int(endtime[0:4]), int(endtime[4:6]), int(endtime[6:8]), int(endtime[8:10]), int(endtime[10:12]) )
    def getLength( self ):
        return abs(self.endtimeAsTime() - self.starttimeAsTime())
    def setStartTime( self, newstarttime ):
        raise Exception, "Abstract base class"
    def setEndTime( self, newendtime ):
        raise Exception, "Abstract base class"
    def scheduledrecordinginfo( self ):
        return None
    def __repr__( self ):
        return """
Title:   %s : %s 
Description: %s
starttime: %s
endtime: %s
channum: %s
""" % ( self.title(), self.subtitle(), self.description(), self.starttimeAsTime(), self.endtimeAsTime(), self.chanstr() )

    def formattedAirDate( self ):
        """Returns air times as a formattted string for display purposes"""
        value = ""
        value += self.starttimeAsTime().strftime( "%A %b %d, %I:%M%p" )
        value += " - " + self.endtimeAsTime().strftime( "%I:%M%p" )
        if abs( self.starttimeAsTime() - self.endtimeAsTime() ) > datetime.timedelta( days = 1):
            value += " +1"
        return value

    def formattedChannel( self ):
        """Returns chanstr callsign for display purposes"""
        value = self.chanstr()
        if self.callsign():
            value += " " + self.callsign()
        return value

    def fullTitle( self ):
        """returns Title - subtitle if subtitle exists"""
        fullTitle = ""
        if self.title():
            fullTitle += self.title()
        if self.subtitle() and not sre.match( '^\s+$', self.subtitle() ):
            fullTitle += " - " + self.subtitle()
        return fullTitle
        
    def formattedOrigAirDate( self ):
        """returns original air date or the localized string 
           for no airdate if no airdate exists"""
        value = mythtvutil.getLocalizedString( 45 )
        try:
            if self.origairdate():
                value = self.origairdate()
        except:
            pass
        return value

    def formattedDescription( self ):
        value = mythtvutil.getLocalizedString( 46 )
        if self.description():
            value = self.description()
        return value[:200]

class ProgramFromQuery( Program ):
    """Implementation of the Program object using data obtained from
    a query to the program table in the mythtv database.  See mythtv.Database
    for the query that generates the dictonary that this class expects."""
    def __init__( self, data ):
        self.__data = dict( data )
    def data( self ):
        return self.__data
    def title( self ):
        return mythtv.convToGUIEncoding( self.__data["title"] )
    def subtitle( self ):
        return mythtv.convToGUIEncoding( self.__data["subtitle"] )
    def description( self ):
        return mythtv.convToGUIEncoding( self.__data["description"] )
    def category( self ):
        return self.__data["category"]
    def chanid( self ):
        return int(self.__data["chanid"])
    def chanstr( self ):
        if not self.__data["channum"]:
            return ""
        else:
            return self.__data["channum"]
    def origairdate( self ):
        key = "origairdate"
        if self.__data.has_key( "originalairdate" ):
            key = "originalairdate"
        try:
            if len( self.__data[ key ] ) == 4:
                return self.__data[ key ]
        except:
            pass
        return None
    def hostname( self ):
        try:
            return self.__data["hostname"]
        except:
            return None
    def basename( self ):
        try:
            return self.__data["basename"]
        except:
            return None
    def remotePath( self ):
        debug( '> mythtvstruct.ProgramFromQuery.remotePath()' )
        s = getInstance( mythtv.Settings )
        remoteFile = self.basename()
        remotePath = s.getSetting("paths_recordedprefix")
        shostIp = getInstance( mythtv.Settings ).getSetting( "mythtv_host" )
        host = self.hostname()
        try:
            hostIp = socket.gethostbyname(host)
            snet = hostIp[:6]
            ssnet = shostIp[:6]
            debug(snet + " " + ssnet)
            
            # if the first 6 characters of both addresses don't match then
            # chances are the 'internet' address of the host has been
            # found so just use the setting IP
            if snet <> ssnet:
                hostIp = shostIp
        except:
            hostIp = shostIp
        
        debug ('Host: %s hostIp: %s'%(host, hostIp))
        # we should do this substitute anyway?!
        remotePath = sre.sub( '\%h', hostIp, remotePath )

        if sre.match( "^[Ss][Mm][Bb]:", remotePath ) and not sre.match( "^\d", host ):
            host = sre.sub( '\..*$', '', host )
            remotePath = string.replace( remotePath, '\\', '/' )

        if remotePath[len(remotePath)-1] != '/':
            remotePath += '/'
        remotePath += remoteFile   

        debug( '< mythtvstruct.ProgramFromQuery.remotePath()' + \
                ' => [%s]'%remotePath )
        return str(remotePath)


    def callsign( self ):
        return self.__data["callsign"] 
    def seriesid( self ):
        return self.__data[ "seriesid" ]
    def programid( self ):
        return self.__data[ "programid" ]
    def recordid( self ):
        return self.__data[ "recordid" ]
    def manualid( self ):
        return self.__data[ "manualid" ]
    def icon( self ):
        return self.__data[ "icon" ]
    def channame( self ):
        return self.__data[ "channame" ]
    def scheduledrecordinginfo( self ):
        return ScheduledRecordingInfo( self.__data )
    def starttime( self ):
        starttime = self.__data[ "starttime" ]
        if int(mythtv.mythProtocolVersion) >= 13:
            starttime = sre.sub( "[T:|\\-| ]", "", starttime )
        return starttime
    def endtime( self ):
        endtime = self.__data[ "endtime" ]
        if int(mythtv.mythProtocolVersion) >= 13:
            endtime = sre.sub( "[T:|\\-| ]", "", endtime )
        return endtime
    def recstarttime( self ):
        return self.starttime()
    def recendtime( self ):
        return self.endtime()
    def isduplicate( self ):
        if self.__data["isduplicate"] == '0':
            return False
        else:
            return True
    def setStartTime( self, newstarttime ):
        if hasattr(newstarttime, "strftime" ):
            self.__data[ "starttime" ] = newstarttime.strftime( "%Y%m%d%H%M%S" )
        else:
            self.__data[ "starttime" ] = newstarttime
    def setEndTime( self, newendtime ):
        if hasattr(newendtime, "strftime" ):
            self.__data[ "endtime" ] = newendtime.strftime( "%Y%m%d%H%M%S" )
        else:
            self.__data[ "endtime" ] = newendtime

class ProgramFromRecordings( Program ):
    """Implementation of the Program object that contains data
    retrieved from a call to mythbackend"""
    def __init__( self, data ):
        """data: a list of fields from mythbackend.  
        libs/libmythtv/programinfo.cpp in the mythtv
        source describes the ordering of these fields"""
        self.__data = data[:]
    def data( self ):
        return self.__data
    def title( self ):
        return mythtv.convToGUIEncoding( self.__data[0] )
    def subtitle( self ):
        return mythtv.convToGUIEncoding( self.__data[1] )
    def description( self ):
        return mythtv.convToGUIEncoding( self.__data[2] )
    def category( self ):
        return self.__data[3]
    def chanid( self ):
        return int(self.__data[4])
    def chanstr( self ):
        if not self.__data[5]:
            return ""
        else:
            return self.__data[5]
    def callsign( self ):
        return self.__data[6]
    def channame( self ):
        return self.__data[7]
    def filename( self ):
        return self.__data[8]
    def fshigh( self ):    # high word of file size
        return int(self.__data[9])
    def fslow( self ):    # low word of file size
        return int(self.__data[10])
    def starttimets( self ):
        return int(self.__data[11])
    def endtimets( self ):
        return int(self.__data[12])
    def starttime( self ):
        #this might be broken now for protocol < 14
        #time format should be YYYYMMDDHHmmss
        if int(mythtv.mythProtocolVersion) < 14:
            return sre.sub( "[T:|\\-| ]", "", self.__data[11])
        else:
            if int(self.__data[11]) < 0:
                return ctime2MythTime(self.__data[26])
            else:
                return ctime2MythTime(self.__data[11])
    def endtime( self ):
        #this might be broken now for protocol < 14
        #time format should be YYYYMMDDHHmmss
        if int(mythtv.mythProtocolVersion) < 14:
            return sre.sub( "[T:|\\-| ]", "", self.__data[12] )
        else:
            if int(self.__data[12]) < 0:
                return ctime2MythTime(self.__data[27])
            else:
                return ctime2MythTime(self.__data[12])
    def conflicting( self ):
        if int(mythtv.mythProtocolVersion) == 1:
            return self.__data[13]
        elif int(mythtv.mythProtocolVersion) >= 4:
            return recstatus() == "Conflict"
        else:
            raise mythtv.ProtocolVersionException, "unsupported call for protocol version"
    def recording( self ):
        if int(mythtv.mythProtocolVersion) == 1:
            return self.__data[14]
        elif int(mythtv.mythProtocolVersion) >= 4:
            return recstatus() == "WillRecord"
        else:
            raise mythtv.mythtv.ProtocolVersionException, "unsupported call for protocol version"
    def duplicate( self ):
        return self.__data[15]
    def hostname( self ):
        return self.__data[16]
    def sourceid( self ):
        return self.__data[17]
    def cardid( self ):
        return self.__data[18]
    def inputid( self ):
        return self.__data[19]
    def recpriority( self ):
        return self.__data[20]
    def recstatus( self ):
        return self.__data[21]
    def recordid( self ):
        return self.__data[22]
    def rectype( self ):
        return self.__data[23]
    def recdups( self ):
        if int(mythtv.mythProtocolVersion) == 1:
            return self.__data[24]
        raise mythtv.ProtocolVersionException, "unsupported call for protocol version"
    def recstarttime( self ):
        if mythtv.mythProtocolVersion == "1":
            return self.__data[25]
        elif mythtv.mythProtocolVersion >= "15":
            return self.__data[26]
        raise mythtv.ProtocolVersionException, "unsupported call for protocol version 6"
    def recendtime( self ):
        if mythtv.mythProtocolVersion == 1:
            return self.__data[26]
        elif mythtv.mythProtocolVersion >= "15":
            return self.__data[27]
        raise mythtv.ProtocolVersionException, "unsupported call for protocol version 7"
    def repeat( self ):
        if mythtv.mythProtocolVersion == "1":
            return self.__data[27] 
        elif mythtv.mythProtocolVersion >= "15":
            return self.__data[28]
        raise mythtv.ProtocolVersionException, "unsupported call for protocol version 8"
    def programflags( self ):
        if int(mythtv.mythProtocolVersion) >= 13:
            return int(self.__data[29])
        raise mythtv.ProtocolVersionException, "unsupported call for protocol version"
    def recgroup( self ):
        if int(mythtv.mythProtocolVersion) >= 26:
            return self.__data[30]
        else:
            return "default"

    def origairdate( self ):
        try:
            if int(mythtv.mythProtocolVersion) >= 14:
                if int(mythtv.mythProtocolVersion) >= 32:
                    if int(self.__data[38]) <> 0:
                        return self.__data[37]
                    else:
                        return None
                    
                else:
                    if int(self.__data[37]) > 0:
                        return ctime2MythTime(self.__data[37])[0:4]
                    else:
                        return None
            else:
                return None
        except:
            return None
    def autoexpire( self ):
        return (self.programflags() & FL_AUTOEXP) != 0
    def commflagged(self):
        return (self.programflags() & FL_COMMFLAG) != 0
    def bookmarked(self):
        return (self.programflags() & FL_BOOKMARK) != 0
    def editing(self):
        return (self.programflags() & FL_EDITING) != 0
    def cutlist(self):
        return (self.programflags() & FL_CUTLIST) != 0


    def rawFileSize( self ):
        return (((self.fshigh() + (self.fslow() < 0)) * 4294967296 + self.fslow()) / 1024.0 )
    
    def formattedFileSize( self ):
        value = mythtvutil.getLocalizedString( 46 )
        size = (self.fshigh() + (self.fslow() < 0)) * 4294967296 + self.fslow()
        value = mythtv.formatSize( size / 1024.0, True )
        return value

    def remoteFileInfo( self, path=None ):
        """
        On failure, returns None if the file info cannot be retrieved (either
        the file does not exist or the protocol is not supported).
        
        On success, returns the file information as a smb.SharedFile object.
        """
        debug( "> mythtvstruct.ProgramFromRecordings.remoteFileInfo()" )

        if not path:
            path = self.remotePath()
        if not path:
            return None

        if not sre.match('^[Ss][Mm][Bb]:', path):
            return None

        fileInfo = mythtvutil.parseSMBPath(path)
        if not fileInfo:
            return None

        user,password,host,service,dirPath,fileName = fileInfo
        
        hostIp = getInstance( mythtv.NMBService ).gethostipbyname( host )

        remote = smb.SMB(host,hostIp)

        if remote.is_login_required():
            remote.login( user, password )

        found = None
        try:
            files = remote.list_path( service, "%s%s" % (dirPath,fileName) )
            for f in files:
                if fileName == f.get_longname():
                    found = f
        except smb.SessionError, ex:
            pass

        debug( "< mythtvrecordedshowdetails.ProgramDetails." + \
                "remoteFileInfo() => [%s]"%found )
        return found

    def remoteMythPath( self ):
        debug( '> mythtvrecordedshowdetails.ProgramDetails.remoteMythPath()' )

##        host = self.hostname()
##        port = int( getInstance( mythtv.Settings ).getSetting( "mythtv_port" ) )
##        remotePath = "myth://%s:%d/%d_%s_%s.nuv"% \
##            (host,port,self.chanid(),self.starttime(),self.endtime())
        remotePath = self.filename()
        debug( '< mythtvrecordedshowdetails.ProgramDetails.remoteMythPath()' + \
                ' => [%s]'%remotePath )
        return str(remotePath)

    def remotePath( self ):
        debug( '> mythtvstruct.ProgramFromRecordings.remotePath()' )
        s = getInstance( mythtv.Settings )
        remoteFile = self.remoteMythPath()
        remoteFile = remoteFile[remoteFile.rfind("/")+1:]
        remotePath = s.getSetting("paths_recordedprefix")
        
        host = self.hostname()
        shost = getInstance( mythtv.Settings ).getSetting( "mythtv_host" )

        try:
            hostIp = getInstance( mythtv.NMBService ).gethostipbyname( host )
            snet = hostIp[:6]
            ssnet = shost[:6]
            debug(snet + " " + ssnet)
            if snet <> ssnet:
                hostIp = shost              
        except:
            try:
                hostIp = socket.gethostbyname(host)
                snet = hostIp[:6]
                ssnet = shost[:6]
                debug(snet + " " + ssnet)
                if snet <> ssnet:
                    hostIp = shost                  
            except:
                hostIp = shost
        debug ('Host: %s hostIp: %s'%(host, hostIp))
        # we should do this substitute anyway?!
        remotePath = sre.sub( '\%h', hostIp, remotePath )

        if sre.match( "^[Ss][Mm][Bb]:", remotePath ) and not sre.match( "^\d", host ):
            host = sre.sub( '\..*$', '', host )
            remotePath = string.replace( remotePath, '\\', '/' )

        if remotePath[len(remotePath)-1] != '/':
            remotePath += '/'
        remotePath += remoteFile   

        debug( '< mythtvp.ProgramDetails.remotePath()' + \
                ' => [%s]'%remotePath )
        return str(remotePath)

    def remoteThumbnailPath( self ):
        debug( '> mythtvrecordedshowdetails.ProgramDetails.remoteThumbnailPath()' )

        path = self.remotePath() + ".png"

        debug( '< mythtvstruct.ProgramFromRecordings.remoteThumbnailPath()' + \
                ' => [%s]'%path )
        return str(path)

    def remoteThumbnailInfo( self ):
        debug( '> mythtvstruct.ProgramFromRecordings.remoteThumbnailInfo()' )
        path = self.remotePath() + ".png"
        debug( '< mythtvstruct.ProgramFromRecordings.remoteThumbnailInfo()' + \
                ' => [%s]'%path )
        return str(path)

    def translatedRecStatus( self ):
        return mythtvutil.getLocalizedString( \
            gRecStatusTrans[self.recstatus()] )

class Schedule( object ):
    """
    Abstract base class to represent a recording schedule in the mythtv system.

    This class is baed on the Myth TV RECORD table.
    """
  
    def recordid( self ):
        raise NotImplementedError, "Abstract base class"
    def type( self ):
        raise NotImplementedError, "Abstract base class"
    def chanid( self ):
        raise NotImplementedError, "Abstract base class"
    def channum( self ):
        raise NotImplementedError, "Abstract base class"
    def callsign( self ):
        raise NotImplementedError, "Abstract base class"
    def channame( self ):
        raise NotImplementedError, "Abstract base class"
    def icon( self ):
        raise NotImplementedError, "Abstract base class"
    def starttime( self ):
        raise NotImplementedError, "Abstract base class"
    def startdate( self ):
        raise NotImplementedError, "Abstract base class"
    def endtime( self ):
        raise NotImplementedError, "Abstract base class"
    def enddate( self ):
        raise NotImplementedError, "Abstract base class"
    def title( self ):
        raise NotImplementedError, "Abstract base class"
    def subtitle( self ):
        raise NotImplementedError, "Abstract base class"
    def description( self ):
        raise NotImplementedError, "Abstract base class"
    def category( self ):
        raise NotImplementedError, "Abstract base class"
    def profile( self ):
        raise NotImplementedError, "Abstract base class"
    def recpriority( self ):
        raise NotImplementedError, "Abstract base class"
    def autoexpire( self ):
        raise NotImplementedError, "Abstract base class"
    def maxepisodes( self ):
        raise NotImplementedError, "Abstract base class"
    def maxnewest( self ):
        raise NotImplementedError, "Abstract base class"
    def startoffset( self ):
        raise NotImplementedError, "Abstract base class"
    def endoffset( self ):
        raise NotImplementedError, "Abstract base class"
    def recgroup( self ):
        raise NotImplementedError, "Abstract base class"
    def dupmethod( self ):
        raise NotImplementedError, "Abstract base class"
    def dupin( self ):
        raise NotImplementedError, "Abstract base class"
    def station( self ):
        raise NotImplementedError, "Abstract base class"
    def seriesid( self ):
        raise NotImplementedError, "Abstract base class"
    def programid( self ):
        raise NotImplementedError, "Abstract base class"
    def search( self ):
        raise NotImplementedError, "Abstract base class"
    def autotranscode( self ):
        raise NotImplementedError, "Abstract base class"
    def autocommflag( self ):
        raise NotImplementedError, "Abstract base class"
    def autouserjob1( self ):
        raise NotImplementedError, "Abstract base class"
    def autouserjob2( self ):
        raise NotImplementedError, "Abstract base class"
    def autouserjob3( self ):
        raise NotImplementedError, "Abstract base class"
    def autouserjob4( self ):
        raise NotImplementedError, "Abstract base class"
    def findday( self ):
        raise NotImplementedError, "Abstract base class"
    def findtime( self ):
        raise NotImplementedError, "Abstract base class"
    def findid( self ):
        raise NotImplementedError, "Abstract base class"
    def inactive( self ):
        raise NotImplementedError, "Abstract base class"
    def parentid( self ):
        raise NotImplementedError, "Abstract base class"
    def __repr__( self ):
        return "recordid=%s,type=%s,title=[%s],subtitle=[%s],starttime=[%s]" % (
            str(self.recordid()),
            str(self.type()),
            self.title(),
            self.subtitle(),
            self.starttime() )
    def formattedChannel( self ):
        text = ""
        if self.channum():
            text += self.channum()
        if self.callsign():
            text += " - " + self.callsign()
        return text
    def formattedDuplicateMethod( self ):
        return mythtvutil.getLocalizedString(
            gRecSchedDupMethodTrans[self.dupmethod()] )
    def formattedDuplicateIn( self ):
        return mythtvutil.getLocalizedString(
            gRecSchedDupInTrans[self.dupin()] )
    def formattedStartDate( self ):
        value = ""
        value += self.startdateAsTime().strftime( "%a, %b %d" )
        return value
    def formattedTime( self ):
        text = "%s:%s - %s:%s"%(
            self.starttime()[0:2],
            self.starttime()[2:4],
            self.endtime()[0:2],
            self.endtime()[2:4])
        if self.startdate() != self.enddate():
            text += " +1"
        return text
    def formattedType( self ):
        return mythtvutil.getLocalizedString(
            gRecSchedTypeTrans[self.type()] )
    def formattedTypeLong( self ):
        return mythtvutil.getLocalizedString(
            gRecSchedTypeLongTrans[self.type()] )
    def fullTitle( self ):
        """returns Title - subtitle if subtitle exists"""
        fullTitle = ""
        if self.title():
            fullTitle += self.title()
        if self.subtitle() and not sre.match( '^\s+$', self.subtitle() ):
            fullTitle += " - " + self.subtitle()
        return fullTitle
    def startdateAsTime( self ):
        startdate = self.startdate()
        return datetime.datetime(
            int(startdate[0:4]), int(startdate[4:6]), int(startdate[6:8]),
            0, 0 )

class ScheduleFromQuery( Schedule ):
    """
    Implementation of a Schedule object obtained from a query to the record
    table in the mythtv database.
    """
    def __init__( self, data ):
        self.__data = dict( data )
        if not self.__data.has_key( 'icon' ) or \
            not self.__data['icon'] or \
            self.__data['icon'] == "none":
            self.__data['icon'] = None
    def data( self ):
        return self.__data
    def recordid( self ):
        if self.__data['recordid']:
            return int( self.__data['recordid'] )
        else:
            return None
    def type( self ):
        return int( self.__data['type'] )
    def chanid( self ):
        return int( self.__data['chanid'] )
    def channum( self ):
        return self.__data['channum']
    def callsign( self ):
        return self.__data['callsign']
    def channame( self ):
        return self.__data['channame']
    def icon( self ):
        return self.__data['icon']
    def starttime( self ):
        starttime = sre.sub( "[T:|\\-| ]", "", self.__data['starttime'] )
        return starttime
    def startdate( self ):
        startdate = sre.sub( "[T:|\\-| ]", "", self.__data['startdate'] )
        return startdate
    def endtime( self ):
        endtime = sre.sub( "[T:|\\-| ]", "", self.__data['endtime'] )
        return endtime
    def enddate( self ):
        enddate = sre.sub( "[T:|\\-| ]", "", self.__data['enddate'] )
        return enddate
    def title( self ):
        return mythtv.convToGUIEncoding( self.__data["title"] )
    def subtitle( self ):
        return mythtv.convToGUIEncoding( self.__data["subtitle"] )
    def description( self ):
        return mythtv.convToGUIEncoding( self.__data["description"] )
    def category( self ):
        return self.__data['category']
    def profile( self ):
        return self.__data['profile']
    def recpriority( self ):
        return int( self.__data['recpriority'] )
    def autoexpire( self ):
        return int( self.__data['autoexpire'] )
    def maxepisodes( self ):
        return int( self.__data['maxepisodes'] )
    def maxnewest( self ):
        return int( self.__data['maxnewest'] )
    def startoffset( self ):
        return int( self.__data['startoffset'] )
    def endoffset( self ):
        return int( self.__data['endoffset'] )
    def recgroup( self ):
        return self.__data['recgroup']
    def dupmethod( self ):
        return int( self.__data['dupmethod'] )
    def dupin( self ):
        return int( self.__data['dupin'] )
    def station( self ):
        return self.__data['station']
    def seriesid( self ):
        return self.__data['seriesid']
    def programid( self ):
        return self.__data['programid']
    def search( self ):
        return int( self.__data['search'] )
    def autotranscode( self ):
        return int( self.__data['autotranscode'] )
    def autocommflag( self ):
        return int( self.__data['autocommflag'] )
    def autouserjob1( self ):
        return int( self.__data['autouserjob1'] )
    def autouserjob2( self ):
        return int( self.__data['autouserjob2'] )
    def autouserjob3( self ):
        return int( self.__data['autouserjob3'] )
    def autouserjob4( self ):
        return int( self.__data['autouserjob4'] )
    def findday( self ):
        return self.__data['findday']
    def findtime( self ):
        return self.__data['findtime']
    def findid( self ):
        return int( self.__data['findid'] )
    def inactive( self ):
        return int( self.__data['inactive'] )
    def parentid( self ):
        return int( self.__data['parentid'] )

class ScheduleFromProgram( ScheduleFromQuery ):
    """
    Implementation of a Schedule object obtained from a ProgramFromQuery object.
    """
    def __init__( self, programFromQuery ):
        data = dict()
        ScheduleFromQuery.__init__( self, data )
        self.data()['icon'] = programFromQuery.icon()
        self.data()['title'] = programFromQuery.data()['title']
        self.data()['subtitle'] = programFromQuery.data()['subtitle']
        self.data()['description'] = programFromQuery.data()['description']
        self.data()['category'] = programFromQuery.category()
        self.data()['chanid'] = programFromQuery.chanid()
        self.data()['channum'] = programFromQuery.chanstr()
        self.data()['callsign'] = programFromQuery.callsign()
        self.data()['seriesid'] = programFromQuery.seriesid()
        self.data()['programid'] = programFromQuery.programid()
        self.data()['channame'] = programFromQuery.channame()
        self.data()['recordid'] = None
        self.data()['type'] = "3"   # channel
        starttime = programFromQuery.starttime()
        self.data()['startdate'] = starttime[0:8]
        self.data()['starttime'] = starttime[8:14]
        endtime = programFromQuery.endtime()
        self.data()['enddate'] = endtime[0:8]
        self.data()['endtime'] = endtime[8:14]
        self.data()['profile'] = "Default"
        self.data()['recpriority'] = "0"
        self.data()['autoexpire'] = "0"
        self.data()['maxepisodes'] = "0"
        self.data()['maxnewest'] = "0"
        self.data()['startoffset'] = "0"
        self.data()['endoffset'] = "0"
        self.data()['recgroup'] = "Default"
        self.data()['dupmethod'] = "6"  # Subtitle and Description
        self.data()['dupin'] = "15"     # All
        self.data()['station'] = self.callsign()
        self.data()['search'] = "0"
        self.data()['autotranscode'] = "0"
        self.data()['autocommflag'] = "1"
        self.data()['autouserjob1'] = "0"
        self.data()['autouserjob2'] = "0"
        self.data()['autouserjob3'] = "0"
        self.data()['autouserjob4'] = "0"
        self.data()['findday'] = "0"
        self.data()['findtime'] = "00:00:00"
        self.data()['findid'] = "0"
        self.data()['inactive'] = "0"
        self.data()['parentid'] = "0"

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.