Example #1
0
def api_get_channels():
    channels_url = '{dut_epg_url}/channels.json'.format(
        dut_epg_url=CONST_DUT_EPG)
    file = "cache" + os.sep + "channels.json"

    if not is_file_older_than_x_days(file=ADDON_PROFILE + file, days=1):
        data = load_file(file=file, isJSON=True)
    else:
        download = api_download(url=channels_url,
                                type='get',
                                headers=None,
                                data=None,
                                json_data=True,
                                return_json=True)
        data = download['data']
        code = download['code']

        if code and code == 200 and data:
            write_file(file=file, data=data, isJSON=True)
            update_prefs(profile_id=1, channels=data)
        else:
            return None

        change_icon()
        clear_cache()

    data2 = OrderedDict()

    for currow in data:
        row = data[currow]
        data2[currow] = row

    return data2
Example #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()
Example #3
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)

    service_timer('startup')
Example #4
0
def api_get_channels():
    channels_url = '{dut_epg_url}/channels.json'.format(
        dut_epg_url=CONST_DUT_EPG)
    file = os.path.join("cache", "channels.json")

    if check_key(CONST_MOD_CACHE, 'channels'):
        days = CONST_MOD_CACHE['channels']
    else:
        days = 1

    if not is_file_older_than_x_days(file=os.path.join(ADDON_PROFILE, file),
                                     days=days):
        data = load_file(file=file, isJSON=True)
    else:
        download = api_download(url=channels_url,
                                type='get',
                                headers=None,
                                data=None,
                                json_data=True,
                                return_json=True)
        data = download['data']
        code = download['code']

        if code and code == 200 and data:
            write_file(file=file, data=data, isJSON=True)
            update_prefs(profile_id=1, channels=data)
        else:
            return None

        clear_cache()

    data2 = OrderedDict()

    for currow in data:
        row = data[currow]
        data2[currow] = row

    return data2
Example #5
0
def api_test_channels(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 api_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 = api_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 xbmc.Monitor().abortRequested() and counter < 5:
                    if xbmc.Monitor().waitForAbort(1):
                        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 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 = {'Content-Type': 'application/json', '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 = api_download(url=channel_url, type='post', headers=headers, data=session_post_data, json_data=True, return_json=True)
                data = download['data']
                code = download['code']

                if code and 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 = api_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 xbmc.Monitor().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 xbmc.Monitor().abortRequested() and counter < 15:
                    if xbmc.Monitor().waitForAbort(1):
                        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 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
Example #6
0
def api_test_channels(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 api_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 = api_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 = {}

                    if check_key(playdata, 'license') and check_key(playdata['license'], 'drmConfig') and check_key(playdata['license']['drmConfig'], 'widevine'):
                        if 'nlznl.solocoo.tv' in playdata['license']['drmConfig']['widevine']['drmServerUrl']:
                            if xbmc.Monitor().waitForAbort(1):
                                return 5

                        if check_key(playdata['license']['drmConfig']['widevine'], 'customHeaders'):
                            for row in playdata['license']['drmConfig']['widevine']['customHeaders']:
                                CDMHEADERS[row] = playdata['license']['drmConfig']['widevine']['customHeaders'][row]

                    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 xbmc.Monitor().abortRequested() and counter < 5:
                    if xbmc.Monitor().waitForAbort(1):
                        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 xbmc.Monitor().abortRequested():
                    return 5

                yesterday = datetime.datetime.now() - datetime.timedelta(1)
                fromtime = datetime.datetime.strftime(yesterday, "%Y-%m-%dT%H%M%S")
                channel_url = '{base_url}/v6/epg/locations/{friendly}/live/1?fromDate={date}'.format(base_url=CONST_API_URL, friendly=channeldata['channel_friendly'], date=fromtime)

                download = api_download(url=channel_url, type='get', headers=None, data=None, json_data=False, return_json=True)
                data = download['data']
                code = download['code']

                if code and code == 200 and data:
                    for row in data:
                        if check_key(row, 'Channel') and check_key(row, 'Locations'):
                            for row2 in row['Locations']:
                                program_id = row2['LocationId']

                if program_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 = api_play_url(type='program', channel=id, id=program_id, test=True)

                    if len(playdata['path']) > 0:
                        CDMHEADERS = {}

                        if check_key(playdata, 'license') and check_key(playdata['license'], 'drmConfig') and check_key(playdata['license']['drmConfig'], 'widevine'):
                            if 'nlznl.solocoo.tv' in playdata['license']['drmConfig']['widevine']['drmServerUrl']:
                                if xbmc.Monitor().waitForAbort(1):
                                    return 5

                            if check_key(playdata['license']['drmConfig']['widevine'], 'customHeaders'):
                                for row in playdata['license']['drmConfig']['widevine']['customHeaders']:
                                    CDMHEADERS[row] = playdata['license']['drmConfig']['widevine']['customHeaders'][row]

                        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 xbmc.Monitor().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 xbmc.Monitor().abortRequested() and counter < 15:
                    if xbmc.Monitor().waitForAbort(1):
                        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 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
Example #7
0
def api_test_channels(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 api_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 = api_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 xbmc.Monitor().abortRequested() and counter < 5:
                    if xbmc.Monitor().waitForAbort(1):
                        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 xbmc.Monitor().abortRequested():
                    return 5

                headers = {
                    '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 = api_download(url=program_url,
                                        type='get',
                                        headers=headers,
                                        data=None,
                                        json_data=False,
                                        return_json=True)
                data = download['data']
                code = download['code']

                if code and 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 = api_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 xbmc.Monitor().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 xbmc.Monitor().abortRequested() and counter < 15:
                    if xbmc.Monitor().waitForAbort(1):
                        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 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
Example #8
0
def api_test_channels(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 api_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']
        listing_url = profile_settings['listings_url']

        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 = api_play_url(type='channel',
                                        id=row['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 = {
                        'User-Agent': user_agent,
                        'X-Client-Id':
                        profile_settings['client_id'] + '||' + user_agent,
                        'X-OESP-Token': profile_settings['access_token'],
                        'X-OESP-Username': profile_settings['username'],
                        'X-OESP-License-Token': profile_settings['drm_token'],
                        'X-OESP-DRM-SchemeIdUri':
                        'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed',
                        'X-OESP-Content-Locator': playdata['locator'],
                    }

                    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 xbmc.Monitor().abortRequested() and counter < 5:
                    if xbmc.Monitor().waitForAbort(1):
                        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 xbmc.Monitor().abortRequested():
                    return 5

                listing_url = '{listings_url}?byEndTime={time}~&byStationId={channel}&range=1-1&sort=startTime'.format(
                    listings_url=listing_url,
                    time=int(int(time.time() - 86400) * 1000),
                    channel=id)
                download = api_download(url=listing_url,
                                        type='get',
                                        headers=api_get_headers(),
                                        data=None,
                                        json_data=False,
                                        return_json=True)
                data = download['data']
                code = download['code']

                program_id = None

                if code and code == 200 and data and check_key(
                        data, 'listings'):
                    for row in data['listings']:
                        program_id = row['id']

                if program_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 = api_play_url(type='program',
                                            id=program_id,
                                            test=True)

                    if len(playdata['path']) > 0:
                        CDMHEADERS = {
                            'User-Agent': user_agent,
                            'X-Client-Id':
                            profile_settings['client_id'] + '||' + user_agent,
                            'X-OESP-Token': profile_settings['access_token'],
                            'X-OESP-Username': profile_settings['username'],
                            'X-OESP-License-Token':
                            profile_settings['drm_token'],
                            'X-OESP-DRM-SchemeIdUri':
                            'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed',
                            'X-OESP-Content-Locator': playdata['locator'],
                        }

                        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 xbmc.Monitor().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 xbmc.Monitor().abortRequested() and counter < 15:
                    if xbmc.Monitor().waitForAbort(1):
                        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

                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
Example #9
0
def api_test_channels(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 api_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 = api_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 xbmc.Monitor().abortRequested() and counter < 5:
                    if xbmc.Monitor().waitForAbort(1):
                        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 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 = api_download(url=program_url,
                                        type='get',
                                        headers=None,
                                        data=None,
                                        json_data=False,
                                        return_json=True)
                data = download['data']
                code = download['code']

                if code and 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 = api_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 xbmc.Monitor().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 xbmc.Monitor().abortRequested() and counter < 15:
                    if xbmc.Monitor().waitForAbort(1):
                        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 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