def test_datetime_000_18(self):
        """Test method 'MythTV.datetime.rfcformat()"""

        dt22 = self.ut.split(" ", 1)[1]
        dt22 = dt22.rsplit(" ", 1)[0]
        dtiso = datetime.fromIso(dt22, tz='UTC')
        trfc = dtiso.rfcformat()
        #print(trfc)                            # Sun, 31 May 2020 11:10:44 +0000

        dt23 = self.lt.split(" ", 1)[1]
        dt23 = dt23.rsplit(" ", 1)[0]
        dtiso = datetime.fromIso(dt23)
        trfc1 = dtiso.rfcformat()
        #print(trfc1)                           # Sun, 31 May 2020 13:10:44 +0200

        dttrfc = datetime.duck(trfc)
        dttrfc1 = datetime.duck(trfc1)

        #print(dttrfc)
        #print(dttrfc1)

        self.assertTrue(isinstance(dttrfc, MythTV.utility.dt.datetime),
                        "Unknown type returned from 'rfcfomat()'")
        self.assertTrue(isinstance(dttrfc, MythTV.utility.dt.datetime),
                        "Unknown type returned from 'rfcfomat()'")

        self.assertEqual((dttrfc1 - dttrfc), timedelta(seconds=0),
                         "Wrong time calculated from 'rfcformat()'")
    def test_Methodheap_MythDB_001_searchRecorded_05(self):
        """Test 'seachRecorded' method from MythTV.MythDB() using 'olderthan' and 'newerthan'.
           Time values are passed in UTC and ISO format.
        """

        # substract / add 1 minute from/to starttime
        starttime_before = int(self.testenv['RECSTARTTIMEMYTH']) - 100
        starttime_after  = int(self.testenv['RECSTARTTIMEMYTH']) + 100

        # transform to utc iso, like '2019-03-05T12:50:00Z'
        starttime_before_utc_iso = datetime.duck(starttime_before).utcisoformat() +"Z"
        starttime_after_utc_iso  = datetime.duck(starttime_after).utcisoformat() +"Z"

        recs =  self.mydb.searchRecorded( chanid = self.testenv['RECCHANID']
                                        , olderthan = starttime_after_utc_iso
                                        , newerthan = starttime_before_utc_iso
                                        )
        rec01 = next(recs)

        self.assertTrue(isinstance(rec01, Recorded))
        # check if accessing a property works
        self.assertTrue(rec01.basename == self.testenv['RECBASENAME'])
    def test_datetime_002_01(self):
        """Test 'ISO' to 'UTC' conversion in respect to daylight saving time of 'America/Anchorage'
           using 'datetime.duck()' method.
        """

        for i, t in enumerate(self.t_iso_list):
            t_duck = datetime.duck(t)
            t_org = t_duck.isoformat()
            self.assertTrue(isinstance(t_duck, datetime))
            # check if conversion works:
            self.assertEqual(t_org, self.t_utc_list[i])
            # check for correct types:
            self.assertTrue(isinstance(t_duck, datetime))
            self.assertTrue('posixtzinfo' in repr(t_duck.tzinfo))
    def test_datetime_001_04(self):
        """Test 'mythtime (i.e. integer time)' to 'UTC' conversion in respect to daylight saving time of 'Europe/Vienna'
           using 'datetime.duck()' method.
        """

        for i,t in enumerate(self.t_mtime_list):
            t_duck = datetime.duck(t)
            t_org  = t_duck.isoformat()
            self.assertTrue(isinstance(t_duck, datetime))
            # check if conversion works:
            self.assertEqual(t_org, self.t_mtime_utc_list[i])
            # check for correct types:
            self.assertTrue(isinstance(t_duck, datetime))
            self.assertTrue('posixtzinfo' in repr(t_duck.tzinfo))
    def test_Methodheap_MythDB_003_searchArtwork_02(self):
        """Test 'searchArtwork' method from MythTV.MythDB(),
           given 'chanid', 'starttime'.
        """

        # get the sattime in UTC and ISO format: like '2019-03-05T12:51:00Z'
        starttime_utc_iso = datetime.duck(self.testenv['RECSTARTTIMEMYTH']).utcisoformat() +"Z"
        artworks =  self.mydb.searchArtwork( chanid = self.testenv['RECCHANID']
                                           , starttime = starttime_utc_iso
                                           )
        artwork  =  next(artworks)
        self.assertTrue(isinstance(artwork, RecordedArtwork))
        # check if accessing a property works
        self.assertTrue(artwork.coverart.data == "%s_coverart.jpg" % self.testenv['RECINETREF'])
def FindProgram(xmlprog, fuzzy):
    tvmode = xmlprog.find('tv-mode').text
    chan = None
    if tvmode == 'cable':
        # for cable, require a match of channel and station name
        for c in Channel.getAllEntries(db=DB):
            if c.freqid == xmlprog.find('rf-channel').text and \
               c.mplexid == 32767 and \
               c.callsign == xmlprog.find('station').text:
                chan = c
                break
        else:
            if not fuzzy:
                return None
    elif tvmode in ('digital_cable', 'satellite'):
        # for digital cable and satellite, use station name only
        for c in Channel.getAllEntries(db=DB):
            if c.callsign == xmlprog.find('station').text:
                chan = c
                break
        else:
            if not fuzzy:
                return None
    elif tvmode == 'digital':
        # for broadcast digital, go with PSIP channel
        # fall back to physical channel and stream id
        for c in Channel.getAllEntries():
            if c.atsc_major_chan == int(xmlprog.find('psip-major').text) and \
               c.atsc_major_chan == int(xmlprog.find('psip-minor').text):
                chan = c
                break
        else:
            for c in Channel.getAllEntries(db=DB):
                if c.freqid == xmlprog.find('rf-channel').text and \
                   c.serviceid == xmlprog.find('stream-number').text:
                    chan = c
                    break
            else:
                if not fuzzy:
                    return None

    starttime = datetime.duck(xmlprog.find('start-date').text +\
                              xmlprog.find('start-time').text.replace(':','') +\
                              '00') + tzoff
    endtime = datetime.duck(xmlprog.find('end-date').text +\
                            xmlprog.find('end-time').text.replace(':','') +\
                            '00') + tzoff
    title = xmlprog.find('program-title').text
    try: subtitle = xmlprog.find('episode-title').text
    except AttributeError: subtitle = None

    if chan:
        # there should only be one response to the query
        try:
            prog = DB.searchGuide(chanid = chan.chanid,
                                  startafter = starttime-timedelta(0,300),
                                  startbefore = starttime+timedelta(0,300),
                                  endafter = endtime-timedelta(0,300),
                                  endbefore = endtime+timedelta(0,300)).next()
        except StopIteration:
            return None

        if prog.title == xmlprog.find('program-title').text:
            if not subtitle:
                # direct movie match
                return prog
            if prog.subtitle == subtitle:
                # direct television match
                return prog
            if fuzzy:
                # close enough
                return prog
        return None

    else:
        progs = list(DB.searchGuide(title = xmlprog.find('program-title').text,
                                    startafter = starttime-timedelta(0,300),
                                    startbefore = starttime+timedelta(0,300),
                                    endafter = endtime-timedelta(0,300),
                                    endbefore = endtime+timedelta(0,300)))
        if len(progs) == 0:
            return None

        if not subtitle:
            # nothing that can be used to better match, just pick the first
            return progs[0]

        for prog in progs:
            if prog.subtitle == subtitle:
                # best option
                return prog
        else:
            # no direct match, just pick the first
            return progs[0]
Example #7
0
def FindProgram(xmlprog, fuzzy):
    tvmode = xmlprog.find('tv-mode').text
    chan = None
    if tvmode == 'cable':
        # for cable, require a match of channel and station name
        for c in Channel.getAllEntries(db=DB):
            if c.freqid == xmlprog.find('rf-channel').text and \
               c.mplexid == 32767 and \
               c.callsign == xmlprog.find('station').text:
                chan = c
                break
        else:
            if not fuzzy:
                return None
    elif tvmode in ('digital_cable', 'satellite'):
        # for digital cable and satellite, use station name only
        for c in Channel.getAllEntries(db=DB):
            if c.callsign == xmlprog.find('station').text:
                chan = c
                break
        else:
            if not fuzzy:
                return None
    elif tvmode == 'digital':
        # for broadcast digital, go with PSIP channel
        # fall back to physical channel and stream id
        for c in Channel.getAllEntries():
            if c.atsc_major_chan == int(xmlprog.find('psip-major').text) and \
               c.atsc_major_chan == int(xmlprog.find('psip-minor').text):
                chan = c
                break
        else:
            for c in Channel.getAllEntries(db=DB):
                if c.freqid == xmlprog.find('rf-channel').text and \
                   c.serviceid == xmlprog.find('stream-number').text:
                    chan = c
                    break
            else:
                if not fuzzy:
                    return None

    starttime = datetime.duck(xmlprog.find('start-date').text +\
                              xmlprog.find('start-time').text.replace(':','') +\
                              '00') + tzoff
    endtime = datetime.duck(xmlprog.find('end-date').text +\
                            xmlprog.find('end-time').text.replace(':','') +\
                            '00') + tzoff
    title = xmlprog.find('program-title').text
    try:
        subtitle = xmlprog.find('episode-title').text
    except AttributeError:
        subtitle = None

    if chan:
        # there should only be one response to the query
        try:
            prog = DB.searchGuide(chanid=chan.chanid,
                                  startafter=starttime - timedelta(0, 300),
                                  startbefore=starttime + timedelta(0, 300),
                                  endafter=endtime - timedelta(0, 300),
                                  endbefore=endtime +
                                  timedelta(0, 300)).next()
        except StopIteration:
            return None

        if prog.title == xmlprog.find('program-title').text:
            if not subtitle:
                # direct movie match
                return prog
            if prog.subtitle == subtitle:
                # direct television match
                return prog
            if fuzzy:
                # close enough
                return prog
        return None

    else:
        progs = list(
            DB.searchGuide(title=xmlprog.find('program-title').text,
                           startafter=starttime - timedelta(0, 300),
                           startbefore=starttime + timedelta(0, 300),
                           endafter=endtime - timedelta(0, 300),
                           endbefore=endtime + timedelta(0, 300)))
        if len(progs) == 0:
            return None

        if not subtitle:
            # nothing that can be used to better match, just pick the first
            return progs[0]

        for prog in progs:
            if prog.subtitle == subtitle:
                # best option
                return prog
        else:
            # no direct match, just pick the first
            return progs[0]