Beispiel #1
0
    def searchJobs(self, init=False, key=None, value=None):
        """
        obj.searchJobs(**kwars) -> list of Job objects

        Supports the following keywords:
            chanid,     starttime,  type,       status,     hostname,
            title,      subtitle,   flags,      olderthan,  newerthan
        """
        if init:
            return ('jobqueue', Job, (),
                    ('recorded','jobqueue',('chanid','starttime')))
        if key in ('chanid','type','status','hostname'):
            return ('jobqueue.%s=%%s' % key, value, 0)
        if key in ('title','subtitle'):
            return ('recorded.%s=%%s' % key, value, 1)
        if key == 'flags':
            return ('jobqueue.flags&%s', value, 0)

        if key == 'starttime':
            return ('jobqueue.starttime=%s', datetime.duck(value), 0)
        if key == 'olderthan':
            return ('jobqueue.inserttime>%s', datetime.duck(value), 0)
        if key == 'newerthan':
            return ('jobqueue.inserttime<%s', datetime.duck(value), 0)
        return None
Beispiel #2
0
    def searchJobs(self, init=False, key=None, value=None):
        """
        obj.searchJobs(**kwars) -> list of Job objects

        Supports the following keywords:
            chanid,     starttime,  type,       status,     hostname,
            title,      subtitle,   flags,      olderthan,  newerthan
        """
        if init:
            init.table = "jobqueue"
            init.handler = Job
            init.joins = (init.Join(table="recorded", tableto="jobqueue", fields=("chanid", "starttime")),)
            return None

        if key in ("chanid", "type", "status", "hostname"):
            return ("jobqueue.%s=?" % key, value, 0)
        if key in ("title", "subtitle"):
            return ("recorded.%s=?" % key, value, 1)
        if key == "flags":
            return ("jobqueue.flags&?", value, 0)

        if key == "starttime":
            return ("jobqueue.starttime=?", datetime.duck(value), 0)
        if key == "olderthan":
            return ("jobqueue.inserttime>?", datetime.duck(value), 0)
        if key == "newerthan":
            return ("jobqueue.inserttime<?", datetime.duck(value), 0)
        return None
Beispiel #3
0
    def searchJobs(self, init=False, key=None, value=None):
        """
        obj.searchJobs(**kwars) -> list of Job objects

        Supports the following keywords:
            chanid,     starttime,  type,       status,     hostname,
            title,      subtitle,   flags,      olderthan,  newerthan
        """
        if init:
            init.table = 'jobqueue'
            init.handler = Job
            init.joins = (init.Join(table='recorded',
                                    tableto='jobqueue',
                                    fields=('chanid','starttime')),)

        if key in ('chanid','type','status','hostname'):
            return ('jobqueue.%s=%%s' % key, value, 0)
        if key in ('title','subtitle'):
            return ('recorded.%s=%%s' % key, value, 1)
        if key == 'flags':
            return ('jobqueue.flags&%s', value, 0)

        if key == 'starttime':
            return ('jobqueue.starttime=%s', datetime.duck(value), 0)
        if key == 'olderthan':
            return ('jobqueue.inserttime>%s', datetime.duck(value), 0)
        if key == 'newerthan':
            return ('jobqueue.inserttime<%s', datetime.duck(value), 0)
        return None
Beispiel #4
0
    def searchJobs(self, init=False, key=None, value=None):
        """
        obj.searchJobs(**kwars) -> list of Job objects

        Supports the following keywords:
            chanid,     starttime,  type,       status,     hostname,
            title,      subtitle,   flags,      olderthan,  newerthan
        """
        if init:
            init.table = 'jobqueue'
            init.handler = Job
            init.joins = (init.Join(table='recorded',
                                    tableto='jobqueue',
                                    fields=('chanid','starttime')),)
            return None

        if key in ('chanid','type','status','hostname'):
            return ('jobqueue.%s=?' % key, value, 0)
        if key in ('title','subtitle'):
            return ('recorded.%s=?' % key, value, 1)
        if key == 'flags':
            return ('jobqueue.flags&?', value, 0)

        if key == 'starttime':
            return ('jobqueue.starttime=?', datetime.duck(value), 0)
        if key == 'olderthan':
            return ('jobqueue.inserttime>?', datetime.duck(value), 0)
        if key == 'newerthan':
            return ('jobqueue.inserttime<?', datetime.duck(value), 0)
        return None
Beispiel #5
0
    def searchRecorded(self, init=False, key=None, value=None):
        """
        obj.searchRecorded(**kwargs) -> list of Recorded objects

        Supports the following keywords:
            title,      subtitle,   chanid,     starttime,  progstart,
            category,   hostname,   autoexpire, commflagged,
            stars,      recgroup,   playgroup,  duplicate,  transcoded,
            watched,    storagegroup,           category_type,
            airdate,    stereo,     subtitled,  hdtv,       closecaptioned,
            partnumber, parttotal,  seriesid,   showtype,   programid,
            manualid,   generic,    cast,       livetv,     basename,
            syndicatedepisodenumber

        Multiple keywords can be chained as such:
            obj.searchRecorded(title='Title', commflagged=False)
        """

        if init:
            # table and join descriptor
            return ('recorded', Recorded, ('livetv',),
                    ('recordedprogram','recorded',('chanid','starttime')),  #1
                    ('recordedcredits','recorded',
                                            ('chanid','starttime'),
                                            ('chanid','progstart')),        #2
                    ('people','recordedcredits',('person',)))               #4

        # local table matches
        if key in ('title','subtitle','chanid',
                        'category','hostname','autoexpire','commflagged',
                        'stars','recgroup','playgroup','duplicate',
                        'transcoded','watched','storagegroup','basename'):
            return ('recorded.%s=%%s' % key, value, 0)

        # time matches
        if key in ('starttime','endtime','progstart','progend'):
            return ('recorded.%s=%%s' % key, datetime.duck(value), 0)

        if key == 'olderthan':
            return ('recorded.starttime<%s', datetime.duck(value), 0)
        if key == 'newerthan':
            return ('recorded.starttime>%s', datetime.duck(value), 0)


        # recordedprogram matches
        if key in ('category_type','airdate','stereo','subtitled','hdtv',
                    'closecaptioned','partnumber','parttotal','seriesid',
                    'showtype','syndicatedepisodenumber','programid',
                    'manualid','generic'):
            return ('recordedprogram.%s=%%s' % key, value, 1)

        if key == 'cast':
            return ('people.name', 'recordedcredits', 4, 1)

        if key == 'livetv':
            if (value is None) or (value == False):
                return ('recorded.recgroup!=%s', 'LiveTV', 0)
            return ()

        return None
Beispiel #6
0
    def searchGuide(self, init=False, key=None, value=None):
        """
        obj.searchGuide(**args) -> list of Guide objects

        Supports the following keywords:
            chanid,     starttime,  endtime,    title,      subtitle,
            category,   airdate,    stars,      previouslyshown,
            stereo,     subtitled,  hdtv,       closecaptioned,
            partnumber, parttotal,  seriesid,   originalairdate,
            showtype,   programid,  generic,    syndicatedepisodenumber,
            ondate,     cast,       startbefore,startafter
            endbefore,  endafter
        """
        if init:
            init.table = "program"
            init.handler = Guide
            init.joins = (
                init.Join(table="credits", tableto="program", fields=("chanid", "starttime")),
                init.Join(table="people", tableto="credits", fields=("person",)),
            )

        if key in (
            "chanid",
            "title",
            "subtitle",
            "category",
            "airdate",
            "stars",
            "previouslyshown",
            "stereo",
            "subtitled",
            "hdtv",
            "closecaptioned",
            "partnumber",
            "parttotal",
            "seriesid",
            "originalairdate",
            "showtype",
            "syndicatedepisodenumber",
            "programid",
            "generic",
        ):
            return ("%s=%%s" % key, value, 0)
        if key in ("starttime", "endtime"):
            return ("%s=%%s" % key, datetime.duck(value), 0)
        if key == "ondate":
            return ("DATE(starttime)=%s", value, 0)
        if key == "cast":
            return ("people.name", "credits", 2, 0)
        if key == "startbefore":
            return ("starttime<%s", datetime.duck(value), 0)
        if key == "startafter":
            return ("starttime>%s", datetime.duck(value), 0)
        if key == "endbefore":
            return ("endtime<%s", datetime.duck(value), 0)
        if key == "endafter":
            return ("endtime>%s", datetime.duck(value), 0)
        return None
Beispiel #7
0
    def searchArtwork(self, init=False, key=None, value=None):
        """
        obj.searchArtwork(**kwargs) -> list of RecordedArtwork objects

        Supports the following keywords:
            inetref,    season,     host,   chanid,     starttime
            title,      subtitle
        """

        if init:
            # table and join descriptor
            init.table = 'recordedartwork'
            init.handler = RecordedArtwork
            init.joins = (init.Join(table='recorded',
                                    tableto='recordedartwork',
                                    fieldsfrom=('inetref','season','hostname'),
                                    fieldsto=('inetref','season','host')),)
            return None

        if key in ('inetref', 'season', 'host'):
            return ('recordedartwork.%s=?' % key, value, 0)

        if key in ('chanid', 'title', 'subtitle'):
            return ('recorded.%s=?' % key, value, 1)

        if key == 'starttime':
            return ('recorded.%s=?' % key, datetime.duck(value), 1)

        return None
Beispiel #8
0
    def searchOldRecorded(self, init=False, key=None, value=None):
        """
        obj.searchOldRecorded(**kwargs) -> list of OldRecorded objects

        Supports the following keywords:
            title,      subtitle,   chanid,     starttime,  endtime,
            category,   seriesid,   programid,  station,    duplicate,
            generic,    recstatus,  inetref,    season,     episode
        """

        if init:
            init.table = "oldrecorded"
            init.handler = OldRecorded
            return None

        if key in (
            "title",
            "subtitle",
            "chanid",
            "category",
            "seriesid",
            "programid",
            "station",
            "duplicate",
            "generic",
            "recstatus",
            "inetref",
            "season",
            "episode",
        ):
            return ("oldrecorded.%s=?" % key, value, 0)
            # time matches
        if key in ("starttime", "endtime"):
            return ("oldrecorded.%s=?" % key, datetime.duck(value), 0)
        return None
Beispiel #9
0
    def searchArtwork(self, init=False, key=None, value=None):
        """
        obj.searchArtwork(**kwargs) -> list of RecordedArtwork objects

        Supports the following keywords:
            inetref,    season,     host,   chanid,     starttime
            title,      subtitle
        """

        if init:
            # table and join descriptor
            init.table = "recordedartwork"
            init.handler = RecordedArtwork
            init.joins = (
                init.Join(
                    table="recorded",
                    tableto="recordedartwork",
                    fieldsfrom=("inetref", "season", "hostname"),
                    fieldsto=("inetref", "season", "host"),
                ),
            )
            return None

        if key in ("inetref", "season", "host"):
            return ("recordedartwork.%s=?" % key, value, 0)

        if key in ("chanid", "title", "subtitle"):
            return ("recorded.%s=?" % key, value, 1)

        if key == "starttime":
            return ("recorded.%s=?" % key, datetime.duck(value), 1)

        return None
Beispiel #10
0
    def searchArtwork(self, init=False, key=None, value=None):
        """
        obj.searchArtwork(**kwargs) -> list of RecordedArtwork objects

        Supports the following keywords:
            inetref,    season,     host,   chanid,     starttime
            title,      subtitle
        """

        if init:
            # table and join descriptor
            init.table = 'recordedartwork'
            init.handler = RecordedArtwork
            init.joins = (init.Join(table='recorded',
                                    tableto='recordedartwork',
                                    fieldsfrom=('inetref','season','hostname'),
                                    fieldsto=('inetref','season','host')),)
            return None

        if key in ('inetref', 'season', 'host'):
            return ('recordedartwork.%s=?' % key, value, 0)

        if key in ('chanid', 'title', 'subtitle'):
            return ('recorded.%s=?' % key, value, 1)

        if key == 'starttime':
            return ('recorded.%s=?' % key, datetime.duck(value), 1)

        return None
Beispiel #11
0
 def getProgramDetails(self, chanid, starttime):
     """
     Returns a Program object for the matching show.
     """
     starttime = datetime.duck(starttime)
     args = {"ChanId": chanid, "StartTime": starttime.isoformat()}
     return Program.fromJSON(self._request("Guide/GetProgramDetails", **args).readJSON()["Program"], db=self.db)
Beispiel #12
0
 def __init__(self, data=None, db=None):
     if data is not None:
         if None not in data:
             data = [data[0], datetime.duck(data[1])]
     DBDataWrite.__init__(self, data, db)
     if self.future:
         raise MythDBError(MythError.DB_RESTRICT, "'future' OldRecorded " +\
                     "instances are not usable from the bindings.")
Beispiel #13
0
 def __init__(self, data=None, db=None):
     if data is not None:
         if None not in data:
             data = [data[0], datetime.duck(data[1])]
     DBDataWrite.__init__(self, data, db)
     if self.future:
         raise MythDBError(MythError.DB_RESTRICT, "'future' OldRecorded " +\
                     "instances are not usable from the bindings.")
Beispiel #14
0
 def getLastGuideData(self):
     """
     Returns the last dat for which guide data is available
     """
     try:
         return datetime.duck(self.backendCommand('QUERY_GUIDEDATATHROUGH'))
     except ValueError:
         return None
Beispiel #15
0
 def getLastGuideData(self):
     """
     Returns the last dat for which guide data is available
     """
     try:
         return datetime.duck(self.backendCommand('QUERY_GUIDEDATATHROUGH'))
     except ValueError:
         return None
Beispiel #16
0
    def getPreviewImage(self, chanid, starttime, width=None, \
                                                 height=None, secsin=None):
        starttime = datetime.duck(starttime)
        args = {'ChanId':chanid, 'StartTime':starttime.isoformat()}
        if width: args['Width'] = width
        if height: args['Height'] = height
        if secsin: args['SecsIn'] = secsin

        return self._query('GetPreviewImage', **args)
Beispiel #17
0
 def getProgramDetails(self, chanid, starttime):
     """
     Returns a Program object for the matching show.
     """
     starttime = datetime.duck(starttime)
     args = {'ChanId': chanid, 'StartTime': starttime.isoformat()}
     tree = self._queryTree('GetProgramDetails', **args)
     prog = tree.find('ProgramDetails').find('Program')
     return Program.fromEtree(prog, self.db)
Beispiel #18
0
 def getProgramDetails(self, chanid, starttime):
     """
     Returns a Program object for the matching show.
     """
     starttime = datetime.duck(starttime)
     args = {"ChanId": chanid, "StartTime": starttime.isoformat()}
     tree = self._queryTree("GetProgramDetails", **args)
     prog = tree.find("ProgramDetails").find("Program")
     return Program.fromEtree(prog, self.db)
Beispiel #19
0
 def getProgramDetails(self, chanid, starttime):
     """
     Returns a Program object for the matching show.
     """
     starttime = datetime.duck(starttime)
     args = {'ChanId': chanid, 'StartTime': starttime.isoformat()}
     tree = self._queryTree('GetProgramDetails', **args)
     prog = tree.find('ProgramDetails').find('Program')
     return Program.fromEtree(prog, self.db)
Beispiel #20
0
    def getPreviewImage(self, chanid, starttime, width=None, \
                                                 height=None, secsin=None):
        starttime = datetime.duck(starttime)
        args = {'ChanId':chanid, 'StartTime':starttime.isoformat()}
        if width: args['Width'] = width
        if height: args['Height'] = height
        if secsin: args['SecsIn'] = secsin

        return self._result('Content/GetPreviewImage', **args).read()
Beispiel #21
0
    def searchGuide(self, init=False, key=None, value=None):
        """
        obj.searchGuide(**args) -> list of Guide objects

        Supports the following keywords:
            chanid,     starttime,  endtime,    title,      subtitle,
            category,   airdate,    stars,      previouslyshown,
            stereo,     subtitled,  hdtv,       closecaptioned,
            partnumber, parttotal,  seriesid,   originalairdate,
            showtype,   programid,  generic,    syndicatedepisodenumber,
            ondate,     cast,       startbefore,startafter
            endbefore,  endafter
        """
        if init:
            init.table = 'program'
            init.handler = Guide
            init.joins = (init.Join(table='credits',
                                    tableto='program',
                                    fields=('chanid', 'starttime')),
                          init.Join(table='people',
                                    tableto='credits',
                                    fields=('person', )))

        if key in ('chanid', 'title', 'subtitle', 'category', 'airdate',
                   'stars', 'previouslyshown', 'stereo', 'subtitled', 'hdtv',
                   'closecaptioned', 'partnumber', 'parttotal', 'seriesid',
                   'originalairdate', 'showtype', 'syndicatedepisodenumber',
                   'programid', 'generic'):
            return ('%s=%%s' % key, value, 0)
        if key in ('starttime', 'endtime'):
            return ('%s=%%s' % key, datetime.duck(value), 0)
        if key == 'ondate':
            return ('DATE(starttime)=%s', value, 0)
        if key == 'cast':
            return ('people.name', 'credits', 2, 0)
        if key == 'startbefore':
            return ('starttime<%s', datetime.duck(value), 0)
        if key == 'startafter':
            return ('starttime>%s', datetime.duck(value), 0)
        if key == 'endbefore':
            return ('endtime<%s', datetime.duck(value), 0)
        if key == 'endafter':
            return ('endtime>%s', datetime.duck(value), 0)
        return None
Beispiel #22
0
    def searchGuide(self, init=False, key=None, value=None):
        """
        obj.searchGuide(**args) -> list of Guide objects

        Supports the following keywords:
            chanid,     starttime,  endtime,    title,      subtitle,
            category,   airdate,    stars,      previouslyshown,
            stereo,     subtitled,  hdtv,       closecaptioned,
            partnumber, parttotal,  seriesid,   originalairdate,
            showtype,   programid,  generic,    syndicatedepisodenumber,
            ondate,     cast,       startbefore,startafter
            endbefore,  endafter
        """
        if init:
            init.table = 'program'
            init.handler = Guide
            init.joins = (init.Join(table='credits',
                                    tableto='program',
                                    fields=('chanid','starttime')),
                          init.Join(table='people',
                                    tableto='credits',
                                    fields=('person',)))

        if key in ('chanid','title','subtitle',
                        'category','airdate','stars','previouslyshown','stereo',
                        'subtitled','hdtv','closecaptioned','partnumber',
                        'parttotal','seriesid','originalairdate','showtype',
                        'syndicatedepisodenumber','programid','generic'):
            return ('%s=%%s' % key, value, 0)
        if key in ('starttime','endtime'):
            return ('%s=%%s' % key, datetime.duck(value), 0)
        if key == 'ondate':
            return ('DATE(starttime)=%s', value, 0)
        if key == 'cast':
            return ('people.name', 'credits', 2, 0)
        if key == 'startbefore':
            return ('starttime<%s', datetime.duck(value), 0)
        if key == 'startafter':
            return ('starttime>%s', datetime.duck(value), 0)
        if key == 'endbefore':
            return ('endtime<%s', datetime.duck(value), 0)
        if key == 'endafter':
            return ('endtime>%s', datetime.duck(value), 0)
        return None
Beispiel #23
0
 def getProgramDetails(self, chanid, starttime):
     """
     Returns a Program object for the matching show.
     """
     starttime = datetime.duck(starttime)
     args = {'ChanId': chanid, 'StartTime': starttime.isoformat()}
     return Program.fromJSON(
             self._request('Guide/GetProgramDetails', **args)\
                 .readJSON()['Program'],
             db=self.db)
Beispiel #24
0
    def getProgramGuide(self, starttime, endtime, startchan, numchan=None):
        """
        Returns a list of Guide objects corresponding to the given time period.
        """
        starttime = datetime.duck(starttime)
        endtime = datetime.duck(endtime)
        args = {'StartTime':starttime.isoformat().rsplit('.',1)[0],
                'EndTime':endtime.isoformat().rsplit('.',1)[0], 
                'StartChanId':startchan, 'Details':1}
        if numchan:
            args['NumOfChannels'] = numchan
        else:
            args['NumOfChannels'] = 1

        dat = self._request('Guide/GetProgramGuide', **args).readJSON()
        for chan in dat['ProgramGuide']['Channels']:
            for prog in chan['Programs']:
                prog['ChanId'] = chan['ChanId']
                yield Guide.fromJSON(prog, self.db)
Beispiel #25
0
    def getProgramGuide(self, starttime, endtime, startchan, numchan=None):
        """
        Returns a list of Guide objects corresponding to the given time period.
        """
        starttime = datetime.duck(starttime)
        endtime = datetime.duck(endtime)
        args = {'StartTime':starttime.isoformat().rsplit('.',1)[0],
                'EndTime':endtime.isoformat().rsplit('.',1)[0], 
                'StartChanId':startchan, 'Details':1}
        if numchan:
            args['NumOfChannels'] = numchan
        else:
            args['NumOfChannels'] = 1

        tree = self._queryTree('GetProgramGuide', **args)
        for chan in tree.find('ProgramGuide').find('Channels').getchildren():
            chanid = int(chan.attrib['chanId'])
            for guide in chan.getchildren():
                yield Guide.fromEtree((chanid, guide), self.db)
Beispiel #26
0
 def getRecording(self, chanid, starttime):
     """FileOps.getRecording(chanid, starttime) -> Program object"""
     starttime = datetime.duck(starttime)
     res = self.backendCommand('QUERY_RECORDING TIMESLOT %s %s' \
                     % (chanid, starttime.mythformat()))\
                 .split(BACKEND_SEP)
     if res[0] == 'ERROR':
         return None
     else:
         return Program(res[1:], db=self.db)
Beispiel #27
0
 def getProgramDetails(self, chanid, starttime):
     """
     Returns a Program object for the matching show.
     """
     starttime = datetime.duck(starttime)
     args = {'ChanId': chanid, 'StartTime': starttime.isoformat()}
     return Program.fromJSON(
             self._request('Guide/GetProgramDetails', **args)\
                 .readJSON()['Program'],
             db=self.db)
Beispiel #28
0
 def getRecording(self, chanid, starttime):
     """FileOps.getRecording(chanid, starttime) -> Program object"""
     starttime = datetime.duck(starttime)
     res = self.backendCommand('QUERY_RECORDING TIMESLOT %s %s' \
                     % (chanid, starttime.mythformat()))\
                 .split(BACKEND_SEP)
     if res[0] == 'ERROR':
         return None
     else:
         return Program(res[1:], db=self.db)
Beispiel #29
0
    def getProgramGuide(self, starttime, endtime, startchan, numchan=None):
        """
        Returns a list of Guide objects corresponding to the given time period.
        """
        starttime = datetime.duck(starttime)
        endtime = datetime.duck(endtime)
        args = {'StartTime':starttime.isoformat().rsplit('.',1)[0],
                'EndTime':endtime.isoformat().rsplit('.',1)[0], 
                'StartChanId':startchan, 'Details':1}
        if numchan:
            args['NumOfChannels'] = numchan
        else:
            args['NumOfChannels'] = 1

        dat = self._request('Guide/GetProgramGuide', **args).readJSON()
        for chan in dat['ProgramGuide']['Channels']:
            for prog in chan['Programs']:
                prog['ChanId'] = chan['ChanId']
                yield Guide.fromJSON(prog, self.db)
Beispiel #30
0
    def getProgramGuide(self, starttime, endtime, startchan, numchan=None):
        """
        Returns a list of Guide objects corresponding to the given time period.
        """
        starttime = datetime.duck(starttime)
        endtime = datetime.duck(endtime)
        args = {'StartTime':starttime.isoformat().rsplit('.',1)[0],
                'EndTime':endtime.isoformat().rsplit('.',1)[0], 
                'StartChanId':startchan, 'Details':1}
        if numchan:
            args['NumOfChannels'] = numchan
        else:
            args['NumOfChannels'] = 1

        tree = self._queryTree('GetProgramGuide', **args)
        for chan in tree.find('ProgramGuide').find('Channels').getchildren():
            chanid = int(chan.attrib['chanId'])
            for guide in chan.getchildren():
                yield Guide.fromEtree((chanid, guide), self.db)
Beispiel #31
0
    def getPreviewImage(self, chanid, starttime, width=None, height=None, secsin=None):
        starttime = datetime.duck(starttime)
        args = {"ChanId": chanid, "StartTime": starttime.isoformat()}
        if width:
            args["Width"] = width
        if height:
            args["Height"] = height
        if secsin:
            args["SecsIn"] = secsin

        return self._result("Content/GetPreviewImage", **args).read()
Beispiel #32
0
    def getProgramGuide(self, starttime, endtime, startchan, numchan=None):
        """
        Returns a list of Guide objects corresponding to the given time period.
        """
        starttime = datetime.duck(starttime)
        endtime = datetime.duck(endtime)
        args = {
            "StartTime": starttime.isoformat().rsplit(".", 1)[0],
            "EndTime": endtime.isoformat().rsplit(".", 1)[0],
            "StartChanId": startchan,
            "Details": 1,
        }
        if numchan:
            args["NumOfChannels"] = numchan
        else:
            args["NumOfChannels"] = 1

        tree = self._queryTree("GetProgramGuide", **args)
        for chan in tree.find("ProgramGuide").find("Channels").getchildren():
            chanid = int(chan.attrib["chanId"])
            for guide in chan.getchildren():
                yield Guide.fromEtree((chanid, guide), self.db)
Beispiel #33
0
    def getProgramGuide(self, starttime, endtime, startchan, numchan=None):
        """
        Returns a list of Guide objects corresponding to the given time period.
        """
        starttime = datetime.duck(starttime)
        endtime = datetime.duck(endtime)
        args = {
            "StartTime": starttime.isoformat().rsplit(".", 1)[0],
            "EndTime": endtime.isoformat().rsplit(".", 1)[0],
            "StartChanId": startchan,
            "Details": 1,
        }
        if numchan:
            args["NumOfChannels"] = numchan
        else:
            args["NumOfChannels"] = 1

        dat = self._request("Guide/GetProgramGuide", **args).readJSON()
        for chan in dat["ProgramGuide"]["Channels"]:
            for prog in chan["Programs"]:
                prog["ChanId"] = chan["ChanId"]
                yield Guide.fromJSON(prog, self.db)
Beispiel #34
0
    def searchOldRecorded(self, init=False, key=None, value=None):
        """
        obj.searchOldRecorded(**kwargs) -> list of OldRecorded objects

        Supports the following keywords:
            title,      subtitle,   chanid,     starttime,  endtime,
            category,   seriesid,   programid,  station,    duplicate,
            generic,    recstatus
        """

        if init:
            return ('oldrecorded', OldRecorded, ())
        if key in ('title','subtitle','chanid',
                        'category','seriesid','programid','station',
                        'duplicate','generic','recstatus'):
            return ('oldrecorded.%s=%%s' % key, value, 0)
                # time matches
        if key in ('starttime','endtime'):
            return ('oldrecorded.%s=%%s' % key, datetime.duck(value), 0)
        return None
Beispiel #35
0
    def searchOldRecorded(self, init=False, key=None, value=None):
        """
        obj.searchOldRecorded(**kwargs) -> list of OldRecorded objects

        Supports the following keywords:
            title,      subtitle,   chanid,     starttime,  endtime,
            category,   seriesid,   programid,  station,    duplicate,
            generic,    recstatus
        """

        if init:
            init.table = 'oldrecorded'
            init.handler = OldRecorded

        if key in ('title','subtitle','chanid',
                        'category','seriesid','programid','station',
                        'duplicate','generic','recstatus'):
            return ('oldrecorded.%s=%%s' % key, value, 0)
                # time matches
        if key in ('starttime','endtime'):
            return ('oldrecorded.%s=%%s' % key, datetime.duck(value), 0)
        return None
Beispiel #36
0
 def __init__(self, data=None, db=None):
     if data is not None:
         if None not in data:
             data = [data[0], datetime.duck(data[1])]
     DBDataWrite.__init__(self, data, db)
Beispiel #37
0
 def __init__(self, data=None, db=None):
     if data is not None:
         if None not in data:
             data = [data[0], datetime.duck(data[1])]
     DBDataWrite.__init__(self, data, db)
Beispiel #38
0
    def searchGuide(self, init=False, key=None, value=None):
        """
        obj.searchGuide(**args) -> list of Guide objects

        Supports the following keywords:
            chanid,     starttime,  endtime,    title,      subtitle,
            category,   airdate,    stars,      previouslyshown,
            stereo,     subtitled,  hdtv,       closecaptioned,
            partnumber, parttotal,  seriesid,   originalairdate,
            showtype,   programid,  generic,    syndicatedepisodenumber,
            ondate,     cast,       startbefore,startafter
            endbefore,  endafter,   dayofweek,  weekday
            first,      last,       callsign,   commfree
            channelgroup,           videosource,
            genre,      rating,     cast,       fuzzytitle
            fuzzysubtitle,          fuzzydescription,
            fuzzyprogramid,         beforedate, afterdate,
        """
        if init:
            init.table = 'program'
            init.handler = Guide
            init.joins = (init.Join(table='credits',
                                    tableto='program',
                                    fields=('chanid','starttime')),
                          init.Join(table='people',
                                    tableto='credits',
                                    fields=('person',)),
                          init.Join(table='channel',
                                    tableto='program',
                                    fields=('chanid',)),
                          init.Join(table='channelgroup',
                                    tableto='program',
                                    fields=('chanid',)),
                          init.Join(table='channelgroupnames',
                                    tableto='channelgroup',
                                    fields=('grpid',)),
                          init.Join(table='videosource',
                                    tableto='channel',
                                    fields=('sourceid',)),
                          init.Join(table='programgenres',
                                    tableto='program',
                                    fields=('chanid','starttime')),
                          init.Join(table='programrating',
                                    tableto='program',
                                    fields=('chanid','starttime')))
            return None

        if key in ('chanid','title','subtitle',
                        'category','airdate','stars','previouslyshown','stereo',
                        'subtitled','hdtv','closecaptioned','partnumber',
                        'parttotal','seriesid','originalairdate','showtype',
                        'syndicatedepisodenumber','programid','generic',
                        'category_type'):
            return ('program.%s=?' % key, value, 0)
        if key in ('starttime','endtime'):
            return ('program.%s=?' % key, datetime.duck(value), 0)
        if key == 'dayofweek':
            return ('DAYNAME(program.starttime)=?', value, 0)
        if key == 'weekday':
            return ('WEEKDAY(program.starttime)<?', 5, 0)
        if key in ('first', 'last'):
            return ('program.%s=?' % key, 1, 0)

        if key == 'callsign':
            return ('channel.callsign=?', value, 4)
        if key == 'commfree':
            return ('channel.commmethod=?', -2, 4)
        if key == 'channelgroup':
            return ('channelgroupnames.name=?', value, 24)
        if key == 'videosource':
            try:
                value = int(value)
                return ('channel.sourceid=?', value, 4)
            except:
                return ('videosource.name=?', value, 36)
        if key == 'genre':
            return ('programgenres.genre=?', value, 64)
        if key == 'rating':
            return ('programrating.rating=?', value, 128)
        if key == 'cast':
            return ('people.name', 'credits', 2, 0)

        if key.startswith('fuzzy'):
            if key[5:] in ('title', 'subtitle', 'description', 'programid'):
                return ('program.%s LIKE ?' % key[5:], '%'+value+'%', 0)
            if key[5:] == 'callsign':
                return ('channel.callsign LIKE ?', '%'+value+'%', 4)
        if key.endswith('date'):
            prefix = {'on':'=', 'before':'<', 'after':'>'}
            if key[:-4] in prefix:
                return ('DATE(program.starttime){0}?'.format(prefix[key[:-4]]),
                        value, 0)

        if key == 'startbefore':
            return ('program.starttime<?', datetime.duck(value), 0)
        if key == 'startafter':
            return ('program.starttime>?', datetime.duck(value), 0)
        if key == 'endbefore':
            return ('program.endtime<?', datetime.duck(value), 0)
        if key == 'endafter':
            return ('program.endtime>?', datetime.duck(value), 0)
        return None
Beispiel #39
0
    def searchRecorded(self, init=False, key=None, value=None):
        """
        obj.searchRecorded(**kwargs) -> list of Recorded objects

        Supports the following keywords:
            title,      subtitle,   chanid,     starttime,  progstart,
            category,   hostname,   autoexpire, commflagged,
            stars,      recgroup,   playgroup,  duplicate,  transcoded,
            watched,    storagegroup,           category_type,
            airdate,    stereo,     subtitled,  hdtv,       closecaptioned,
            partnumber, parttotal,  seriesid,   showtype,   programid,
            manualid,   generic,    cast,       livetv,     basename,
            syndicatedepisodenumber,            olderthan,  newerthan,
            inetref,    season,     episode

        Multiple keywords can be chained as such:
            obj.searchRecorded(title='Title', commflagged=False)
        """

        if init:
            # table and join descriptor
            init.table = "recorded"
            init.handler = Recorded
            init.require = ("livetv",)
            init.joins = (
                init.Join(table="recordedprogram", tableto="recorded", fields=("chanid", "starttime")),
                init.Join(
                    table="recordedcredits",
                    tableto="recorded",
                    fieldsfrom=("chanid", "starttime"),
                    fieldsto=("chanid", "progstart"),
                ),
                init.Join(table="people", tableto="recordedcredits", fields=("person",)),
            )
            return None

        # local table matches
        if key in (
            "title",
            "subtitle",
            "chanid",
            "category",
            "hostname",
            "autoexpire",
            "commflagged",
            "stars",
            "recgroup",
            "playgroup",
            "duplicate",
            "transcoded",
            "watched",
            "storagegroup",
            "basename",
            "inetref",
            "season",
            "episode",
        ):
            return ("recorded.%s=%%s" % key, value, 0)

        # time matches
        if key in ("starttime", "endtime", "progstart", "progend"):
            return ("recorded.%s=?" % key, datetime.duck(value), 0)

        if key == "olderthan":
            return ("recorded.starttime<?", datetime.duck(value), 0)
        if key == "newerthan":
            return ("recorded.starttime>?", datetime.duck(value), 0)

        # recordedprogram matches
        if key in (
            "category_type",
            "airdate",
            "stereo",
            "subtitled",
            "hdtv",
            "closecaptioned",
            "partnumber",
            "parttotal",
            "seriesid",
            "showtype",
            "syndicatedepisodenumber",
            "programid",
            "manualid",
            "generic",
        ):
            return ("recordedprogram.%s=?" % key, value, 1)

        if key == "cast":
            return ("people.name", "recordedcredits", 4, 1)

        if key == "livetv":
            if (value is None) or (value == False):
                return ("recorded.recgroup!=?", "LiveTV", 0)
            return ()

        return None
Beispiel #40
0
    def searchGuide(self, init=False, key=None, value=None):
        """
        obj.searchGuide(**args) -> list of Guide objects

        Supports the following keywords:
            chanid,     starttime,  endtime,    title,      subtitle,
            category,   airdate,    stars,      previouslyshown,
            stereo,     subtitled,  hdtv,       closecaptioned,
            partnumber, parttotal,  seriesid,   originalairdate,
            showtype,   programid,  generic,    syndicatedepisodenumber,
            ondate,     cast,       startbefore,startafter
            endbefore,  endafter,   dayofweek,  weekday
            first,      last,       callsign,   commfree
            channelgroup,           videosource,
            genre,      rating,     cast,       fuzzytitle
            fuzzysubtitle,          fuzzydescription,
            fuzzyprogramid,         beforedate, afterdate,
        """
        if init:
            init.table = "program"
            init.handler = Guide
            init.joins = (
                init.Join(table="credits", tableto="program", fields=("chanid", "starttime")),
                init.Join(table="people", tableto="credits", fields=("person",)),
                init.Join(table="channel", tableto="program", fields=("chanid",)),
                init.Join(table="channelgroup", tableto="program", fields=("chanid",)),
                init.Join(table="channelgroupnames", tableto="channelgroup", fields=("grpid",)),
                init.Join(table="videosource", tableto="channel", fields=("sourceid",)),
                init.Join(table="programgenres", tableto="program", fields=("chanid", "starttime")),
                init.Join(table="programrating", tableto="program", fields=("chanid", "starttime")),
            )
            return None

        if key in (
            "chanid",
            "title",
            "subtitle",
            "category",
            "airdate",
            "stars",
            "previouslyshown",
            "stereo",
            "subtitled",
            "hdtv",
            "closecaptioned",
            "partnumber",
            "parttotal",
            "seriesid",
            "originalairdate",
            "showtype",
            "syndicatedepisodenumber",
            "programid",
            "generic",
            "category_type",
        ):
            return ("program.%s=?" % key, value, 0)
        if key in ("starttime", "endtime"):
            return ("program.%s=?" % key, datetime.duck(value), 0)
        if key == "dayofweek":
            return ("DAYNAME(program.starttime)=?", value, 0)
        if key == "weekday":
            return ("WEEKDAY(program.starttime)<?", 5, 0)
        if key in ("first", "last"):
            return ("program.%s=?" % key, 1, 0)

        if key == "callsign":
            return ("channel.callsign=?", value, 4)
        if key == "commfree":
            return ("channel.commmethod=?", -2, 4)
        if key == "channelgroup":
            return ("channelgroupnames.name=?", value, 24)
        if key == "videosource":
            try:
                value = int(value)
                return ("channel.sourceid=?", value, 4)
            except:
                return ("videosource.name=?", value, 36)
        if key == "genre":
            return ("programgenres.genre=?", value, 64)
        if key == "rating":
            return ("programrating.rating=?", value, 128)
        if key == "cast":
            return ("people.name", "credits", 2, 0)

        if key.startswith("fuzzy"):
            if key[5:] in ("title", "subtitle", "description", "programid"):
                return ("program.%s LIKE ?" % key[5:], "%" + value + "%", 0)
            if key[5:] == "callsign":
                return ("channel.callsign LIKE ?", "%" + value + "%", 4)
        if key.endswith("date"):
            prefix = {"on": "=", "before": "<", "after": ">"}
            if key[:-4] in prefix:
                return ("DATE(program.starttime){0}?".format(prefix[key[:-4]]), value, 0)

        if key == "startbefore":
            return ("program.starttime<?", datetime.duck(value), 0)
        if key == "startafter":
            return ("program.starttime>?", datetime.duck(value), 0)
        if key == "endbefore":
            return ("program.endtime<?", datetime.duck(value), 0)
        if key == "endafter":
            return ("program.endtime>?", datetime.duck(value), 0)
        return None
Beispiel #41
0
    def searchRecorded(self, init=False, key=None, value=None):
        """
        obj.searchRecorded(**kwargs) -> list of Recorded objects

        Supports the following keywords:
            title,      subtitle,   chanid,     starttime,  progstart,
            category,   hostname,   autoexpire, commflagged,
            stars,      recgroup,   playgroup,  duplicate,  transcoded,
            watched,    storagegroup,           category_type,
            airdate,    stereo,     subtitled,  hdtv,       closecaptioned,
            partnumber, parttotal,  seriesid,   showtype,   programid,
            manualid,   generic,    cast,       livetv,     basename,
            syndicatedepisodenumber,            olderthan,  newerthan

        Multiple keywords can be chained as such:
            obj.searchRecorded(title='Title', commflagged=False)
        """

        if init:
            # table and join descriptor
            init.table = 'recorded'
            init.handler = Recorded
            init.require = ('livetv',)
            init.joins = (init.Join(table='recordedprogram',
                                    tableto='recorded',
                                    fields=('chanid','starttime')),
                          init.Join(table='recordedcredits',
                                    tableto='recorded',
                                    fieldsfrom=('chanid','starttime'),
                                    fieldsto=('chanid','progstart')),
                          init.Join(table='people',
                                    tableto='recordedcredits',
                                    fields=('person',)))

        # local table matches
        if key in ('title','subtitle','chanid',
                        'category','hostname','autoexpire','commflagged',
                        'stars','recgroup','playgroup','duplicate',
                        'transcoded','watched','storagegroup','basename'):
            return ('recorded.%s=%%s' % key, value, 0)

        # time matches
        if key in ('starttime','endtime','progstart','progend'):
            return ('recorded.%s=%%s' % key, datetime.duck(value), 0)

        if key == 'olderthan':
            return ('recorded.starttime<%s', datetime.duck(value), 0)
        if key == 'newerthan':
            return ('recorded.starttime>%s', datetime.duck(value), 0)

        # recordedprogram matches
        if key in ('category_type','airdate','stereo','subtitled','hdtv',
                    'closecaptioned','partnumber','parttotal','seriesid',
                    'showtype','syndicatedepisodenumber','programid',
                    'manualid','generic'):
            return ('recordedprogram.%s=%%s' % key, value, 1)

        if key == 'cast':
            return ('people.name', 'recordedcredits', 4, 1)

        if key == 'livetv':
            if (value is None) or (value == False):
                return ('recorded.recgroup!=%s', 'LiveTV', 0)
            return ()

        return None
Beispiel #42
0
    def searchGuide(self, init=False, key=None, value=None):
        """
        obj.searchGuide(**args) -> list of Guide objects

        Supports the following keywords:
            chanid,     starttime,  endtime,    title,      subtitle,
            category,   airdate,    stars,      previouslyshown,
            stereo,     subtitled,  hdtv,       closecaptioned,
            partnumber, parttotal,  seriesid,   originalairdate,
            showtype,   programid,  generic,    syndicatedepisodenumber,
            ondate,     cast,       startbefore,startafter
            endbefore,  endafter,   dayofweek,  weekday
            first,      last,       callsign,   commfree
            channelgroup,           videosource,
            genre,      rating,     cast,       fuzzytitle
            fuzzysubtitle,          fuzzydescription,
            fuzzyprogramid,         beforedate, afterdate,
        """
        if init:
            init.table = 'program'
            init.handler = Guide
            init.joins = (init.Join(table='credits',
                                    tableto='program',
                                    fields=('chanid','starttime')),
                          init.Join(table='people',
                                    tableto='credits',
                                    fields=('person',)),
                          init.Join(table='channel',
                                    tableto='program',
                                    fields=('chanid',)),
                          init.Join(table='channelgroup',
                                    tableto='program',
                                    fields=('chanid',)),
                          init.Join(table='channelgroupnames',
                                    tableto='channelgroup',
                                    fields=('grpid',)),
                          init.Join(table='videosource',
                                    tableto='channel',
                                    fields=('sourceid',)),
                          init.Join(table='programgenres',
                                    tableto='program',
                                    fields=('chanid','starttime')),
                          init.Join(table='programrating',
                                    tableto='program',
                                    fields=('chanid','starttime')))
            return None

        if key in ('chanid','title','subtitle',
                        'category','airdate','stars','previouslyshown','stereo',
                        'subtitled','hdtv','closecaptioned','partnumber',
                        'parttotal','seriesid','originalairdate','showtype',
                        'syndicatedepisodenumber','programid','generic',
                        'category_type'):
            return ('program.%s=?' % key, value, 0)
        if key in ('starttime','endtime'):
            return ('program.%s=?' % key, datetime.duck(value), 0)
        if key == 'dayofweek':
            return ('DAYNAME(program.starttime)=?', value, 0)
        if key == 'weekday':
            return ('WEEKDAY(program.starttime)<?', 5, 0)
        if key in ('first', 'last'):
            return ('program.%s=?' % key, 1, 0)

        if key == 'callsign':
            return ('channel.callsign=?', value, 4)
        if key == 'commfree':
            return ('channel.commmethod=?', -2, 4)
        if key == 'channelgroup':
            return ('channelgroupnames.name=?', value, 24)
        if key == 'videosource':
            try:
                value = int(value)
                return ('channel.sourceid=?', value, 4)
            except:
                return ('videosource.name=?', value, 36)
        if key == 'genre':
            return ('programgenres.genre=?', value, 64)
        if key == 'rating':
            return ('programrating.rating=?', value, 128)
        if key == 'cast':
            return ('people.name', 'credits', 2, 0)

        if key.startswith('fuzzy'):
            if key[5:] in ('title', 'subtitle', 'description', 'programid'):
                return ('program.%s LIKE ?' % key[5:], '%'+value+'%', 0)
            if key[5:] == 'callsign':
                return ('channel.callsign LIKE ?', '%'+value+'%', 4)
        if key.endswith('date'):
            prefix = {'on':'=', 'before':'<', 'after':'>'}
            if key[:-4] in prefix:
                return ('DATE(program.starttime){0}?'.format(prefix[key[:-4]]),
                        value, 0)

        if key == 'startbefore':
            return ('program.starttime<?', datetime.duck(value), 0)
        if key == 'startafter':
            return ('program.starttime>?', datetime.duck(value), 0)
        if key == 'endbefore':
            return ('program.endtime<?', datetime.duck(value), 0)
        if key == 'endafter':
            return ('program.endtime>?', datetime.duck(value), 0)
        return None