Пример #1
0
def startup():
    directory = os.path.dirname(ADDON_PROFILE + os.sep + "images")

    try:
        if not os.path.exists(directory):
            os.makedirs(directory)
    except:
        pass

    directory = os.path.dirname(ADDON_PROFILE + os.sep + "cache")

    try:
        if not os.path.exists(directory):
            os.makedirs(directory)
    except:
        pass

    system, arch = get_system_arch()
    proxyserver_port = find_free_port()

    query = "UPDATE `vars` SET `arch`='{arch}', `system`='{system}', `test_running`=0, `proxyserver_port`={proxyserver_port} WHERE profile_id={profile_id}".format(arch=arch, system=system, proxyserver_port=proxyserver_port, profile_id=1)
    query_settings(query=query, return_result=False, return_insert=False, commit=True)

    hourly(type=0)
    daily()
    change_icon()

    update_prefs()

    hourly(type=2)
Пример #2
0
def _reset(**kwargs):
    if not gui.yes_no(_.PLUGIN_RESET_YES_NO):
        return

    _close()

    try:
        xbmc.executeJSONRPC(
            '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":false}}}}'
            .format(ADDON_ID))

        profile_settings = load_profile(profile_id=1)
        proxyserver_port = int(profile_settings['proxyserver_port'])
        system = profile_settings['system']
        arch = profile_settings['arch']

        shutil.rmtree(ADDON_PROFILE)

        directory = os.path.dirname(ADDON_PROFILE + os.sep + "images")

        try:
            if not os.path.exists(directory):
                os.makedirs(directory)
        except:
            pass

        directory = os.path.dirname(ADDON_PROFILE + os.sep + "cache")

        try:
            if not os.path.exists(directory):
                os.makedirs(directory)
        except:
            pass

        query = "UPDATE `vars` SET `arch`='{arch}', `system`='{system}', `test_running`=0, `proxyserver_port`={proxyserver_port} WHERE profile_id={profile_id}".format(
            arch=arch,
            system=system,
            proxyserver_port=proxyserver_port,
            profile_id=1)
        query_settings(query=query,
                       return_result=False,
                       return_insert=False,
                       commit=True)

        download_files()
        update_settings()
        update_prefs()
    except:
        pass

    xbmc.executeJSONRPC(
        '{{"jsonrpc":"2.0","id":1,"method":"Addons.SetAddonEnabled","params":{{"addonid":"{}","enabled":true}}}}'
        .format(ADDON_ID))

    gui.notification(_.PLUGIN_RESET_OK)
    signals.emit(signals.AFTER_RESET)
    gui.refresh()
Пример #3
0
def startup():
    system, arch = get_system_arch()
    proxyserver_port = find_free_port()

    query = "UPDATE `vars` SET `arch`='{arch}', `system`='{system}', `test_running`=0, `proxyserver_port`={proxyserver_port} WHERE profile_id={profile_id}".format(arch=arch, system=system, proxyserver_port=proxyserver_port, profile_id=1)
    query_settings(query=query, return_result=False, return_insert=False, commit=True)

    hourly(type=0)
    daily()
    change_icon()

    update_prefs()

    hourly(type=2)
Пример #4
0
    def test_channels(self, tested=False, channel=None):
        profile_settings = load_profile(profile_id=1)

        if channel:
            channel = unicode(channel)

        try:
            if not profile_settings[
                    'last_login_success'] == 1 or not settings.getBool(
                        key='run_tests'):
                return 5

            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                test_running=1, profile_id=1)
            query_settings(query=query,
                           return_result=False,
                           return_insert=False,
                           commit=True)

            query = "SELECT * FROM `channels`"
            channels = query_epg(query=query,
                                 return_result=True,
                                 return_insert=False,
                                 commit=False)
            results = load_tests(profile_id=1)

            count = 0
            first = True
            last_tested_found = False
            test_run = False
            user_agent = profile_settings['user_agent']

            if not results:
                results = {}

            for row in channels:
                if count == 5 or (count == 1 and tested):
                    if test_run:
                        update_prefs()

                    query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                        test_running=0, profile_id=1)
                    query_settings(query=query,
                                   return_result=False,
                                   return_insert=False,
                                   commit=True)
                    return count

                id = unicode(row['id'])

                if len(id) > 0:
                    if channel:
                        if not id == channel:
                            continue
                    elif tested:
                        if unicode(profile_settings['last_tested']) == id:
                            last_tested_found = True
                            continue
                        elif last_tested_found:
                            pass
                        else:
                            continue

                    if check_key(results, id) and not tested and not first:
                        continue

                    livebandwidth = 0
                    replaybandwidth = 0
                    live = 0
                    replay = 0
                    epg = 0
                    guide = 0

                    profile_settings = load_profile(profile_id=1)

                    if profile_settings['last_playing'] > int(time.time() -
                                                              300):
                        if test_run:
                            update_prefs()

                        query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                            test_running=0, profile_id=1)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)
                        return 5

                    playdata = self.play_url(type='channel',
                                             channel=id,
                                             id=row['assetid'],
                                             test=True)

                    if first and not profile_settings['last_login_success']:
                        if test_run:
                            update_prefs()

                        query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                            test_running=0, profile_id=1)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)
                        return 5

                    if len(playdata['path']) > 0:
                        CDMHEADERS = CONST_BASE_HEADERS
                        CDMHEADERS['User-Agent'] = user_agent
                        playdata['path'] = playdata['path'].split("&", 1)[0]
                        session = Session(headers=CDMHEADERS)
                        resp = session.get(playdata['path'])

                        if resp.status_code == 200:
                            livebandwidth = find_highest_bandwidth(
                                xml=resp.text)
                            live = 1

                    if check_key(results, id) and first and not tested:
                        first = False

                        if live == 1:
                            continue
                        else:
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                    first = False
                    counter = 0

                    while not self._abortRequested and not xbmc.Monitor(
                    ).abortRequested() and counter < 5:
                        if self._abortRequested or xbmc.Monitor().waitForAbort(
                                1):
                            self._abortRequested = True
                            break

                        counter += 1

                        profile_settings = load_profile(profile_id=1)

                        if profile_settings['last_playing'] > int(time.time() -
                                                                  300):
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                    if self._abortRequested or xbmc.Monitor().abortRequested():
                        return 5

                    program_url = '{api_url}/TRAY/AVA/TRENDING/YESTERDAY?maxResults=1&filter_channelIds={channel}'.format(
                        api_url=profile_settings['api_url'],
                        channel=channeldata['channel_id'])
                    download = self.download(url=program_url,
                                             type='get',
                                             headers=None,
                                             data=None,
                                             json_data=False,
                                             return_json=True)
                    data = download['data']
                    resp = download['resp']

                    if resp and resp.status_code == 200 and data and check_key(
                            data, 'resultCode'
                    ) and data['resultCode'] == 'OK' and check_key(
                            data, 'resultObj') and check_key(
                                data['resultObj'], 'containers') and check_key(
                                    data['resultObj']['containers'][0], 'id'):
                        profile_settings = load_profile(profile_id=1)

                        if profile_settings['last_playing'] > int(time.time() -
                                                                  300):
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                        playdata = self.play_url(
                            type='program',
                            channel=id,
                            id=data['resultObj']['containers'][0]['id'],
                            test=True)

                        if len(playdata['path']) > 0:
                            CDMHEADERS = CONST_BASE_HEADERS
                            CDMHEADERS['User-Agent'] = user_agent
                            playdata['path'] = playdata['path'].split(
                                "&min_bitrate", 1)[0]
                            session = Session(headers=CDMHEADERS)
                            resp = session.get(playdata['path'])

                            if resp.status_code == 200:
                                replaybandwidth = find_highest_bandwidth(
                                    xml=resp.text)
                                replay = 1

                    query = "SELECT id FROM `epg` WHERE channel='{channel}' LIMIT 1".format(
                        channel=id)
                    data = query_epg(query=query,
                                     return_result=True,
                                     return_insert=False,
                                     commit=False)

                    if len(data) > 0:
                        guide = 1

                        if live == 1:
                            epg = 1

                    if not self._abortRequested:
                        query = "UPDATE `vars` SET `last_tested`='{last_tested}' WHERE profile_id={profile_id}".format(
                            last_tested=id, profile_id=1)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)

                        query = "REPLACE INTO `tests_{profile_id}` VALUES ('{id}', '{live}', '{livebandwidth}', '{replay}', '{replaybandwidth}', '{epg}', '{guide}')".format(
                            profile_id=1,
                            id=id,
                            live=live,
                            livebandwidth=livebandwidth,
                            replay=replay,
                            replaybandwidth=replaybandwidth,
                            epg=epg,
                            guide=guide)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)

                    test_run = True
                    counter = 0

                    while not self._abortRequested and not xbmc.Monitor(
                    ).abortRequested() and counter < 15:
                        if self._abortRequested or xbmc.Monitor().waitForAbort(
                                1):
                            self._abortRequested = True
                            break

                        counter += 1

                        profile_settings = load_profile(profile_id=1)

                        if profile_settings['last_playing'] > int(time.time() -
                                                                  300):
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                    if self._abortRequested or xbmc.Monitor().abortRequested():
                        return 5

                    count += 1
        except:
            if test_run:
                update_prefs()

            count = 5

        query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
            test_running=0, profile_id=1)
        query_settings(query=query,
                       return_result=False,
                       return_insert=False,
                       commit=True)

        return count
Пример #5
0
    def test_channels(self, tested=False, channel=None):
        profile_settings = load_profile(profile_id=1)

        if channel:
            channel = unicode(channel)

        try:
            if not profile_settings[
                    'last_login_success'] == 1 or not settings.getBool(
                        key='run_tests') or not self.get_session():
                return 5

            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                test_running=1, profile_id=1)
            query_settings(query=query,
                           return_result=False,
                           return_insert=False,
                           commit=True)

            query = "SELECT * FROM `channels`"
            channels = query_epg(query=query,
                                 return_result=True,
                                 return_insert=False,
                                 commit=False)
            results = load_tests(profile_id=1)

            count = 0
            first = True
            last_tested_found = False
            test_run = False
            user_agent = profile_settings['user_agent']

            if not results:
                results = {}

            for row in channels:
                if count == 5 or (count == 1 and tested):
                    if test_run:
                        update_prefs()

                    query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                        test_running=0, profile_id=1)
                    query_settings(query=query,
                                   return_result=False,
                                   return_insert=False,
                                   commit=True)
                    return count

                id = unicode(row['id'])

                if len(id) > 0:
                    if channel:
                        if not id == channel:
                            continue
                    elif tested:
                        if unicode(profile_settings['last_tested']) == id:
                            last_tested_found = True
                            continue
                        elif last_tested_found:
                            pass
                        else:
                            continue

                    if check_key(results, id) and not tested and not first:
                        continue

                    livebandwidth = 0
                    replaybandwidth = 0
                    live = 0
                    replay = 0
                    epg = 0
                    guide = 0

                    profile_settings = load_profile(profile_id=1)

                    if profile_settings['last_playing'] > int(time.time() -
                                                              300):
                        if test_run:
                            update_prefs()

                        query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                            test_running=0, profile_id=1)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)
                        return 5

                    playdata = self.play_url(type='channel',
                                             channel=id,
                                             id=None,
                                             test=True)

                    if first and not profile_settings['last_login_success']:
                        if test_run:
                            update_prefs()

                        query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                            test_running=0, profile_id=1)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)
                        return 5

                    if len(playdata['path']) > 0:
                        CDMHEADERS = {
                            'User-Agent': user_agent,
                            'X_CSRFToken': profile_settings['csrf_token'],
                            'Cookie': playdata['license']['cookie'],
                        }

                        if check_key(playdata, 'license') and check_key(
                                playdata['license'], 'triggers') and check_key(
                                    playdata['license']['triggers'][0],
                                    'licenseURL'):
                            if check_key(playdata['license']['triggers'][0],
                                         'customData'):
                                CDMHEADERS[
                                    'AcquireLicense.CustomData'] = playdata[
                                        'license']['triggers'][0]['customData']
                                CDMHEADERS[
                                    'CADeviceType'] = 'Widevine OTT client'

                        session = Session(headers=CDMHEADERS)
                        resp = session.get(playdata['path'])

                        if resp.status_code == 200:
                            livebandwidth = find_highest_bandwidth(
                                xml=resp.text)
                            live = 1

                    if check_key(results, id) and first and not tested:
                        first = False

                        if live == 1:
                            continue
                        else:
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                    first = False
                    counter = 0

                    while not self._abortRequested and not xbmc.Monitor(
                    ).abortRequested() and counter < 5:
                        if self._abortRequested or xbmc.Monitor().waitForAbort(
                                1):
                            self._abortRequested = True
                            break

                        counter += 1

                        profile_settings = load_profile(profile_id=1)

                        if profile_settings['last_playing'] > int(time.time() -
                                                                  300):
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                    if self._abortRequested or xbmc.Monitor().abortRequested():
                        return 5

                    militime = int(int(time.time() - 86400) * 1000)

                    session_post_data = {
                        'needChannel': '0',
                        'queryChannel': {
                            'channelIDs': [
                                id,
                            ],
                            'isReturnAllMedia': '1',
                        },
                        'queryPlaybill': {
                            'count': '1',
                            'endTime': militime,
                            'isFillProgram': '1',
                            'offset': '0',
                            'startTime': militime,
                            'type': '0',
                        }
                    }

                    headers = CONST_BASE_HEADERS
                    headers.update({'Content-Type': 'application/json'})
                    headers.update(
                        {'X_CSRFToken': profile_settings['csrf_token']})

                    channel_url = '{base_url}/VSP/V3/QueryPlaybillListStcProps?SID=queryPlaybillListStcProps3&DEVICE=PC&DID={deviceID}&from=throughMSAAccess'.format(
                        base_url=CONST_BASE_URL,
                        deviceID=profile_settings['devicekey'])

                    download = self.download(url=channel_url,
                                             type='post',
                                             headers=headers,
                                             data=session_post_data,
                                             json_data=True,
                                             return_json=True)
                    data = download['data']
                    resp = download['resp']

                    if resp and resp.status_code == 200 and data and check_key(
                            data, 'channelPlaybills') and check_key(
                                data['channelPlaybills'][0],
                                'playbillLites') and check_key(
                                    data['channelPlaybills'][0]
                                    ['playbillLites'][0], 'ID'):
                        profile_settings = load_profile(profile_id=1)

                        if profile_settings['last_playing'] > int(time.time() -
                                                                  300):
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                        playdata = self.play_url(type='program',
                                                 channel=id,
                                                 id=data['channelPlaybills'][0]
                                                 ['playbillLites'][0]['ID'],
                                                 test=True)

                        if len(playdata['path']) > 0:
                            CDMHEADERS = {
                                'User-Agent': user_agent,
                                'X_CSRFToken': profile_settings['csrf_token'],
                                'Cookie': playdata['license']['cookie'],
                            }

                            if check_key(playdata, 'license') and check_key(
                                    playdata['license'],
                                    'triggers') and check_key(
                                        playdata['license']['triggers'][0],
                                        'licenseURL'):
                                if check_key(
                                        playdata['license']['triggers'][0],
                                        'customData'):
                                    CDMHEADERS[
                                        'AcquireLicense.CustomData'] = playdata[
                                            'license']['triggers'][0][
                                                'customData']
                                    CDMHEADERS[
                                        'CADeviceType'] = 'Widevine OTT client'

                            session = Session(headers=CDMHEADERS)
                            resp = session.get(playdata['path'])

                            if resp.status_code == 200:
                                replaybandwidth = find_highest_bandwidth(
                                    xml=resp.text)
                                replay = 1

                    query = "SELECT id FROM `epg` WHERE channel='{channel}' LIMIT 1".format(
                        channel=id)
                    data = query_epg(query=query,
                                     return_result=True,
                                     return_insert=False,
                                     commit=False)

                    if len(data) > 0:
                        guide = 1

                        if live == 1:
                            epg = 1

                    if not self._abortRequested:
                        query = "UPDATE `vars` SET `last_tested`='{last_tested}' WHERE profile_id={profile_id}".format(
                            last_tested=id, profile_id=1)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)

                        query = "REPLACE INTO `tests_{profile_id}` VALUES ('{id}', '{live}', '{livebandwidth}', '{replay}', '{replaybandwidth}', '{epg}', '{guide}')".format(
                            profile_id=1,
                            id=id,
                            live=live,
                            livebandwidth=livebandwidth,
                            replay=replay,
                            replaybandwidth=replaybandwidth,
                            epg=epg,
                            guide=guide)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)

                    test_run = True
                    counter = 0

                    while not self._abortRequested and not xbmc.Monitor(
                    ).abortRequested() and counter < 15:
                        if self._abortRequested or xbmc.Monitor().waitForAbort(
                                1):
                            self._abortRequested = True
                            break

                        counter += 1

                        profile_settings = load_profile(profile_id=1)

                        if profile_settings['last_playing'] > int(time.time() -
                                                                  300):
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                    if self._abortRequested or xbmc.Monitor().abortRequested():
                        return 5

                    count += 1
        except:
            if test_run:
                update_prefs()

            count = 5

        query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
            test_running=0, profile_id=1)
        query_settings(query=query,
                       return_result=False,
                       return_insert=False,
                       commit=True)

        return count
Пример #6
0
    def test_channels(self, tested=False, channel=None):
        profile_settings = load_profile(profile_id=1)

        if channel:
            channel = unicode(channel)

        try:
            if not profile_settings[
                    'last_login_success'] == 1 or not settings.getBool(
                        key='run_tests'):
                return 5

            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                test_running=1, profile_id=1)
            query_settings(query=query,
                           return_result=False,
                           return_insert=False,
                           commit=True)

            query = "SELECT * FROM `channels`"
            channels = query_epg(query=query,
                                 return_result=True,
                                 return_insert=False,
                                 commit=False)
            results = load_tests(profile_id=1)

            count = 0
            first = True
            last_tested_found = False
            test_run = False
            user_agent = profile_settings['user_agent']

            if not results:
                results = {}

            for row in channels:
                if count == 5 or (count == 1 and tested):
                    if test_run:
                        update_prefs()

                    query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                        test_running=0, profile_id=1)
                    query_settings(query=query,
                                   return_result=False,
                                   return_insert=False,
                                   commit=True)
                    return count

                id = unicode(row['id'])

                if len(id) > 0:
                    if channel:
                        if not id == channel:
                            continue
                    elif tested:
                        if unicode(profile_settings['last_tested']) == id:
                            last_tested_found = True
                            continue
                        elif last_tested_found:
                            pass
                        else:
                            continue

                    if check_key(results, id) and not tested and not first:
                        continue

                    livebandwidth = 0
                    replaybandwidth = 0
                    live = 0
                    replay = 0
                    epg = 0
                    guide = 0

                    profile_settings = load_profile(profile_id=1)

                    if profile_settings['last_playing'] > int(time.time() -
                                                              300):
                        if test_run:
                            update_prefs()

                        query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                            test_running=0, profile_id=1)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)
                        return 5

                    playdata = self.play_url(type='channel',
                                             channel=id,
                                             id=id,
                                             test=True)

                    if first and not profile_settings['last_login_success']:
                        if test_run:
                            update_prefs()

                        query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                            test_running=0, profile_id=1)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)
                        return 5

                    if len(playdata['path']) > 0:
                        CDMHEADERS = CONST_BASE_HEADERS
                        CDMHEADERS['User-Agent'] = user_agent
                        session = Session(headers=CDMHEADERS)
                        resp = session.get(playdata['path'])

                        if resp.status_code == 200:
                            livebandwidth = find_highest_bandwidth(
                                xml=resp.text)
                            live = 1

                    if check_key(results, id) and first and not tested:
                        first = False

                        if live == 1:
                            continue
                        else:
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                    first = False
                    counter = 0

                    while not self._abortRequested and not xbmc.Monitor(
                    ).abortRequested() and counter < 5:
                        if self._abortRequested or xbmc.Monitor().waitForAbort(
                                1):
                            self._abortRequested = True
                            break

                        counter += 1

                        profile_settings = load_profile(profile_id=1)

                        if profile_settings['last_playing'] > int(time.time() -
                                                                  300):
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                    if self._abortRequested or xbmc.Monitor().abortRequested():
                        return 5

                    headers = CONST_BASE_HEADERS
                    headers.update({
                        'Authorization':
                        'Bearer ' + profile_settings['session_token']
                    })
                    yesterday = datetime.datetime.now() - datetime.timedelta(1)
                    fromtime = datetime.datetime.strftime(
                        yesterday, '%Y-%m-%dT%H:%M:%S.000Z')
                    tilltime = datetime.datetime.strftime(
                        yesterday, '%Y-%m-%dT%H:%M:59.999Z')

                    program_url = "{api_url}/schedule?channels={id}&from={fromtime}&until={tilltime}".format(
                        api_url=CONST_DEFAULT_API,
                        id=id,
                        fromtime=fromtime,
                        tilltime=tilltime)

                    download = self.download(url=program_url,
                                             type='get',
                                             headers=headers,
                                             data=None,
                                             json_data=False,
                                             return_json=True)
                    data = download['data']
                    resp = download['resp']

                    if resp and resp.status_code == 200 and data and check_key(
                            data, 'epg') and check_key(data['epg'][0], 'id'):
                        profile_settings = load_profile(profile_id=1)

                        if profile_settings['last_playing'] > int(time.time() -
                                                                  300):
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                        playdata = self.play_url(type='program',
                                                 channel=id,
                                                 id=data['epg'][0]['id'],
                                                 test=True)

                        if len(playdata['path']) > 0:
                            CDMHEADERS = CONST_BASE_HEADERS
                            CDMHEADERS['User-Agent'] = user_agent
                            session = Session(headers=CDMHEADERS)
                            resp = session.get(playdata['path'])

                            if resp.status_code == 200:
                                replaybandwidth = find_highest_bandwidth(
                                    xml=resp.text)
                                replay = 1

                    query = "SELECT id FROM `epg` WHERE channel='{channel}' LIMIT 1".format(
                        channel=id)
                    data = query_epg(query=query,
                                     return_result=True,
                                     return_insert=False,
                                     commit=False)

                    if len(data) > 0:
                        guide = 1

                        if live == 1:
                            epg = 1

                    if not self._abortRequested:
                        query = "UPDATE `vars` SET `last_tested`='{last_tested}' WHERE profile_id={profile_id}".format(
                            last_tested=id, profile_id=1)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)

                        query = "REPLACE INTO `tests_{profile_id}` VALUES ('{id}', '{live}', '{livebandwidth}', '{replay}', '{replaybandwidth}', '{epg}', '{guide}')".format(
                            profile_id=1,
                            id=id,
                            live=live,
                            livebandwidth=livebandwidth,
                            replay=replay,
                            replaybandwidth=replaybandwidth,
                            epg=epg,
                            guide=guide)
                        query_settings(query=query,
                                       return_result=False,
                                       return_insert=False,
                                       commit=True)

                    test_run = True
                    counter = 0

                    while not self._abortRequested and not xbmc.Monitor(
                    ).abortRequested() and counter < 15:
                        if self._abortRequested or xbmc.Monitor().waitForAbort(
                                1):
                            self._abortRequested = True
                            break

                        counter += 1

                        profile_settings = load_profile(profile_id=1)

                        if profile_settings['last_playing'] > int(time.time() -
                                                                  300):
                            if test_run:
                                update_prefs()

                            query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
                                test_running=0, profile_id=1)
                            query_settings(query=query,
                                           return_result=False,
                                           return_insert=False,
                                           commit=True)
                            return 5

                    if self._abortRequested or xbmc.Monitor().abortRequested():
                        return 5

                    count += 1
        except:
            if test_run:
                update_prefs()

            count = 5

        query = "UPDATE `vars` SET `test_running`={test_running} WHERE profile_id={profile_id}".format(
            test_running=0, profile_id=1)
        query_settings(query=query,
                       return_result=False,
                       return_insert=False,
                       commit=True)

        return count