Esempio 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')
Esempio n. 2
0
def unpair_device(deviceId, deviceName, serviceid):
    session = Session()
    if deviceId == 'None':
        deviceId = ''
    response = xbmcgui.Dialog().yesno('Smazání zařízení',
                                      'Opravdu smazat spárované zařízení ' +
                                      deviceName + ' (' + deviceId + ')' + '?',
                                      nolabel='Ne',
                                      yeslabel='Ano')
    if response:
        post = {'deviceId': deviceId}
        data = call_o2_api(
            url=
            'https://app.o2tv.cz/sws/subscription/settings/remove-device.json',
            data=post,
            header=get_header(session.services[serviceid]))
        if data != None and 'err' in data:
            xbmcgui.Dialog().notification(
                'Sledování O2TV', 'Problém při smazání spárovaného zařízení',
                xbmcgui.NOTIFICATION_ERROR, 4000)
            sys.exit()
        xbmcgui.Dialog().notification(
            'Sledování O2TV', 'Může trvat i cca. hodinu, než se změna projeví',
            xbmcgui.NOTIFICATION_INFO, 4000)
        xbmc.executebuiltin('Container.Refresh')
Esempio n. 3
0
def load_o2_channels_list(serviceid, list):
    session = Session()
    channels = Channels()
    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_name in data['listUserChannelNumbers']:
            if list == encode(list_name):
                channels_list = channels.get_channels_list(
                    visible_filter=False)
                for channel in channels_list:
                    if channel in data['listUserChannelNumbers'][decode(list)]:
                        channels.set_visibility(channel, True)
                    else:
                        channels.set_visibility(channel, False)
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Seznam kanálů byl načtený',
                                      xbmcgui.NOTIFICATION_INFO, 5000)
    else:
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Problém s načtením seznamu kanálů',
                                      xbmcgui.NOTIFICATION_ERROR, 5000)
        sys.exit()
Esempio n. 4
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)
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
def add_recording(channelKey, epgId):
    channelKey = decode(channelKey)
    channels = Channels()
    channels_list = channels.get_channels_list()
    session = Session()
    service = session.get_service(channels_list[channelKey]['serviceid'])
    post = {'epgId': int(epgId)}
    data = call_o2_api(
        url='https://app.o2tv.cz/sws/subscription/vod/pvr-add-program.json',
        data=post,
        header=get_header(service))
    if 'err' in data:
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Problém s přidáním nahrávky',
                                      xbmcgui.NOTIFICATION_ERROR, 5000)
        sys.exit()
    xbmcgui.Dialog().notification('Sledování O2TV', 'Nahrávka přidána',
                                  xbmcgui.NOTIFICATION_INFO, 5000)
def delete_recording(channelKey, pvrProgramId):
    channelKey = decode(channelKey)
    channels = Channels()
    channels_list = channels.get_channels_list(visible_filter=False)
    session = Session()
    service = session.get_service(channels_list[channelKey]['serviceid'])
    post = {'pvrProgramId': int(pvrProgramId)}
    data = call_o2_api(
        url='https://app.o2tv.cz/sws/subscription/vod/pvr-remove-program.json',
        data=post,
        header=get_header(service))
    if data != None and 'err' in data:
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Problém s odstraněním nahrávky',
                                      xbmcgui.NOTIFICATION_ERROR, 5000)
        sys.exit()
    else:
        xbmcgui.Dialog().notification('Sledování O2TV', 'Nahrávka odstraněna',
                                      xbmcgui.NOTIFICATION_INFO, 5000)
    xbmc.executebuiltin('Container.Refresh')
Esempio n. 8
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)
Esempio n. 9
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_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)
Esempio n. 11
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
def play_video(type, channelKey, start, end, epgId, title):
    addon = xbmcaddon.Addon()
    session = Session()
    channelKey = decode(channelKey)
    channels = Channels()
    channels_list = channels.get_channels_list(visible_filter=False)
    header_unity = get_header_unity(
        session.get_service(channels_list[channelKey]['serviceid']))
    header = get_header(
        session.get_service(channels_list[channelKey]['serviceid']))

    if 'serviceid' not in channels_list[channelKey] or len(
            channels_list[channelKey]['serviceid']) == 0:
        xbmcgui.Dialog().notification(
            'Sledování O2TV',
            'Pravděpodobně neaktivní kanál. Zkuste reset kanálů.',
            xbmcgui.NOTIFICATION_ERROR, 5000)
        sys.exit()

    subscription = session.get_service(
        channels_list[channelKey]['serviceid'])['subscription']

    if addon.getSetting('select_resolution') == 'true' and addon.getSetting(
            'stream_type') == 'HLS' and addon.getSetting('only_sd') != 'true':
        resolution = xbmcgui.Dialog().select('Rozlišení', ['HD', 'SD'],
                                             preselect=0)
    else:
        resolution = -1

    if addon.getSetting('stream_type') == 'MPEG-DASH':
        stream_type = 'DASH'
    else:
        stream_type = 'HLS'

    force_mpeg_dash = 0
    if addon.getSetting('stream_type') == 'HLS' and xbmc.getCondVisibility(
            'System.HasAddon(inputstream.adaptive)') and (
                type == 'live_iptv' or type == 'live_iptv_epg'
            ) and addon.getSetting('force_mpeg_dash') == 'true':
        stream_type = 'DASH'
        force_mpeg_dash = 1

    if type == 'live' or type == 'live_iptv' or type == 'live_iptv_epg':
        startts = 0
        channels_details = get_epg_live(len(channels_list.keys()))
        if channels_list[channelKey]['name'] in channels_details:
            without_details = 0
        else:
            without_details = 1

        if channelKey in channels_list and without_details == 0:
            data = channels_details[channels_list[channelKey]['name']]
            start = data['start']
            startts = int(time.mktime(start.timetuple()))
            end = data['end']
            epgId = str(data['epgId'])

    if addon.getSetting('stream_type') == 'MPEG-DASH-web':
        if type == 'archiv' or type == 'archiv_iptv':
            data = call_o2_api(
                url='https://api.o2tv.cz/unity/api/v1/programs/' + str(epgId) +
                '/playlist/',
                data=None,
                header=header_unity)
        if type == 'live' or type == 'live_iptv' or type == 'live_iptv_epg':
            data = call_o2_api(
                url=
                'https://api.o2tv.cz/unity/api/v1/channels/playlist/?channelKey='
                + quote(channelKey),
                data=None,
                header=header_unity)
        if type == 'recording':
            data = call_o2_api(
                url='https://api.o2tv.cz/unity/api/v1/recordings/' +
                str(epgId) + '/playlist/',
                data=None,
                header=header_unity)
        if 'err' in data:
            xbmcgui.Dialog().notification('Sledování O2TV',
                                          'Problém s přehráním streamu',
                                          xbmcgui.NOTIFICATION_ERROR, 5000)
            sys.exit()
        if 'playlist' in data and len(
                data['playlist']) > 0 and 'streamUrls' in data['playlist'][
                    0] and 'main' in data['playlist'][0]['streamUrls'] and len(
                        data['playlist'][0]['streamUrls']['main']) > 0:
            if 'timeshift' in data['playlist'][0]['streamUrls']:
                url = data['playlist'][0]['streamUrls']['timeshift']
            else:
                url = data['playlist'][0]['streamUrls']['main']
            request = Request(url=url, data=None, headers=header)
            response = urlopen(request)
            url = response.geturl()
        else:
            xbmcgui.Dialog().notification('Sledování O2TV',
                                          'Problém s přehráním streamu',
                                          xbmcgui.NOTIFICATION_ERROR, 5000)
            sys.exit()
    else:
        if type == 'archiv' or type == 'archiv_iptv':
            start = int(float(start) * 1000)
            end = int(float(end) * 1000)
            post = {
                'serviceType':
                'TIMESHIFT_TV',
                'deviceType':
                addon.getSetting('devicetype'),
                'streamingProtocol':
                stream_type,
                'subscriptionCode':
                subscription,
                'channelKey':
                encode(channelKey),
                'fromTimestamp':
                str(start),
                'toTimestamp':
                str(end + (int(addon.getSetting('offset')) * 60 * 1000)),
                'id':
                epgId,
                'encryptionType':
                'NONE'
            }
        if type == 'live' or type == 'live_iptv' or type == 'live_iptv_epg':
            if (addon.getSetting('stream_type') == 'MPEG-DASH'
                    or force_mpeg_dash == 1
                ) and startts > 0 and addon.getSetting('startover') == 'true':
                startts = int(float(startts) * 1000 - 300000)
                post = {
                    'serviceType': 'STARTOVER_TV',
                    'deviceType': addon.getSetting('devicetype'),
                    'streamingProtocol': stream_type,
                    'subscriptionCode': subscription,
                    'channelKey': encode(channelKey),
                    'fromTimestamp': startts,
                    'encryptionType': 'NONE'
                }
            else:
                post = {
                    'serviceType': 'LIVE_TV',
                    'deviceType': addon.getSetting('devicetype'),
                    'streamingProtocol': stream_type,
                    'subscriptionCode': subscription,
                    'channelKey': encode(channelKey),
                    'encryptionType': 'NONE'
                }
        if type == 'recording':
            post = {
                'serviceType': 'NPVR',
                'deviceType': addon.getSetting('devicetype'),
                'streamingProtocol': stream_type,
                'subscriptionCode': subscription,
                'contentId': epgId,
                'encryptionType': 'NONE'
            }
        if addon.getSetting(
                'stream_type') != 'MPEG-DASH' and force_mpeg_dash == 0 and (
                    addon.getSetting('only_sd') == 'true' or resolution == 1):
            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:
            if data['err'] == 'Not Found':
                post = {
                    'serviceType': 'LIVE_TV',
                    'deviceType': addon.getSetting('devicetype'),
                    'streamingProtocol': stream_type,
                    'subscriptionCode': subscription,
                    'channelKey': encode(channelKey),
                    'encryptionType': 'NONE'
                }
                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 přehráním streamu',
                        xbmcgui.NOTIFICATION_ERROR, 5000)
                    sys.exit()
            else:
                xbmcgui.Dialog().notification('Sledování O2TV',
                                              'Problém s přehráním streamu',
                                              xbmcgui.NOTIFICATION_ERROR, 5000)
                sys.exit()
        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']:
                print(uris)
                if addon.getSetting(
                        'only_sd'
                ) != 'true' and resolution != 1 and uris['resolution'] == 'HD':
                    url = uris['uri']
                if (addon.getSetting('only_sd') == 'true'
                        or resolution == 1) and uris['resolution'] == 'SD':
                    url = uris['uri']
            if url == '':
                url = data['uris'][0]['uri']
            if addon.getSetting(
                    'stream_type') == 'MPEG-DASH' or force_mpeg_dash == 1:
                request = Request(url=url, data=None, headers=header)
                response = urlopen(request)
                url = response.geturl().replace('http:', 'https:').replace(
                    ':80/', ':443/')
        else:
            xbmcgui.Dialog().notification('Sledování O2TV',
                                          'Problém s přehráním streamu',
                                          xbmcgui.NOTIFICATION_ERROR, 5000)
            sys.exit()

    if type == 'live_iptv' or type == 'live_iptv_epg':
        list_item = xbmcgui.ListItem(path=url)
        list_item = get_listitem_epg_details(list_item,
                                             str(epgId),
                                             '',
                                             update_from_api=1)
    elif type == 'archiv_iptv':
        list_item = xbmcgui.ListItem(title)
        list_item = get_listitem_epg_details(list_item,
                                             str(epgId),
                                             '',
                                             update_from_api=1)
    else:
        list_item = xbmcgui.ListItem(path=url)

    if addon.getSetting('stream_type') == 'MPEG-DASH' or addon.getSetting(
            'stream_type') == 'MPEG-DASH-web' or force_mpeg_dash == 1:
        list_item.setProperty('inputstreamaddon', 'inputstream.adaptive')
        list_item.setProperty('inputstream', 'inputstream.adaptive')
        list_item.setProperty('inputstream.adaptive.manifest_type', 'mpd')
        list_item.setMimeType('application/dash+xml')
    if type == 'archiv_iptv' or (type == 'live_iptv' and
                                 (addon.getSetting('stream_type') != 'HLS'
                                  or force_mpeg_dash == 1)
                                 and addon.getSetting('startover')
                                 == 'true') or type == 'live_iptv_epg':
        playlist = xbmc.PlayList(1)
        playlist.clear()
        if epgId is not None:
            event = get_epg_details([str(epgId)], update_from_api=1)
            list_item.setInfo('video', {'title': event['title']})
        else:
            list_item.setInfo('video',
                              {'title': channels_list[channelKey]['name']})
        xbmc.PlayList(1).add(url, list_item)
        xbmc.Player().play(playlist)
    else:
        list_item.setContentLookup(False)
        xbmcplugin.setResolvedUrl(_handle, True, list_item)
Esempio n. 14
0
def enable_service(serviceid):
    session = Session()
    if serviceid in session.get_services(filtered=0):
        session.enable_service(serviceid)
    xbmc.executebuiltin('Container.Refresh')
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()
Esempio n. 16
0
def disable_service(serviceid):
    session = Session()
    if serviceid in session.get_services():
        session.disable_service(serviceid)
    xbmc.executebuiltin('Container.Refresh')
Esempio n. 17
0
def router(paramstring):
    params = dict(parse_qsl(paramstring))
    check_settings()
    session = Session()
    if params:
        print(params)
        if params['action'] == 'list_live':
            list_live(params['page'], params['label'])
        elif params['action'] == 'play_live':
            play_video(type='live',
                       channelKey=params['channelKey'],
                       start=None,
                       end=None,
                       epgId=None,
                       title=params['title'])

        elif params['action'] == 'list_archiv':
            list_archiv(params['label'])
        elif params['action'] == 'list_arch_days':
            list_arch_days(params['channelKey'], params['label'])
        elif params['action'] == 'list_program':
            list_program(params['channelKey'], params['day_min'],
                         params['label'])
        elif params['action'] == 'play_archiv':
            play_video(type='archiv',
                       channelKey=params['channelKey'],
                       start=params['start'],
                       end=params['end'],
                       epgId=params['epgId'],
                       title=None)

        elif params['action'] == 'list_categories':
            list_categories(params['label'])
        elif params['action'] == 'list_subcategories':
            list_subcategories(params['category'], params['label'])
        elif params['action'] == 'list_category':
            if 'page' not in params:
                params['page'] = None
            list_category(params['category'], params['dataSource'],
                          params['filtr'], params['page'], params['label'])
        elif params['action'] == 'list_series':
            list_series(params['epgId'], params['season'], params['label'])
        elif params['action'] == 'list_related':
            list_related(params['epgId'], params['label'])
        elif params['action'] == 'list_same':
            list_same(params['epgId'], params['label'])

        elif params['action'] == 'list_planning_recordings':
            list_planning_recordings(params['label'])
        elif params['action'] == 'list_rec_days':
            list_rec_days(params['channelKey'], params['label'])
        elif params['action'] == 'future_program':
            future_program(params['channelKey'], params['day'],
                           params['label'])
        elif params['action'] == 'list_recordings':
            list_recordings(params['label'])
        elif params['action'] == 'list_future_recordings':
            list_future_recordings(params['label'])
        elif params['action'] == 'delete_recording':
            delete_recording(params['channelKey'], params['pvrProgramId'])
        elif params['action'] == 'add_recording':
            add_recording(params['channelKey'], params['epgId'])
        elif params['action'] == 'play_recording':
            play_video(type='recording',
                       channelKey=params['channelKey'],
                       start=None,
                       end=None,
                       epgId=params['pvrProgramId'],
                       title=params['title'])

        elif params['action'] == 'list_search':
            list_search(params['label'])
        elif params['action'] == 'program_search':
            program_search(params['query'], params['label'])
        elif params['action'] == 'delete_search':
            delete_search(params['query'])

        elif params['action'] == 'list_settings':
            list_settings(params['label'])
        elif params['action'] == 'list_devices':
            list_devices(params['label'])
        elif params['action'] == 'unpair_device':
            unpair_device(params['deviceId'], params['deviceName'],
                          params['serviceid'])
        elif params['action'] == 'list_services':
            list_services(params['label'])
        elif params['action'] == 'enable_service':
            enable_service(params['serviceid'])
        elif params['action'] == 'disable_service':
            disable_service(params['serviceid'])
        elif params['action'] == 'move_service':
            move_service(params['serviceid'])

        elif params['action'] == 'list_channels_list':
            list_channels_list(params['label'])
        elif params['action'] == 'get_o2_channels_lists':
            get_o2_channels_lists(params['label'])
        elif params['action'] == 'load_o2_channels_list':
            load_o2_channels_list(params['serviceid'], params['list'])
        elif params['action'] == 'reset_channels_list':
            channels = Channels()
            channels.reset_channels()
        elif params['action'] == 'list_channels_list_backups':
            list_channels_list_backups(params['label'])
        elif params['action'] == 'restore_channels':
            channels = Channels()
            channels.restore_channels(params['backup'])
        elif params['action'] == 'list_channels_edit':
            list_channels_edit(params['label'])
        elif params['action'] == 'edit_channel':
            edit_channel(params['channelKey'])
        elif params['action'] == 'delete_channel':
            delete_channel(params['channelKey'])
        elif params['action'] == 'change_channels_numbers':
            change_channels_numbers(params['from_number'], params['direction'])

        elif params['action'] == 'list_channels_groups':
            list_channels_groups(params['label'])
        elif params['action'] == 'add_channel_group':
            add_channel_group(params['label'])
        elif params['action'] == 'delete_channel_group':
            delete_channel_group(params['group'])
        elif params['action'] == 'select_channel_group':
            select_channel_group(params['group'])

        elif params['action'] == 'edit_channel_group':
            edit_channel_group(params['group'], params['label'])
        elif params['action'] == 'edit_channel_group_list_channels':
            edit_channel_group_list_channels(params['group'], params['label'])
        elif params['action'] == 'edit_channel_group_add_channel':
            edit_channel_group_add_channel(params['group'], params['channel'])
        elif params['action'] == 'edit_channel_group_add_all_channels':
            edit_channel_group_add_all_channels(params['group'])
        elif params['action'] == 'edit_channel_group_delete_channel':
            edit_channel_group_delete_channel(params['group'],
                                              params['channel'])

        elif params['action'] == 'addon_settings':
            xbmcaddon.Addon().openSettings()

        elif params['action'] == 'generate_playlist':
            if 'output_file' in params:
                generate_playlist(params['output_file'])
                xbmcplugin.addDirectoryItem(_handle, '1', xbmcgui.ListItem())
                xbmcplugin.endOfDirectory(_handle, succeeded=True)
            else:
                generate_playlist()
        elif params['action'] == 'generate_epg':
            if 'output_file' in params:
                generate_epg(params['output_file'])
                xbmcplugin.addDirectoryItem(_handle, '1', xbmcgui.ListItem())
                xbmcplugin.endOfDirectory(_handle, succeeded=True)
            else:
                generate_epg()

        elif params['action'] == 'get_stream_url':
            if 'catchup_start_ts' in params and 'catchup_end_ts' in params:
                play_catchup(channelKey=params['channelKey'],
                             start_ts=params['catchup_start_ts'])
            else:
                if addon.getSetting('switch_channel_archiv') == 'true' and len(
                        xbmc.getInfoLabel('ListItem.ChannelName')) > 0 and len(
                            xbmc.getInfoLabel('ListItem.Date')) > 0:
                    iptv_sc_play(
                        xbmc.getInfoLabel('ListItem.ChannelName'),
                        parsedatetime(xbmc.getInfoLabel('ListItem.Date'),
                                      xbmc.getInfoLabel('ListItem.StartDate')),
                        0)
                else:
                    play_video(type='live_iptv',
                               channelKey=params['channelKey'],
                               start=None,
                               end=None,
                               epgId=None,
                               title=None)
        elif params['action'] == 'iptv_sc_play':
            iptv_sc_play(params['channel'], params['startdatetime'], 1)
        elif params['action'] == 'iptv_sc_rec':
            iptv_sc_rec(params['channel'], params['startdatetime'])
        elif params['action'] == 'iptv_sc_download':
            iptv_sc_download(params['channel'], params['startdatetime'])
        elif params['action'] == 'reset_session':
            session = Session()
            session.remove_session()

        elif params['action'] == 'add_to_queue':
            if 'pvrProgramId' in params:
                pvrProgramId = params['pvrProgramId']
            else:
                pvrProgramId = None
            add_to_queue(epgId=params['epgId'], pvrProgramId=pvrProgramId)
        elif params['action'] == 'remove_from_queue':
            remove_from_queue(epgId=params['epgId'])
        elif params['action'] == 'list_downloads':
            list_downloads(params['label'])
        else:
            raise ValueError('Neznámý parametr: {0}!'.format(paramstring))
    else:
        list_menu()