Exemplo n.º 1
0
def move_service(serviceid):
    session = Session()
    if serviceid in session.get_services(filtered=0):
        service = session.get_service(serviceid)
        old_order = service['order']
        new_order = old_order - 1
        for replaced_serviceid in session.get_services(filtered=0):
            replaced_service = session.get_service(replaced_serviceid)
            if replaced_service['order'] == new_order:
                session.set_service_order(replaced_serviceid, old_order)
        session.set_service_order(serviceid, new_order)
    xbmc.executebuiltin('Container.Refresh')
Exemplo n.º 2
0
def list_services(label):
    xbmcplugin.setPluginCategory(_handle, label)
    session = Session()
    first = 1
    for serviceid in session.get_services(filtered=0):
        offers = ''
        menuitems = []
        for offer in session.services[serviceid]['offers']:
            offers = offers + offer + ' '
        offers = '(' + offers + ')'

        if session.services[serviceid]['enabled'] == 1:
            list_item = xbmcgui.ListItem(
                label=session.services[serviceid]['description'] + ' ' +
                offers)
        else:
            list_item = xbmcgui.ListItem(
                label='[COLOR=gray]' +
                session.services[serviceid]['description'] + ' ' + offers +
                '[/COLOR]')

        if session.services[serviceid]['enabled'] == 1:
            if len(session.get_services()) > 1:
                menuitems.append((
                    'Zakázat službu',
                    'RunPlugin(plugin://' + plugin_id +
                    '?action=disable_service&serviceid=' + serviceid + ')',
                ))
        else:
            menuitems.append((
                'Povolit službu',
                'RunPlugin(plugin://' + plugin_id +
                '?action=enable_service&serviceid=' + serviceid + ')',
            ))
        if first == 0:
            menuitems.append((
                'Posunout nahoru',
                'RunPlugin(plugin://' + plugin_id +
                '?action=move_service&serviceid=' + serviceid + ')',
            ))
        if len(menuitems) > 0:
            list_item.addContextMenuItems(menuitems)

        xbmcplugin.addDirectoryItem(_handle, None, list_item, False)
        first = 0
    xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
Exemplo n.º 3
0
def get_recordings_epgIds():
    epgIds = []
    session = Session()
    for serviceid in session.get_services():
        data = call_o2_api(url='https://api.o2tv.cz/unity/api/v1/recordings/',
                           data=None,
                           header=get_header_unity(
                               session.services[serviceid]))
        if 'err' in data:
            xbmcgui.Dialog().notification(
                'Sledování O2TV',
                'Problém s načtením nahrávek, zkuste to znovu',
                xbmcgui.NOTIFICATION_ERROR, 5000)
        if 'result' in data and len(data['result']) > 0:
            for program in data['result']:
                epgIds.append(str(program['program']['epgId']))
    return epgIds
Exemplo n.º 4
0
def get_o2_channels_lists(label):
    xbmcplugin.setPluginCategory(_handle, label)
    session = Session()
    for serviceid in session.get_services():
        data = call_o2_api(
            url=
            'https://app.o2tv.cz/sws/subscription/settings/get-user-pref.json?name=nangu.channelListUserChannelNumbers',
            data=None,
            header=get_header(session.services[serviceid]))
        if 'err' in data:
            xbmcgui.Dialog().notification('Sledování O2TV',
                                          'Problém s načtením seznamu kanálů',
                                          xbmcgui.NOTIFICATION_ERROR, 5000)
            sys.exit()
        if 'listUserChannelNumbers' in data and len(
                data['listUserChannelNumbers']) > 0:
            for list in data['listUserChannelNumbers']:
                list_item = xbmcgui.ListItem(label=list.replace('user::', ''))
                url = get_url(action='load_o2_channels_list',
                              serviceid=serviceid,
                              list=encode(list))
                xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
            xbmcplugin.endOfDirectory(_handle)
Exemplo n.º 5
0
def disable_service(serviceid):
    session = Session()
    if serviceid in session.get_services():
        session.disable_service(serviceid)
    xbmc.executebuiltin('Container.Refresh')
Exemplo n.º 6
0
def enable_service(serviceid):
    session = Session()
    if serviceid in session.get_services(filtered=0):
        session.enable_service(serviceid)
    xbmc.executebuiltin('Container.Refresh')
Exemplo n.º 7
0
def list_devices(label):
    xbmcplugin.setPluginCategory(_handle, label)
    session = Session()
    for serviceid in session.get_services():
        data = call_o2_api(url='https://api.o2tv.cz/unity/api/v1/devices/',
                           data=None,
                           header=get_header_unity(
                               session.services[serviceid]))
        if 'err' in data:
            xbmcgui.Dialog().notification(
                'Sledování O2TV',
                'Problém při zjištování spárovaných zařízení',
                xbmcgui.NOTIFICATION_ERROR, 4000)
            sys.exit()
        if 'pairedDeviceAddLimit' in data and 'sessionLimit' in data and 'result' in data:
            list_item = xbmcgui.ListItem(
                label='Limit souběžných přehrávání: ' +
                str(int(data['sessionLimit'])))
            xbmcplugin.addDirectoryItem(_handle, None, list_item, False)
        else:
            xbmcgui.Dialog().notification(
                'Sledování O2TV',
                'Problém při zjištování spárovaných zařízení',
                xbmcgui.NOTIFICATION_ERROR, 4000)
            sys.exit()

        data = call_o2_api(
            url=
            'https://app.o2tv.cz/sws/subscription/settings/subscription-configuration.json',
            data=None,
            header=get_header(session.services[serviceid]))
        if 'err' in data:
            xbmcgui.Dialog().notification(
                'Sledování O2TV',
                'Problém při zjištování spárovaných zařízení',
                xbmcgui.NOTIFICATION_ERROR, 4000)
            sys.exit()
        if 'pairedDevicesLimit' in data and 'pairedDevices' in data:
            list_item = xbmcgui.ListItem(label='Spárovaných zařízení: ' +
                                         str(len(data['pairedDevices'])) +
                                         '/' +
                                         str(int(data['pairedDevicesLimit'])))
            xbmcplugin.addDirectoryItem(_handle, None, list_item, False)
            if len(data['pairedDevices']) > 0:
                devices = sorted(data['pairedDevices'],
                                 key=lambda k: k['lastLoginTimestamp'])
                for device in devices:
                    list_item = xbmcgui.ListItem(
                        label=device['deviceName'] + ' (' +
                        str(device['deviceId']) + ') - ' +
                        datetime.fromtimestamp(device['lastLoginTimestamp'] /
                                               1000).strftime('%d.%m.%Y') +
                        ' z ' + device['lastLoginIpAddress'])
                    list_item.addContextMenuItems([(
                        'Smazat zařízení',
                        'RunPlugin(plugin://' + plugin_id +
                        '?action=unpair_device&deviceId=' +
                        quote(encode(str(device['deviceId']))) +
                        '&deviceName=' + quote(encode(device['deviceName'])) +
                        '&serviceid=' + serviceid + ')',
                    )])
                    xbmcplugin.addDirectoryItem(_handle, None, list_item,
                                                False)
        else:
            xbmcgui.Dialog().notification(
                'Sledování O2TV',
                'Problém při zjištování spárovaných zařízení',
                xbmcgui.NOTIFICATION_ERROR, 4000)
            sys.exit()
    xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
def list_future_recordings(label):
    xbmcplugin.setPluginCategory(_handle, label)
    channels = Channels()
    channels_list = channels.get_channels_list()
    session = Session()
    recordings = {}

    for serviceid in session.get_services():
        data = call_o2_api(url='https://api.o2tv.cz/unity/api/v1/recordings/',
                           data=None,
                           header=get_header_unity(
                               session.services[serviceid]))
        if 'err' in data:
            xbmcgui.Dialog().notification('Sledování O2TV',
                                          'Problém s načtením nahrávek',
                                          xbmcgui.NOTIFICATION_ERROR, 5000)
        if 'result' in data and len(data['result']) > 0:
            for program in data['result']:
                if program['state'] != 'DONE' and program['program'][
                        'channelKey'] in channels_list:
                    recordings.update({
                        program['program']['start'] + random.randint(0, 100): {
                            'pvrProgramId':
                            program['pvrProgramId'],
                            'name':
                            program['program']['name'],
                            'channelKey':
                            program['program']['channelKey'],
                            'start':
                            decode(utils.day_translation_short[
                                datetime.fromtimestamp(
                                    program['program']['start'] /
                                    1000).strftime('%w')]) + ' ' +
                            datetime.fromtimestamp(
                                program['program']['start'] /
                                1000).strftime('%d.%m %H:%M'),
                            'end':
                            datetime.fromtimestamp(program['program']['end'] /
                                                   1000).strftime('%H:%M'),
                            'epgId':
                            program['program']['epgId']
                        }
                    })

        if len(recordings) > 0:
            for recording in sorted(recordings.keys(), reverse=True):
                list_item = xbmcgui.ListItem(
                    label=recordings[recording]['name'] + ' (' +
                    recordings[recording]['channelKey'] + ' | ' +
                    recordings[recording]['start'] + ' - ' +
                    recordings[recording]['end'] + ')')
                list_item.setInfo(
                    'video', {
                        'mediatype':
                        'movie',
                        'title':
                        recordings[recording]['name'] + ' (' +
                        recordings[recording]['channelKey'] + ')'
                    })
                list_item.setProperty('IsPlayable', 'true')
                list_item = get_listitem_epg_details(
                    list_item, recordings[recording]['epgId'],
                    channels_list[recordings[recording]['channelKey']]['logo'])
                list_item.addContextMenuItems([(
                    'Smazat nahrávku',
                    'RunPlugin(plugin://' + plugin_id +
                    '?action=delete_recording&channelKey=' +
                    recordings[recording]['channelKey'] + '&pvrProgramId=' +
                    str(recordings[recording]['pvrProgramId']) + ')',
                )])
                url = get_url(action='list_future_recordings')
                xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
            xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
        else:
            xbmcgui.Dialog().notification('Sledování O2TV',
                                          'Nenalezena žádná nahrávka',
                                          xbmcgui.NOTIFICATION_INFO, 5000)
            sys.exit()
def list_recordings(label):
    xbmcplugin.setPluginCategory(_handle, label)
    addon = xbmcaddon.Addon()

    channels = Channels()
    channels_list = channels.get_channels_list(visible_filter=False)
    session = Session()
    recordings = {}

    list_item = xbmcgui.ListItem(label='Plánování nahrávek')
    url = get_url(action='list_planning_recordings',
                  label=label + ' / ' + 'Plánování')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    list_item = xbmcgui.ListItem(label='Naplánované nahrávky')
    url = get_url(action='list_future_recordings',
                  label=label + ' / ' + 'Naplánované nahrávky')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    for serviceid in session.get_services():
        data = call_o2_api(url='https://api.o2tv.cz/unity/api/v1/recordings/',
                           data=None,
                           header=get_header_unity(
                               session.services[serviceid]))
        if 'err' in data:
            xbmcgui.Dialog().notification(
                'Sledování O2TV',
                'Problém s načtením nahrávek, zkuste to znovu',
                xbmcgui.NOTIFICATION_ERROR, 6000)
        if 'result' in data and len(data['result']) > 0:
            for program in data['result']:
                if program['state'] == 'DONE':
                    recordings.update({
                        program['program']['start'] + random.randint(0, 100): {
                            'pvrProgramId':
                            program['pvrProgramId'],
                            'name':
                            program['program']['name'],
                            'channelKey':
                            program['program']['channelKey'],
                            'start':
                            decode(utils.day_translation_short[
                                datetime.fromtimestamp(
                                    program['program']['start'] /
                                    1000).strftime('%w')]) + ' ' +
                            datetime.fromtimestamp(
                                program['program']['start'] /
                                1000).strftime('%d.%m %H:%M'),
                            'end':
                            datetime.fromtimestamp(program['program']['end'] /
                                                   1000).strftime('%H:%M'),
                            'epgId':
                            program['program']['epgId']
                        }
                    })

    for recording in sorted(recordings.keys(), reverse=True):
        if recordings[recording]['channelKey'] in channels_list:
            list_item = xbmcgui.ListItem(
                label=recordings[recording]['name'] + ' (' +
                recordings[recording]['channelKey'] + ' | ' +
                recordings[recording]['start'] + ' - ' +
                recordings[recording]['end'] + ')')
            list_item.setProperty('IsPlayable', 'true')
            list_item.setInfo(
                'video', {
                    'mediatype':
                    'movie',
                    'title':
                    recordings[recording]['name'] + ' (' +
                    recordings[recording]['channelKey'] + ')'
                })
            list_item = get_listitem_epg_details(
                list_item, recordings[recording]['epgId'],
                channels_list[recordings[recording]['channelKey']]['logo'])
            list_item.setContentLookup(False)
            menus = [('Smazat nahrávku', 'RunPlugin(plugin://' + plugin_id +
                      '?action=delete_recording&channelKey=' +
                      recordings[recording]['channelKey'] + '&pvrProgramId=' +
                      str(recordings[recording]['pvrProgramId']) + ')')]
            if addon.getSetting('download_streams') == 'true':
                menus.append(
                    ('Stáhnout', 'RunPlugin(plugin://' + plugin_id +
                     '?action=add_to_queue&epgId=' +
                     str(recordings[recording]['epgId']) + '&pvrProgramId=' +
                     str(recordings[recording]['pvrProgramId']) + ')'))
            list_item.addContextMenuItems(menus)
            url = get_url(action='play_recording',
                          channelKey=encode(
                              recordings[recording]['channelKey']),
                          pvrProgramId=recordings[recording]['pvrProgramId'],
                          title=encode(recordings[recording]['name']))
            xbmcplugin.addDirectoryItem(_handle, url, list_item, False)
    xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
Exemplo n.º 10
0
    def get_o2_channels(self):
        addon = xbmcaddon.Addon()
        channels = {}
        data = call_o2_api(url='https://api.o2tv.cz/unity/api/v1/channels/',
                           data=None,
                           header=get_header_unity())
        if 'err' in data:
            xbmcgui.Dialog().notification('O2TV',
                                          'Problém při načtení kanálů z O2',
                                          xbmcgui.NOTIFICATION_ERROR, 5000)
            sys.exit()
        if 'result' in data and len(data['result']) > 0:
            for channel in data['result']:
                channels.update({
                    channel['channel']['channelKey']: {
                        'name':
                        channel['channel']['name'],
                        'number':
                        int(channel['channel']['weight']),
                        'logo':
                        'https://assets.o2tv.cz' +
                        channel['channel']['images']['color']['url'],
                        'key':
                        channel['channel']['keyForCache'],
                        'available':
                        False,
                        'serviceid':
                        ''
                    }
                })

        session = Session()
        for serviceid in session.get_services():
            for offer in session.services[serviceid]['offers']:
                post = {
                    'locality': session.services[serviceid]['locality'],
                    'tariff': session.services[serviceid]['tariff'],
                    'isp': session.services[serviceid]['isp'],
                    'language': 'ces',
                    'deviceType': addon.getSetting('devicetype'),
                    'liveTvStreamingProtocol': 'HLS',
                    'offer': offer
                }
                data = call_o2_api(
                    url='https://app.o2tv.cz/sws/server/tv/channels.json',
                    data=post,
                    header=get_header(session.services[serviceid]))
                if 'err' in data:
                    xbmcgui.Dialog().notification('Sledování O2TV',
                                                  'Problém s načtením kanálů',
                                                  xbmcgui.NOTIFICATION_ERROR,
                                                  5000)
                    sys.exit()
                if 'channels' in data and len(data['channels']) > 0:
                    for channel in data['channels']:
                        if data['channels'][channel][
                                'channelType'] == 'TV' and data['channels'][
                                    channel]['channelKey'] not in channels:
                            channels.update({
                                data['channels'][channel]['channelKey']: {
                                    'name':
                                    data['channels'][channel]['channelName'],
                                    'number':
                                    int(data['channels'][channel]
                                        ['channelNumber']),
                                    'key':
                                    '',
                                    'logo':
                                    ''
                                }
                            })
                        if data['channels'][channel]['channelKey'] in channels:
                            channels[data['channels'][channel]
                                     ['channelKey']].update(
                                         {'available': True})
                            if 'serviceid' not in channels[data['channels'][
                                    channel]['channelKey']] or len(
                                        channels[data['channels'][channel][
                                            'channelKey']]['serviceid']) == 0:
                                channels[data['channels'][channel]
                                         ['channelKey']].update(
                                             {'serviceid': serviceid})
        return channels
def get_event(epgId, pvrProgramId, title):
    addon = xbmcaddon.Addon()
    err = 0
    url = ''
    post = {}
    channelKey = ''
    stream_type = 'HLS'
    current_ts = int(time.mktime(datetime.now().timetuple()))
    event = get_epg_details([epgId], update_from_api=1)
    channels = Channels()
    channels_list = channels.get_channels_list('name', visible_filter=False)

    if event != None and (current_ts < event['availableTo']
                          or pvrProgramId is not None):
        if event['startTime'] < current_ts:
            if event['endTime'] < current_ts:
                if pvrProgramId == None:
                    channelKey = channels_list[event['channel']]['channelKey']
                    session = Session()
                    channels_list = channels.get_channels_list(
                        visible_filter=False)
                    header = get_header(
                        session.get_service(
                            channels_list[channelKey]['serviceid']))
                    subscription = session.get_service(
                        channels_list[channelKey]['serviceid'])['subscription']
                    post = {
                        'serviceType':
                        'TIMESHIFT_TV',
                        'deviceType':
                        addon.getSetting('devicetype'),
                        'streamingProtocol':
                        stream_type,
                        'subscriptionCode':
                        subscription,
                        'channelKey':
                        encode(channelKey),
                        'fromTimestamp':
                        str(event['startTime'] * 1000),
                        'toTimestamp':
                        str(event['endTime'] * 1000 +
                            (int(addon.getSetting('offset')) * 60 * 1000)),
                        'id':
                        epgId,
                        'encryptionType':
                        'NONE'
                    }
                else:
                    session = Session()
                    for serviceid in session.get_services():
                        data = call_o2_api(
                            url='https://api.o2tv.cz/unity/api/v1/recordings/',
                            data=None,
                            header=get_header_unity(
                                session.services[serviceid]))
                        if 'err' in data:
                            xbmcgui.Dialog().notification(
                                'Sledování O2TV',
                                'Problém s načtením nahrávek, zkuste to znovu',
                                xbmcgui.NOTIFICATION_ERROR, 6000)
                        if 'result' in data and len(data['result']) > 0:
                            for program in data['result']:
                                if program['pvrProgramId'] == pvrProgramId:
                                    channelKey = program['program'][
                                        'channelKey']
                    if len(channelKey) > 0:
                        channels_list = channels.get_channels_list(
                            visible_filter=False)
                        header = get_header(
                            session.get_service(
                                channels_list[channelKey]['serviceid']))
                        subscription = session.get_service(
                            channels_list[channelKey]
                            ['serviceid'])['subscription']
                        post = {
                            'serviceType': 'NPVR',
                            'deviceType': addon.getSetting('devicetype'),
                            'streamingProtocol': stream_type,
                            'subscriptionCode': subscription,
                            'contentId': pvrProgramId,
                            'encryptionType': 'NONE'
                        }
            else:
                xbmc.log('live')
                err = 1
        else:
            xbmc.log('future')
            err = 1
    else:
        xbmc.log('neni')
        err = 1

    if err == 1:
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Problém s stažením ' + encode(title),
                                      xbmcgui.NOTIFICATION_ERROR, 5000)
        current_ts = int(time.mktime(datetime.now().timetuple()))
        db.execute(
            'UPDATE queue SET status = -1, downloadts = ? WHERE epgId = ?',
            [str(current_ts), str(epgId)])
        db.commit()
        return {}, ''
    else:
        if addon.getSetting('only_sd') == 'true':
            post.update({'resolution': 'SD'})
        data = call_o2_api(
            url='https://app.o2tv.cz/sws/server/streaming/uris.json',
            data=post,
            header=header)
        if 'err' in data:
            xbmcgui.Dialog().notification('Sledování O2TV',
                                          'Problém s stažením streamu',
                                          xbmcgui.NOTIFICATION_ERROR, 5000)
        url = ''
        if 'uris' in data and len(
                data['uris']) > 0 and 'uri' in data['uris'][0] and len(
                    data['uris'][0]['uri']) > 0:
            for uris in data['uris']:
                if addon.getSetting(
                        'only_sd') != 'true' and uris['resolution'] == 'HD':
                    url = uris['uri']
                if addon.getSetting(
                        'only_sd') == 'true' and uris['resolution'] == 'SD':
                    url = uris['uri']
            if url == '':
                url = data['uris'][0]['uri']
        else:
            xbmcgui.Dialog().notification('Sledování O2TV',
                                          'Problém s stažením streamu',
                                          xbmcgui.NOTIFICATION_ERROR, 5000)
        return event, url