示例#1
0
def first_boot():
    if gui.yes_no(message=_.SET_IPTV):
        try:
            plugin._set_settings_iptv()
        except:
            pass
    if gui.yes_no(message=_.SET_KODI):
        try:
            plugin._set_settings_kodi()
        except:
            pass

    settings.setBool(key='_first_boot', value=False)
示例#2
0
def check_iptv_link():
    if settings.getBool(key='enable_simple_iptv') == True:
        try:
            IPTV_SIMPLE = xbmcaddon.Addon(id="pvr.iptvsimple")

            if not IPTV_SIMPLE.getSetting("epgPath") == (ADDON_PROFILE + "epg.xml") or not IPTV_SIMPLE.getSetting("m3uPath") == (ADDON_PROFILE + "playlist.m3u8"):
                settings.setBool(key='enable_simple_iptv', value=False)
            else:
                user_agent = settings.get(key='_user_agent')

                if IPTV_SIMPLE.getSetting("userAgent") != user_agent:
                    IPTV_SIMPLE.setSetting("userAgent", user_agent)
        except:
            pass
示例#3
0
def check_iptv_link():
    if settings.getBool(key='enable_simple_iptv'):
        try:
            IPTV_SIMPLE = xbmcaddon.Addon(id="pvr.iptvsimple")

            if not IPTV_SIMPLE.getSetting("epgPath") == (ADDON_PROFILE + "epg.xml") or not IPTV_SIMPLE.getSetting("m3uPath") == (ADDON_PROFILE + "playlist.m3u8"):
                settings.setBool(key='enable_simple_iptv', value=False)
            else:
                profile_settings = load_profile(profile_id=1)

                if IPTV_SIMPLE.getSetting("userAgent") != profile_settings['user_agent']:
                    IPTV_SIMPLE.setSetting("userAgent", profile_settings['user_agent'])
        except:
            pass
示例#4
0
def startup():
    settings.setBool(key='_test_running', value=False)
    system, arch = get_system_arch()
    settings.set(key="_system", value=system)
    settings.set(key="_arch", value=arch)

    settings.setInt(key='_proxyserver_port', value=find_free_port())

    channels = False

    if settings.getInt(key='_channels_age') < int(time.time() - 86400):
        channels = True

    api.new_session(force=False, retry=False, channels=channels)
    api.update_prefs()

    hourly(type=0)
    daily()
    change_icon()
    hourly(type=2)
示例#5
0
def check_entitlements(**kwargs):
    if plugin.logged_in:
        user_agent = settings.get(key='_user_agent')
        media_groups_url = '{mediagroups_url}/lgi-nl-vod-myprime-movies?byHasCurrentVod=true&range=1-1&sort=playCount7%7Cdesc'.format(mediagroups_url=settings.get('_mediagroupsfeeds_url'))
        data = api.download(url=media_groups_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=False)

        if not data or not check_key(data, 'entryCount'):
            gui.ok(message=_.NO_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS)
            settings.setBool(key='showMoviesSeries', value=False)
            return

        media_item_url = '{mediaitem_url}/{mediaitem_id}'.format(mediaitem_url=settings.get(key='_mediaitems_url'), mediaitem_id=data['mediaGroups'][0]['id'])
        data = api.download(url=media_item_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=False)

        if not data or not check_key(data, 'videoStreams'):
            gui.ok(message=_.NO_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS)
            settings.setBool(key='showMoviesSeries', value=False)
            return

        urldata = get_play_url(content=data['videoStreams'])

        if not urldata or not check_key(urldata, 'play_url') or not check_key(urldata, 'locator'):
            gui.ok(message=_.NO_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS)
            settings.setBool(key='showMoviesSeries', value=False)
            return

        token = api.get_play_token(locator=urldata['locator'], force=True)

        if not token or not len(token) > 0:
            gui.ok(message=_.NO_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS)
            settings.setBool(key='showMoviesSeries', value=False)
            return

        gui.ok(message=_.YES_MOVIES_SERIES, heading=_.CHECKED_ENTITLEMENTS)
        settings.setBool(key='showMoviesSeries', value=True)

    return
示例#6
0
    def test_channels(self, tested=False, channel=None):
        if self._debug_mode:
            log.debug('Executing: api.test_channels')
            log.debug('Vars: tested={tested}, channel={channel}'.format(
                tested=tested, channel=channel))

        if channel:
            channel = unicode(channel)

        try:
            if not self._last_login_success or not settings.getBool(
                    key='run_tests'):
                return 5

            settings.setBool(key='_test_running', value=True)
            channels = load_file(file="channels.json", isJSON=True)
            results = load_file(file="channel_test.json", isJSON=True)

            count = 0
            first = True
            last_tested_found = False
            test_run = False
            user_agent = settings.get(key='_user_agent')

            if not results:
                results = {}

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

                    settings.setBool(key='_test_running', value=False)
                    return count

                channeldata = self.get_channel_data(row=row)
                id = unicode(channeldata['channel_id'])

                if len(id) > 0:
                    if channel:
                        if not id == channel:
                            continue
                    elif tested and check_key(results, 'last_tested'):
                        if unicode(results['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 = 'false'
                    replay = 'false'
                    epg = 'false'
                    guide = 'false'

                    if settings.getInt(key='_last_playing') > int(time.time() -
                                                                  300):
                        if test_run:
                            self.update_prefs()

                        settings.setBool(key='_test_running', value=False)
                        return 5

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

                    if first and not self._last_login_success:
                        if test_run:
                            self.update_prefs()

                        settings.setBool(key='_test_running', value=False)
                        return 5

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

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

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

                        if live == 'true':
                            continue
                        else:
                            if test_run:
                                self.update_prefs()

                            settings.setBool(key='_test_running', value=False)
                            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

                        if settings.getInt(
                                key='_last_playing') > int(time.time() - 300):
                            if test_run:
                                self.update_prefs()

                            settings.setBool(key='_test_running', value=False)
                            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=self._api_url,
                        channel=channeldata['channel_id'])
                    data = self.download(url=program_url,
                                         type='get',
                                         code=[200],
                                         data=None,
                                         json_data=False,
                                         data_return=True,
                                         return_json=True,
                                         retry=False,
                                         check_data=True)

                    if data and check_key(
                            data['resultObj'], 'containers') and check_key(
                                data['resultObj']['containers'][0], 'id'):
                        if settings.getInt(
                                key='_last_playing') > int(time.time() - 300):
                            if test_run:
                                self.update_prefs()

                            settings.setBool(key='_test_running', value=False)
                            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]
                            self._session2 = Session(headers=CDMHEADERS)
                            resp = self._session2.get(playdata['path'])

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

                    if os.path.isfile(ADDON_PROFILE + id + '_replay.json'):
                        guide = 'true'

                        if live == 'true':
                            epg = 'true'

                    results[id] = {
                        'id': id,
                        'live': live,
                        'replay': replay,
                        'livebandwidth': livebandwidth,
                        'replaybandwidth': replaybandwidth,
                        'epg': epg,
                        'guide': guide,
                    }

                    results['last_tested'] = id

                    if not self._abortRequested:
                        write_file(file="channel_test.json",
                                   data=results,
                                   isJSON=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

                        if settings.getInt(
                                key='_last_playing') > int(time.time() - 300):
                            if test_run:
                                self.update_prefs()

                            settings.setBool(key='_test_running', value=False)
                            return 5

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

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

            count = 5

        settings.setBool(key='_test_running', value=False)

        if self._debug_mode:
            log.debug('Execution Done: api.test_channels')

        return count
示例#7
0
    def new_session(self, force=False, retry=True, channels=False):
        self.check_vars()

        if self._debug_mode:
            log.debug('Executing: api.new_session')
            log.debug(
                'Vars: force={force}, retry={retry}, channels={channels}'.
                format(force=force, retry=retry, channels=channels))
            log.debug('Cookies: {cookies}'.format(cookies=self._cookies))

        username = self._username
        password = self._password

        if len(self._cookies) > 0 and len(
                username
        ) > 0 and not force and not channels and self._session_age > int(
                time.time() - 7200) and self._last_login_success:
            self.logged_in = True

            try:
                self._session
            except:
                self._session = Session(cookies_key='_cookies')

                if self._debug_mode:
                    log.debug('Creating new Requests Session')
                    log.debug('Request Session Headers')
                    log.debug(self._session.headers)
                    log.debug('api.logged_in: {logged_in}'.format(
                        logged_in=self.logged_in))

            return True

        self.logged_in = False

        if self._debug_mode:
            log.debug(
                'api.logged_in: {logged_in}'.format(logged_in=self.logged_in))

        if not len(username) > 0:
            if self._debug_mode:
                log.debug('Username length = 0')
                log.debug('Execution Done: api.new_session')

            settings.setBool(key="_last_login_success", value=self.logged_in)
            self._last_login_success = self.logged_in

            return False

        if not len(password) > 0:
            email_or_pin = settings.getBool(key='email_instead_of_customer')

            if not force:
                if self._debug_mode:
                    log.debug('Password length = 0 and force is false')
                    log.debug('Execution Done: api.new_session')

                settings.setBool(key="_last_login_success",
                                 value=self.logged_in)
                self._last_login_success = self.logged_in

                return False

            if email_or_pin:
                password = gui.input(message=_.ASK_PASSWORD2,
                                     hide_input=True).strip()
            else:
                password = gui.numeric(message=_.ASK_PASSWORD).strip()

            if not len(password) > 0:
                if self._debug_mode:
                    log.debug('Password length = 0')
                    log.debug('Execution Done: api.new_session')

                if email_or_pin:
                    gui.ok(message=_.EMPTY_PASS2, heading=_.LOGIN_ERROR_TITLE)
                else:
                    gui.ok(message=_.EMPTY_PASS, heading=_.LOGIN_ERROR_TITLE)

                settings.setBool(key="_last_login_success",
                                 value=self.logged_in)
                self._last_login_success = self.logged_in

                return False

        self.login(username=username,
                   password=password,
                   channels=channels,
                   retry=retry)

        if self._debug_mode:
            log.debug('Execution Done: api.new_session')
            log.debug(
                'api.logged_in: {logged_in}'.format(logged_in=self.logged_in))

        settings.setBool(key="_last_login_success", value=self.logged_in)
        self._last_login_success = self.logged_in

        if self.logged_in:
            return True

        return False
示例#8
0
def _set_settings_iptv(**kwargs):
    _close()

    try:
        IPTV_SIMPLE_ADDON_ID = "pvr.iptvsimple"

        try:
            IPTV_SIMPLE = xbmcaddon.Addon(id=IPTV_SIMPLE_ADDON_ID)
        except:
            xbmc.executebuiltin(
                'InstallAddon({})'.format(IPTV_SIMPLE_ADDON_ID), True)

        if IPTV_SIMPLE.getSettingBool("epgCache") != True:
            IPTV_SIMPLE.setSettingBool("epgCache", True)

        if IPTV_SIMPLE.getSettingInt("epgPathType") != 0:
            IPTV_SIMPLE.setSettingInt("epgPathType", 0)

        if IPTV_SIMPLE.getSetting("epgPath") != ADDON_PROFILE + "epg.xml":
            IPTV_SIMPLE.setSetting("epgPath", ADDON_PROFILE + "epg.xml")

        if IPTV_SIMPLE.getSetting("epgTimeShift") != "0":
            IPTV_SIMPLE.setSetting("epgTimeShift", "0")

        if IPTV_SIMPLE.getSettingBool("epgTSOverride") != False:
            IPTV_SIMPLE.setSettingBool("epgTSOverride", False)

        if get_kodi_version() > 18:
            if IPTV_SIMPLE.getSettingInt("m3uRefreshMode") != 2:
                IPTV_SIMPLE.setSettingInt("m3uRefreshMode", 2)

            if IPTV_SIMPLE.getSettingInt("m3uRefreshIntervalMins") != 60:
                IPTV_SIMPLE.setSettingInt("m3uRefreshIntervalMins", 60)

            if IPTV_SIMPLE.getSettingInt("m3uRefreshHour") != 4:
                IPTV_SIMPLE.setSettingInt("m3uRefreshHour", 4)

            if IPTV_SIMPLE.getSettingBool("catchupEnabled") != True:
                IPTV_SIMPLE.setSettingBool("catchupEnabled", True)

            if IPTV_SIMPLE.getSetting(
                    "catchupQueryFormat") != '&amp;catchup={catchup-id}':
                IPTV_SIMPLE.setSetting("catchupQueryFormat",
                                       '&amp;catchup={catchup-id}')

            if IPTV_SIMPLE.getSettingInt("catchupDays") != 7:
                IPTV_SIMPLE.setSettingInt("catchupDays", 7)

            if IPTV_SIMPLE.getSettingInt("allChannelsCatchupMode") != 2:
                IPTV_SIMPLE.setSettingInt("allChannelsCatchupMode", 2)

            if IPTV_SIMPLE.getSettingBool("catchupPlayEpgAsLive") != True:
                IPTV_SIMPLE.setSettingBool("catchupPlayEpgAsLive", True)

            if IPTV_SIMPLE.getSettingInt(
                    "catchupWatchEpgBeginBufferMins") != 5:
                IPTV_SIMPLE.setSettingInt("catchupWatchEpgBeginBufferMins", 5)

            if IPTV_SIMPLE.getSettingInt("catchupWatchEpgEndBufferMins") != 15:
                IPTV_SIMPLE.setSettingInt("catchupWatchEpgEndBufferMins", 15)

            if IPTV_SIMPLE.getSettingBool(
                    "catchupOnlyOnFinishedProgrammes") != True:
                IPTV_SIMPLE.setSettingBool("catchupOnlyOnFinishedProgrammes",
                                           True)

        if IPTV_SIMPLE.getSettingBool("m3uCache") != True:
            IPTV_SIMPLE.setSettingBool("m3uCache", True)

        if IPTV_SIMPLE.getSettingInt("m3uPathType") != 0:
            IPTV_SIMPLE.setSettingInt("m3uPathType", 0)

        if IPTV_SIMPLE.getSetting(
                "m3uPath") != ADDON_PROFILE + "playlist.m3u8":
            IPTV_SIMPLE.setSetting("m3uPath", ADDON_PROFILE + "playlist.m3u8")

        user_agent = settings.get(key='_user_agent')

        if IPTV_SIMPLE.getSetting("userAgent") != user_agent:
            IPTV_SIMPLE.setSetting("userAgent", user_agent)

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

        settings.setBool('enable_simple_iptv', True)
        gui.notification(_.DONE_REBOOT)
    except:
        pass
示例#9
0
    def test_channels(self, tested=False, channel=None):
        if self._debug_mode:
            log.debug('Executing: api.test_channels')
            log.debug('Vars: tested={tested}, channel={channel}'.format(tested=tested, channel=channel))

        if channel:
            channel = unicode(channel)

        try:
            if not self._last_login_success or not settings.getBool(key='run_tests'):
                return 5

            settings.setBool(key='_test_running', value=True)
            channels = load_file(file="channels.json", isJSON=True)
            results = load_file(file="channel_test.json", isJSON=True)

            count = 0
            first = True
            last_tested_found = False
            test_run = False
            user_agent = settings.get(key='_user_agent')

            if not results:
                results = {}

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

                    settings.setBool(key='_test_running', value=False)
                    return count

                channeldata = self.get_channel_data(row=row, channelno=1)
                id = unicode(channeldata['channel_id'])

                if len(id) > 0:
                    if channel:
                        if not id == channel:
                            continue
                    elif tested and check_key(results, 'last_tested'):
                        if unicode(results['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 = 'false'
                    replay = 'false'
                    epg = 'false'
                    guide = 'false'

                    if settings.getInt(key='_last_playing') > int(time.time() - 300):
                        if test_run:
                            self.update_prefs()

                        settings.setBool(key='_test_running', value=False)
                        return 5

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

                    if first and not self._last_login_success:
                        if test_run:
                            self.update_prefs()

                        settings.setBool(key='_test_running', value=False)
                        return 5

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

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

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

                        if live == 'true':
                            continue
                        else:
                            if test_run:
                                self.update_prefs()

                            settings.setBool(key='_test_running', value=False)
                            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

                        if settings.getInt(key='_last_playing') > int(time.time() - 300):
                            if test_run:
                                self.update_prefs()

                            settings.setBool(key='_test_running', value=False)
                            return 5

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

                    self._session.headers = CONST_BASE_HEADERS
                    self._session.headers.update({'Authorization': 'Bearer ' + self._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);
                    data = self.download(url=program_url, type="get", code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=False, allow_redirects=False)

                    if data and check_key(data, 'epg') and check_key(data['epg'][0], 'id'):
                        if settings.getInt(key='_last_playing') > int(time.time() - 300):
                            if test_run:
                                self.update_prefs()

                            settings.setBool(key='_test_running', value=False)
                            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
                            self._session2 = Session(headers=CDMHEADERS)
                            resp = self._session2.get(playdata['path'])

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

                    if os.path.isfile(ADDON_PROFILE + id + '_replay.json'):
                        guide = 'true'

                        if live == 'true':
                            epg = 'true'

                    results[id] = {
                        'id': id,
                        'live': live,
                        'replay': replay,
                        'livebandwidth': livebandwidth,
                        'replaybandwidth': replaybandwidth,
                        'epg': epg,
                        'guide': guide,
                    }

                    results['last_tested'] = id

                    if not self._abortRequested:
                        write_file(file="channel_test.json", data=results, isJSON=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

                        if settings.getInt(key='_last_playing') > int(time.time() - 300):
                            if test_run:
                                self.update_prefs()

                            settings.setBool(key='_test_running', value=False)
                            return 5

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

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

            count = 5

        settings.setBool(key='_test_running', value=False)

        if self._debug_mode:
            log.debug('Execution Done: api.test_channels')

        return count