Esempio n. 1
0
    def get_channels_for_user(self):
        if self._debug_mode:
            log.debug('Executing: api.get_channels_for_user')

        channels_url = '{api_url}/TRAY/LIVECHANNELS?orderBy=orderId&sortOrder=asc&from=0&to=999&dfilter_channels=subscription'.format(
            api_url=self._api_url)
        data = self.download(url=channels_url,
                             type='get',
                             code=[200],
                             data=None,
                             json_data=False,
                             data_return=True,
                             return_json=True,
                             retry=True,
                             check_data=True)

        if not data or not check_key(data['resultObj'], 'containers'):
            if self._debug_mode:
                log.debug('Failure to retrieve expected data')
                log.debug('Execution Done: api.get_channels_for_user')

            return False

        write_file(file="channels.json",
                   data=data['resultObj']['containers'],
                   isJSON=True)

        self.create_playlist()

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

        return True
Esempio n. 2
0
    def vod_subscription(self):
        if not self.get_session():
            return None

        profile_settings = load_profile(profile_id=1)
        subscription = []

        series_url = '{api_url}/TRAY/SEARCH/VOD?from=1&to=9999&filter_contentType=GROUP_OF_BUNDLES,VOD&filter_contentSubtype=SERIES,VOD&filter_contentTypeExtended=VOD&filter_excludedGenres=erotiek&filter_technicalPackages=10078,10081,10258,10255&dfilter_packages=matchSubscription&orderBy=activationDate&sortOrder=desc'.format(
            api_url=profile_settings['api_url'])
        download = self.download(url=series_url,
                                 type='get',
                                 headers=None,
                                 data=None,
                                 json_data=False,
                                 return_json=True)
        data = download['data']
        resp = download['resp']

        if not resp or not resp.status_code == 200 or not data or not check_key(
                data, 'resultCode'
        ) or not data['resultCode'] == 'OK' or not check_key(
                data, 'resultObj') or not check_key(data['resultObj'],
                                                    'containers'):
            return False

        for row in data['resultObj']['containers']:
            subscription.append(row['metadata']['contentId'])

        write_file(file='vod_subscription.json',
                   data=subscription,
                   isJSON=True)

        return True
Esempio n. 3
0
    def get_channels_for_user(self):
        self._session.headers = CONST_BASE_HEADERS
        self._session.headers.update({'Authorization': 'Bearer ' + self._session_token})

        if self._debug_mode:
            log.debug('Executing: api.get_channels_for_user')
            log.debug('Request Session Headers')
            log.debug(self._session.headers)

        channels_url = "{api_url}/assets?query=channels,3&limit=999&from=0".format(api_url=CONST_DEFAULT_API);

        data = self.download(url=channels_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 not data or not check_key(data, 'assets'):
            if self._debug_mode:
                log.debug('Failure to retrieve expected data')
                log.debug('Execution Done: api.get_channels_for_user')

            return False

        write_file(file="channels.json", data=data['assets'], isJSON=True)

        self.create_playlist()

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

        return True
Esempio n. 4
0
    def vod_seasons(self, id):
        if self._debug_mode:
            log.debug('Executing: api.vod_seasons')
            log.debug('Vars: id={id}'.format(id=id))

        seasons = []

        program_url = '{api_url}/CONTENT/DETAIL/GROUP_OF_BUNDLES/{id}'.format(
            api_url=self._api_url, id=id)

        file = "cache" + os.sep + "vod_seasons_" + unicode(id) + ".json"

        if self._enable_cache and not is_file_older_than_x_minutes(
                file=ADDON_PROFILE + file, minutes=10):
            data = load_file(file=file, isJSON=True)
        else:
            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=True)

            if data and check_key(data['resultObj'],
                                  'containers') and self._enable_cache:
                write_file(file=file, data=data, isJSON=True)

        if not data or not check_key(data['resultObj'], 'containers'):
            if self._debug_mode:
                log.debug('Failure to retrieve expected data')
                log.debug('Execution Done: api.vod_seasons')

            return None

        for row in data['resultObj']['containers']:
            for currow in row['containers']:
                if check_key(currow, 'metadata') and check_key(
                        currow['metadata'], 'season'
                ) and currow['metadata']['contentSubtype'] == 'SEASON':
                    seasons.append({
                        'id':
                        currow['metadata']['contentId'],
                        'seriesNumber':
                        currow['metadata']['season'],
                        'desc':
                        currow['metadata']['shortDescription'],
                        'image':
                        currow['metadata']['pictureUrl']
                    })

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

        return seasons
Esempio n. 5
0
    def vod_seasons(self, id):
        profile_settings = load_profile(profile_id=1)
        seasons = []

        program_url = '{api_url}/CONTENT/DETAIL/GROUP_OF_BUNDLES/{id}'.format(
            api_url=profile_settings['api_url'], id=id)

        file = "cache" + os.sep + "vod_seasons_" + unicode(id) + ".json"

        if settings.getBool(
                key='enable_cache') and not is_file_older_than_x_minutes(
                    file=ADDON_PROFILE + file, minutes=10):
            data = load_file(file=file, isJSON=True)
        else:
            if not self.get_session():
                return None

            download = self.download(url=program_url,
                                     type='get',
                                     headers=None,
                                     data=None,
                                     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,
                    'resultCode') and data['resultCode'] == 'OK' and check_key(
                        data, 'resultObj') and check_key(
                            data['resultObj'],
                            'containers') and settings.getBool(
                                key='enable_cache'):
                write_file(file=file, data=data, isJSON=True)

        if not data or not check_key(data['resultObj'], 'containers'):
            return None

        for row in data['resultObj']['containers']:
            for currow in row['containers']:
                if check_key(currow, 'metadata') and check_key(
                        currow['metadata'], 'season'
                ) and currow['metadata']['contentSubtype'] == 'SEASON':
                    seasons.append({
                        'id':
                        currow['metadata']['contentId'],
                        'seriesNumber':
                        currow['metadata']['season'],
                        'desc':
                        currow['metadata']['shortDescription'],
                        'image':
                        currow['metadata']['pictureUrl']
                    })

        return seasons
Esempio n. 6
0
    def update_prefs(self):
        if self._debug_mode:
            log.debug('Executing: api.update_prefs')

        prefs = load_file(file="channel_prefs.json", isJSON=True)
        results = load_file(file="channel_test.json", isJSON=True)
        channels = load_file(file="channels.json", isJSON=True)

        if not results:
            results = {}

        if not prefs:
            prefs = {}

        if not channels:
            channels = {}

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

            if len(unicode(id)) == 0:
                continue

            keys = ['live', 'replay', 'epg']

            for key in keys:
                if not check_key(prefs, id) or not check_key(prefs[id], key):
                    if not check_key(results, id):
                        if not check_key(prefs, id):
                            prefs[id] = {
                                key: 'true',
                                key + '_choice': 'auto'
                            }
                        else:
                            prefs[id][key] = 'true'
                            prefs[id][key + '_choice'] = 'auto'
                    else:
                        result_value = results[id][key]

                        if not check_key(prefs, id):
                            prefs[id] = {
                                key: result_value,
                                key + '_choice': 'auto'
                            }
                        else:
                            prefs[id][key] = result_value
                            prefs[id][key + '_choice'] = 'auto'
                elif prefs[id][key + '_choice'] == 'auto' and check_key(results, id):
                    prefs[id][key] = results[id][key]

        write_file(file="channel_prefs.json", data=prefs, isJSON=True)

        if self._debug_mode:
            log.debug('Execution Done: api.update_prefs')
Esempio n. 7
0
    def vod_subscription(self):
        subscription = []

        series_url = '{api_url}/TRAY/SEARCH/VOD?from=1&to=9999&filter_contentType=GROUP_OF_BUNDLES,VOD&filter_contentSubtype=SERIES,VOD&filter_contentTypeExtended=VOD&filter_excludedGenres=erotiek&filter_technicalPackages=10078,10081,10258,10255&dfilter_packages=matchSubscription&orderBy=activationDate&sortOrder=desc'.format(api_url=settings.get(key='_api_url'))
        data = self.download(url=series_url, type='get', code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=True)

        if not data or not check_key(data['resultObj'], 'containers'):
            return None

        for row in data['resultObj']['containers']:
            subscription.append(row['metadata']['contentId'])

        write_file(file='vod_subscription.json', data=subscription, isJSON=True)
Esempio n. 8
0
    def create_playlist(self):
        if self._debug_mode:
            log.debug('Executing: api.create_playlist')

        prefs = load_file(file="channel_prefs.json", isJSON=True)
        channels = load_file(file="channels.json", isJSON=True)

        playlist_all = u'#EXTM3U\n'
        playlist = u'#EXTM3U\n'

        for row in channels:
            channeldata = self.get_channel_data(row=row)
            id = unicode(channeldata['channel_id'])

            if len(id) > 0:
                path = 'plugin://{addonid}/?_=play_video&channel={channel}&id={asset}&type=channel&_l=.pvr'.format(
                    addonid=ADDON_ID,
                    channel=channeldata['channel_id'],
                    asset=channeldata['asset_id'])
                playlist_all += u'#EXTINF:-1 tvg-id="{id}" tvg-chno="{channel}" tvg-name="{name}" tvg-logo="{logo}" group-title="TV" radio="false",{name}\n{path}\n'.format(
                    id=channeldata['channel_id'],
                    channel=channeldata['channel_number'],
                    name=channeldata['label'],
                    logo=channeldata['station_image_large'],
                    path=path)

                if not prefs or not check_key(
                        prefs, id) or prefs[id]['epg'] == 'true':
                    playlist += u'#EXTINF:-1 tvg-id="{id}" tvg-chno="{channel}" tvg-name="{name}" tvg-logo="{logo}" group-title="TV" radio="false",{name}\n{path}\n'.format(
                        id=channeldata['channel_id'],
                        channel=channeldata['channel_number'],
                        name=channeldata['label'],
                        logo=channeldata['station_image_large'],
                        path=path)

        self._channels_age = time.time()
        settings.setInt(key='_channels_age', value=self._channels_age)

        if self._debug_mode:
            log.debug('Setting _channels_age to: {channels_age}'.format(
                channels_age=self._channels_age))
            log.debug('Writing tv.m3u8: {playlist}'.format(playlist=playlist))

        write_file(file="tv.m3u8", data=playlist, isJSON=False)
        write_file(file="tv_all.m3u8", data=playlist_all, isJSON=False)
        combine_playlist()

        if self._debug_mode:
            log.debug('Execution Done: api.create_playlist')
Esempio n. 9
0
    def get_channels_for_user(self, location):
        channels_url = '{channelsurl}?byLocationId={location}&includeInvisible=true&personalised=true'.format(
            channelsurl=settings.get('_channels_url'), location=location)
        data = self.download(url=channels_url,
                             type="get",
                             code=[200],
                             data=None,
                             json_data=False,
                             data_return=True,
                             return_json=True,
                             retry=True,
                             check_data=False)

        if data and check_key(data, 'entryCount') and check_key(
                data, 'channels'):
            settings.setInt(key='_channels_age', value=time.time())

            write_file(file="channels.json",
                       data=data['channels'],
                       isJSON=True)

            playlist = u'#EXTM3U\n'

            for row in sorted(
                    data['channels'],
                    key=lambda r: float(r.get('channelNumber', 'inf'))):
                channeldata = self.get_channel_data(row=row)
                urldata = get_play_url(content=channeldata['stream'])

                if urldata and check_key(urldata, 'play_url') and check_key(
                        urldata, 'locator'):
                    path = 'plugin://{addonid}/?_=play_video&type=channel&id={play_url}&locator={locator}&_l=.pvr'.format(
                        addonid=ADDON_ID,
                        play_url=quote(urldata['play_url']),
                        locator=quote(urldata['locator']))

                    playlist += u'#EXTINF:-1 tvg-id="{id}" tvg-chno="{channel}" tvg-name="{name}" tvg-logo="{logo}" group-title="TV" radio="false",{name}\n{path}\n'.format(
                        id=channeldata['channel_id'],
                        channel=channeldata['channel_number'],
                        name=channeldata['label'],
                        logo=channeldata['station_image_large'],
                        path=path)

            write_file(file="tv.m3u8", data=playlist, isJSON=False)
            combine_playlist()
Esempio n. 10
0
    def get_channels_for_user(self):
        channels_url = '{api_url}/TRAY/LIVECHANNELS?orderBy=orderId&sortOrder=asc&from=0&to=999&dfilter_channels=subscription'.format(api_url=settings.get(key='_api_url'))
        data = self.download(url=channels_url, type='get', code=[200], data=None, json_data=False, data_return=True, return_json=True, retry=True, check_data=True)

        if data and check_key(data['resultObj'], 'containers'):
            settings.setInt(key='_channels_age', value=time.time())

            write_file(file="channels.json", data=data['resultObj']['containers'], isJSON=True)

            playlist = u'#EXTM3U\n'

            for row in data['resultObj']['containers']:
                channeldata = self.get_channel_data(row=row)
                path = 'plugin://{addonid}/?_=play_video&channel={channel}&id={asset}&type=channel&_l=.pvr'.format(addonid=ADDON_ID, channel=channeldata['channel_id'], asset=channeldata['asset_id'])
                playlist += u'#EXTINF:-1 tvg-id="{id}" tvg-chno="{channel}" tvg-name="{name}" tvg-logo="{logo}" group-title="TV" radio="false",{name}\n{path}\n'.format(id=channeldata['channel_id'], channel=channeldata['channel_number'], name=channeldata['label'], logo=channeldata['station_image_large'], path=path)

            write_file(file="tv.m3u8", data=playlist, isJSON=False)
            combine_playlist()
Esempio n. 11
0
    def get_channels_for_user(self, channels):
        settings.setInt(key='_channels_age', value=time.time())

        write_file(file="channels.json", data=channels, isJSON=True)

        data = u'#EXTM3U\n'

        for row in channels:
            channeldata = self.get_channel_data(rows=channels, row=row)
            path = 'plugin://{addonid}/?_=play_video&channel={channel}&type=channel&_l=.pvr'.format(
                addonid=ADDON_ID, channel=channeldata['channel_id'])
            data += u'#EXTINF:-1 tvg-id="{id}" tvg-chno="{channel}" tvg-name="{name}" tvg-logo="{logo}" group-title="TV" radio="false",{name}\n{path}\n'.format(
                id=channeldata['channel_id'],
                channel=channeldata['channel_number'],
                name=channeldata['label'],
                logo=channeldata['station_image_large'],
                path=path)

        write_file(file="tv.m3u8", data=data, isJSON=False)
        combine_playlist()
Esempio n. 12
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
Esempio n. 13
0
    def vod_season(self, id):
        if self._debug_mode:
            log.debug('Executing: api.vod_season')
            log.debug('Vars: id={id}'.format(id=id))

        season = []
        episodes = []

        program_url = '{api_url}/CONTENT/DETAIL/BUNDLE/{id}'.format(
            api_url=self._api_url, id=id)

        file = "cache" + os.sep + "vod_season_" + unicode(id) + ".json"

        if self._enable_cache and not is_file_older_than_x_minutes(
                file=ADDON_PROFILE + file, minutes=10):
            data = load_file(file=file, isJSON=True)
        else:
            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=True)

            if data and check_key(data['resultObj'],
                                  'containers') and self._enable_cache:
                write_file(file=file, data=data, isJSON=True)

        if not data or not check_key(data['resultObj'], 'containers'):
            if self._debug_mode:
                log.debug('Failure to retrieve expected data')
                log.debug('Execution Done: api.vod_season')

            return None

        for row in data['resultObj']['containers']:
            for currow in row['containers']:
                if check_key(currow, 'metadata') and check_key(
                        currow['metadata'], 'season') and currow['metadata'][
                            'contentSubtype'] == 'EPISODE' and not currow[
                                'metadata']['episodeNumber'] in episodes:
                    asset_id = ''

                    for asset in currow['assets']:
                        if check_key(
                                asset, 'videoType'
                        ) and asset['videoType'] == 'SD_DASH_PR' and check_key(
                                asset, 'assetType'
                        ) and asset['assetType'] == 'MASTER':
                            asset_id = asset['assetId']
                            break

                    episodes.append(currow['metadata']['episodeNumber'])
                    season.append({
                        'id':
                        currow['metadata']['contentId'],
                        'assetid':
                        asset_id,
                        'duration':
                        currow['metadata']['duration'],
                        'title':
                        currow['metadata']['episodeTitle'],
                        'episodeNumber':
                        '{season}.{episode}'.format(
                            season=currow['metadata']['season'],
                            episode=currow['metadata']['episodeNumber']),
                        'desc':
                        currow['metadata']['shortDescription'],
                        'image':
                        currow['metadata']['pictureUrl']
                    })

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

        return season
Esempio n. 14
0
    def vod_season(self, id):
        profile_settings = load_profile(profile_id=1)
        season = []
        episodes = []

        program_url = '{api_url}/CONTENT/DETAIL/BUNDLE/{id}'.format(
            api_url=profile_settings['api_url'], id=id)

        file = "cache" + os.sep + "vod_season_" + unicode(id) + ".json"

        if settings.getBool(
                key='enable_cache') and not is_file_older_than_x_minutes(
                    file=ADDON_PROFILE + file, minutes=10):
            data = load_file(file=file, isJSON=True)
        else:
            if not self.get_session():
                return None

            download = self.download(url=program_url,
                                     type='get',
                                     headers=None,
                                     data=None,
                                     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,
                    'resultCode') and data['resultCode'] == 'OK' and check_key(
                        data, 'resultObj') and check_key(
                            data['resultObj'],
                            'containers') and settings.getBool(
                                key='enable_cache'):
                write_file(file=file, data=data, isJSON=True)

        if not data or not check_key(data['resultObj'], 'containers'):
            return None

        for row in data['resultObj']['containers']:
            for currow in row['containers']:
                if check_key(currow, 'metadata') and check_key(
                        currow['metadata'], 'season') and currow['metadata'][
                            'contentSubtype'] == 'EPISODE' and not currow[
                                'metadata']['episodeNumber'] in episodes:
                    asset_id = ''

                    for asset in currow['assets']:
                        if check_key(
                                asset, 'videoType'
                        ) and asset['videoType'] == 'SD_DASH_PR' and check_key(
                                asset, 'assetType'
                        ) and asset['assetType'] == 'MASTER':
                            asset_id = asset['assetId']
                            break

                    episodes.append(currow['metadata']['episodeNumber'])
                    season.append({
                        'id':
                        currow['metadata']['contentId'],
                        'assetid':
                        asset_id,
                        'duration':
                        currow['metadata']['duration'],
                        'title':
                        currow['metadata']['episodeTitle'],
                        'episodeNumber':
                        '{season}.{episode}'.format(
                            season=currow['metadata']['season'],
                            episode=currow['metadata']['episodeNumber']),
                        'desc':
                        currow['metadata']['shortDescription'],
                        'image':
                        currow['metadata']['pictureUrl']
                    })

        return season
Esempio n. 15
0
    def vod_season(self, id):
        season = []

        file = "cache" + os.sep + "vod_season_" + unicode(id) + ".json"

        if settings.getBool(
                key='enable_cache') and not is_file_older_than_x_minutes(
                    file=ADDON_PROFILE + file, minutes=10):
            data = load_file(file=file, isJSON=True)
        else:
            profile_settings = load_profile(profile_id=1)

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

            session_post_data = {
                'VODID': unicode(id),
                'offset': '0',
                'count': '35',
            }

            seasons_url = '{base_url}/VSP/V3/QueryEpisodeList?from=throughMSAAccess'.format(
                base_url=CONST_BASE_URL)

            download = self.download(url=seasons_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, 'result') and check_key(
                        data['result'], 'retCode') and data['result'][
                            'retCode'] == '000000000' and check_key(
                                data, 'episodes') and settings.getBool(
                                    key='enable_cache'):
                write_file(file=file, data=data, isJSON=True)

        if not data or not check_key(data, 'episodes'):
            return None

        for row in data['episodes']:
            if check_key(
                    row, 'VOD') and check_key(row['VOD'], 'ID') and check_key(
                        row['VOD'], 'name') and check_key(row, 'sitcomNO'):
                image = ''
                duration = 0

                if not check_key(row['VOD'], 'mediaFiles') or not check_key(
                        row['VOD']['mediaFiles'][0], 'ID'):
                    continue

                if check_key(row['VOD']['mediaFiles'][0], 'elapseTime'):
                    duration = row['VOD']['mediaFiles'][0]['elapseTime']

                if check_key(row['VOD'], 'picture') and check_key(
                        row['VOD']['picture'], 'posters'):
                    image = row['VOD']['picture']['posters'][0]

                season.append({
                    'id': row['VOD']['ID'],
                    'media_id': row['VOD']['mediaFiles'][0]['ID'],
                    'duration': duration,
                    'title': row['VOD']['name'],
                    'episodeNumber': row['sitcomNO'],
                    'desc': '',
                    'image': image
                })

        return season
Esempio n. 16
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