예제 #1
0
def edit_channel_group(group, label):
    group = decode(group)
    xbmcplugin.setPluginCategory(_handle, label)
    channels_groups = Channels_groups()
    channels = Channels()
    channels_list = channels.get_channels_list(visible_filter=False)

    list_item = xbmcgui.ListItem(label='Přidat kanál')
    url = get_url(action='edit_channel_group_list_channels',
                  group=encode(group),
                  label=encode(group) + ' / Přidat kanál')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    list_item = xbmcgui.ListItem(label='Přidat všechny kanály')
    url = get_url(action='edit_channel_group_add_all_channels',
                  group=encode(group),
                  label=encode(group) + ' / Přidat kanál')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    if group in channels_groups.channels:
        for channel in channels_groups.channels[group]:
            if channel in channels_list:
                list_item = xbmcgui.ListItem(
                    label=channels_list[channel]['name'])
                url = get_url(action='edit_channel_group',
                              group=encode(group),
                              label=label)
                list_item.addContextMenuItems([(
                    'Smazat kanál',
                    'RunPlugin(plugin://' + plugin_id +
                    '?action=edit_channel_group_delete_channel&group=' +
                    quote(encode(group)) + '&channel=' +
                    quote(encode(channel)) + ')',
                )])
                xbmcplugin.addDirectoryItem(_handle, url, list_item, False)
    xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
예제 #2
0
def list_channels_edit(label):
    xbmcplugin.setPluginCategory(_handle, label)
    channels = Channels()
    channels_list = channels.get_channels_list('number', visible_filter=False)
    if len(channels_list) > 0:
        for number in sorted(channels_list.keys()):
            if channels_list[number]['visible'] == True:
                list_item = xbmcgui.ListItem(label=str(number) + ' ' +
                                             channels_list[number]['name'])
            else:
                list_item = xbmcgui.ListItem(
                    label='[COLOR=gray]' + str(number) + ' ' +
                    channels_list[number]['name'] + '[/COLOR]')
            url = get_url(action='edit_channel',
                          channelKey=encode(
                              channels_list[number]['channelKey']))
            list_item.addContextMenuItems([
                ('Zvýšit čísla kanálů',
                 encode('RunPlugin(plugin://' + plugin_id +
                        '?action=change_channels_numbers&from_number=' +
                        str(number) + '&direction=increase)')),
                ('Snížit čísla kanálů',
                 encode('RunPlugin(plugin://' + plugin_id +
                        '?action=change_channels_numbers&from_number=' +
                        str(number) + '&direction=decrease)')),
                ('Odstranit kanál',
                 encode('RunPlugin(plugin://' + plugin_id +
                        '?action=delete_channel&channelKey=' +
                        quote(encode(channels_list[number]['channelKey'])) +
                        ')'))
            ])
            xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
        xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
예제 #3
0
def list_related(epgId, label):
    xbmcplugin.setPluginCategory(_handle, label)
    addon = xbmcaddon.Addon(id=plugin_id)

    channels = Channels()
    channels_list = channels.get_channels_list()

    data = call_o2_api(url='https://api.o2tv.cz/unity/api/v1/programs/' +
                       str(epgId) + '/related/?encodedChannels=' +
                       channels.get_encoded_channels() + '&isFuture=false',
                       data=None,
                       header=get_header_unity())
    if 'err' in data:
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Problém s načtením kategorie',
                                      xbmcgui.NOTIFICATION_ERROR, 5000)
        sys.exit()
    if 'result' in data and len(data['result']) > 0:
        for event in data['result']:
            if event['channelKey'] in channels_list:
                startts = event['start'] / 1000
                start = datetime.fromtimestamp(event['start'] / 1000)
                endts = event['end'] / 1000
                end = datetime.fromtimestamp(event['end'] / 1000)
                epgId = event['epgId']
                list_item = xbmcgui.ListItem(
                    label=event['name'] + ' (' +
                    channels_list[event['channelKey']]['name'] + ' | ' +
                    decode(utils.day_translation_short[start.strftime('%w')]) +
                    ' ' + start.strftime('%d.%m %H:%M') + ' - ' +
                    end.strftime('%H:%M') + ')')
                list_item.setInfo(
                    'video', {
                        'mediatype':
                        'movie',
                        'title':
                        event['name'] + ' (' +
                        channels_list[event['channelKey']]['name'] + ')'
                    })
                list_item = get_listitem_epg_details(
                    list_item, str(event['epgId']),
                    channels_list[event['channelKey']]['logo'])
                list_item.setProperty('IsPlayable', 'true')
                list_item.setContentLookup(False)
                if addon.getSetting('download_streams') == 'true':
                    list_item.addContextMenuItems([
                        ('Stáhnout', 'RunPlugin(plugin://' + plugin_id +
                         '?action=add_to_queue&epgId=' + str(epgId) + ')')
                    ])
                url = get_url(action='play_archiv',
                              channelKey=encode(event['channelKey']),
                              start=startts,
                              end=endts,
                              epgId=epgId)
                xbmcplugin.addDirectoryItem(_handle, url, list_item, False)
            xbmcplugin.endOfDirectory(_handle)
    else:
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Žádné pořady nenalezeny',
                                      xbmcgui.NOTIFICATION_INFO, 4000)
예제 #4
0
def list_settings(label):
    xbmcplugin.setPluginCategory(_handle, label)

    list_item = xbmcgui.ListItem(label='Kanály')
    url = get_url(action='list_channels_list', label='Kanály')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    list_item = xbmcgui.ListItem(label='Služby')
    url = get_url(action='list_services', label='Služby')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    list_item = xbmcgui.ListItem(label='Zařízení')
    url = get_url(action='list_devices', label='Zařízení')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    list_item = xbmcgui.ListItem(label='Nastavení doplňku')
    url = get_url(action='addon_settings', label='Nastavení doplňku')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    xbmcplugin.endOfDirectory(_handle)
예제 #5
0
def list_series(epgId, season, label):
    xbmcplugin.setPluginCategory(_handle, label)
    params = ''
    channels = Channels()
    channels_list = channels.get_channels_list()
    if int(season) > 0:
        params = params + '&seasonNumber=' + str(season)
    data = call_o2_api(
        url='https://api.o2tv.cz/unity/api/v1/programs/' + str(epgId) +
        '/episodes/?containsAllGenres=false&encodedChannels=' +
        channels.get_encoded_channels() + '&isFuture=false' + params,
        data=None,
        header=get_header_unity())
    if 'err' in data:
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Problém s načtením kategorie',
                                      xbmcgui.NOTIFICATION_ERROR, 4000)
        sys.exit()
    if 'result' in data and len(data['result']) > 0:
        for event in data['result']:
            if event['channelKey'] in channels_list:
                startts = event['start'] / 1000
                start = datetime.fromtimestamp(event['start'] / 1000)
                endts = event['end'] / 1000
                end = datetime.fromtimestamp(event['end'] / 1000)
                epgId = event['epgId']
                list_item = xbmcgui.ListItem(
                    label=event['name'] + ' (' +
                    channels_list[event['channelKey']]['name'] + ' | ' +
                    decode(utils.day_translation_short[start.strftime('%w')]) +
                    ' ' + start.strftime('%d.%m %H:%M') + ' - ' +
                    end.strftime('%H:%M') + ')')
                list_item.setInfo(
                    'video', {
                        'mediatype':
                        'movie',
                        'title':
                        event['name'] + ' (' +
                        channels_list[event['channelKey']]['name'] + ')'
                    })
                list_item = get_listitem_epg_details(
                    list_item, str(event['epgId']),
                    channels_list[event['channelKey']]['logo'])
                list_item.setProperty('IsPlayable', 'true')
                list_item.setContentLookup(False)
                url = get_url(action='play_archiv',
                              channelKey=encode(event['channelKey']),
                              start=startts,
                              end=endts,
                              epgId=epgId)
                xbmcplugin.addDirectoryItem(_handle, url, list_item, False)
        xbmcplugin.endOfDirectory(_handle)
예제 #6
0
def list_channels_list(label):
    xbmcplugin.setPluginCategory(_handle, label)
    list_item = xbmcgui.ListItem(label='Ruční editace')
    url = get_url(action='list_channels_edit',
                  label=label + ' / Ruční editace')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    list_item = xbmcgui.ListItem(label='Načtení uživatelského seznamu z O2')
    url = get_url(action='get_o2_channels_lists',
                  label=label + '/ Načtení z O2')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    list_item = xbmcgui.ListItem(label='Vlastní skupiny kanálů')
    url = get_url(action='list_channels_groups',
                  label=label + ' / Skupiny kanálů')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    list_item = xbmcgui.ListItem(label='Resetovat seznam kanálů')
    url = get_url(action='reset_channels_list')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    list_item = xbmcgui.ListItem(label='Obnovit seznam kanálů')
    url = get_url(action='list_channels_list_backups',
                  label=label + ' / Obnova seznamu kanálů')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle)
예제 #7
0
def list_channels_groups(label):
    xbmcplugin.setPluginCategory(_handle, label)
    channels_groups = Channels_groups()

    list_item = xbmcgui.ListItem(label='Nová skupina')
    url = get_url(action='add_channel_group', label='Nová skupina')
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    if channels_groups.selected == None:
        list_item = xbmcgui.ListItem(label='[B]Všechny kanály[/B]')
    else:
        list_item = xbmcgui.ListItem(label='Všechny kanály')
    url = get_url(action='list_channels_groups',
                  label='Seznam kanálů / Skupiny kanálů')
    list_item.addContextMenuItems([(
        'Vybrat skupinu',
        'RunPlugin(plugin://' + plugin_id +
        '?action=select_channel_group&group=all)',
    )])
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    for channels_group in channels_groups.groups:
        if channels_groups.selected == channels_group:
            list_item = xbmcgui.ListItem(label='[B]' + channels_group + '[/B]')
        else:
            list_item = xbmcgui.ListItem(label=channels_group)
        url = get_url(action='edit_channel_group',
                      group=encode(channels_group),
                      label='Skupiny kanálů / ' + encode(channels_group))
        list_item.addContextMenuItems([
            ('Vybrat skupinu', 'RunPlugin(plugin://' + plugin_id +
             '?action=select_channel_group&group=' +
             quote(encode(channels_group)) + ')'),
            ('Smazat skupinu', 'RunPlugin(plugin://' + plugin_id +
             '?action=delete_channel_group&group=' +
             quote(encode(channels_group)) + ')')
        ])
        xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
예제 #8
0
def list_categories(label):
    xbmcplugin.setPluginCategory(_handle, label)
    categories, subcategories, slugs = load_categories()  # pylint: disable=unused-variable
    for slug in slugs:
        if categories[slug]['type'] == 'programs' and 'filter' in categories[
                slug]:
            filtr = encode(
                json.dumps({
                    'genres':
                    categories[slug]['filter']['genres'],
                    'notGenres':
                    categories[slug]['filter']['notGenres'],
                    'containsAllGenres':
                    categories[slug]['filter']['containsAllGenres'],
                    'contentType':
                    categories[slug]['filter']['contentType']
                }))
            list_item = xbmcgui.ListItem(
                label=encode(categories[slug]['name']))
            url = get_url(
                action='list_category',
                category=encode(categories[slug]['filter']['contentType']),
                dataSource=categories[slug]['dataSource'],
                filtr=filtr,
                label=label + ' / ' + encode(categories[slug]['name']))
            xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
        if categories[slug]['type'] == 'list' and 'filter' in categories[slug]:
            list_item = xbmcgui.ListItem(
                label=encode(categories[slug]['name']))
            url = get_url(action='list_subcategories',
                          category=encode(categories[slug]['filter']['name']),
                          dataSource=categories[slug]['dataSource'],
                          label=label + ' / ' +
                          encode(categories[slug]['name']))
            xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle)
예제 #9
0
def edit_channel_group_list_channels(group, label):
    group = decode(group)
    xbmcplugin.setPluginCategory(_handle, label)
    channels_groups = Channels_groups()
    channels = Channels()
    channels_list = channels.get_channels_list('number', visible_filter=False)
    for number in sorted(channels_list.keys()):
        if not group in channels_groups.groups or not group in channels_groups.channels or not channels_list[
                number]['channelKey'] in channels_groups.channels[group]:
            list_item = xbmcgui.ListItem(label=str(number) + ' ' +
                                         channels_list[number]['name'])
            url = get_url(action='edit_channel_group_add_channel',
                          group=encode(group),
                          channel=encode(channels_list[number]['channelKey']))
            xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
def list_planning_recordings(label):
    xbmcplugin.setPluginCategory(_handle, label)
    channels = Channels()
    channels_list = channels.get_channels_list('number')
    for number in sorted(channels_list.keys()):
        list_item = xbmcgui.ListItem(label=channels_list[number]['name'])
        if len(channels_list[number]['logo']) > 0:
            list_item.setArt({
                'thumb': channels_list[number]['logo'],
                'icon': channels_list[number]['logo']
            })
        url = get_url(action='list_rec_days',
                      channelKey=encode(channels_list[number]['channelKey']),
                      label=label + ' / ' +
                      encode(channels_list[number]['name']))
        xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle)
def future_program(channelKey, day, label):
    label = label.replace('Nahrávky / Plánování /', '')
    xbmcplugin.setPluginCategory(_handle, label)
    channels = Channels()
    channels_list = channels.get_channels_list()

    channelKey = decode(channelKey)
    if int(day) == 0:
        from_datetime = datetime.now()
        to_datetime = datetime.combine(date.today(), datetime.max.time())
    else:
        from_datetime = datetime.combine(
            date.today(), datetime.min.time()) + timedelta(days=int(day))
        to_datetime = datetime.combine(from_datetime, datetime.max.time())
    from_ts = int(time.mktime(from_datetime.timetuple()))
    to_ts = int(time.mktime(to_datetime.timetuple()))

    events = get_epg_ts(channelKey, from_ts, to_ts, 5)
    for key in sorted(events.keys()):
        epgId = events[key]['epgId']
        start = events[key]['start']
        end = events[key]['end']
        list_item = xbmcgui.ListItem(
            label=decode(utils.day_translation_short[start.strftime('%w')]) +
            ' ' + start.strftime('%d.%m %H:%M') + ' - ' +
            end.strftime('%H:%M') + ' | ' + events[key]['title'])
        list_item = get_listitem_epg_details(list_item, str(epgId),
                                             channels_list[channelKey]['logo'])
        list_item.setInfo('video', {
            'mediatype': 'movie',
            'title': events[key]['title']
        })
        list_item.setProperty('IsPlayable', 'false')
        list_item.addContextMenuItems([(
            'Přidat nahrávku',
            'RunPlugin(plugin://' + plugin_id +
            '?action=add_recording&channelKey=' + channelKey + '&epgId=' +
            str(epgId) + ')',
        )])
        url = get_url(action='add_recording',
                      channelKey=encode(channelKey),
                      epgId=epgId)
        xbmcplugin.addDirectoryItem(_handle, url, list_item, False)
    xbmcplugin.endOfDirectory(_handle)
def list_rec_days(channelKey, label):
    xbmcplugin.setPluginCategory(_handle, label)
    for i in range(10):
        day = date.today() + timedelta(days=i)
        if i == 0:
            den_label = 'Dnes'
            den = 'Dnes'
        elif i == 1:
            den_label = 'Zítra'
            den = 'Zítra'
        else:
            den_label = utils.day_translation_short[day.strftime(
                '%w')] + ' ' + day.strftime('%d.%m')
            den = decode(utils.day_translation[day.strftime(
                '%w')]) + ' ' + day.strftime('%d.%m.%Y')
        list_item = xbmcgui.ListItem(label=den)
        url = get_url(action='future_program',
                      channelKey=channelKey,
                      day=i,
                      label=label + ' / ' + den_label)
        xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle)
예제 #13
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)
예제 #14
0
def list_channels_list_backups(label):
    xbmcplugin.setPluginCategory(_handle, label)
    addon = xbmcaddon.Addon()
    addon_userdata_dir = translatePath(addon.getAddonInfo('profile'))
    channels = Channels()
    backups = channels.get_backups()
    if len(backups) > 0:
        for backup in sorted(backups):
            date_list = backup.replace(addon_userdata_dir,
                                       '').replace('channels_backup_',
                                                   '').replace('.txt',
                                                               '').split('-')
            item = 'Záloha z ' + date_list[2] + '.' + date_list[
                1] + '.' + date_list[0] + ' ' + date_list[3] + ':' + date_list[
                    4] + ':' + date_list[5]
            list_item = xbmcgui.ListItem(label=item)
            url = get_url(action='restore_channels', backup=backup)
            xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
        xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
    else:
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Neexistuje žádná záloha',
                                      xbmcgui.NOTIFICATION_INFO, 5000)
예제 #15
0
def list_downloads(label):
    _handle = int(sys.argv[1])
    xbmcplugin.setPluginCategory(_handle, label)
    open_db()
    for row in db.execute(
            'SELECT epgId, title, startts, endts, status, downloadts FROM queue ORDER BY downloadts DESC'
    ):
        epgId = int(row[0])
        title = row[1]
        startts = int(row[2])
        endts = int(row[3])
        status = int(row[4])
        if row[5] != 'null':
            downloadts = int(row[5])
        else:
            downloadts = None
        currentts = int(time.mktime(datetime.now().timetuple()))
        if status == 1:
            title = encode(title) + ' (100%)'
        elif status == -1:
            title = encode(title) + ' (CHYBA)'
        elif downloadts == None:
            title = encode(title) + ' (ČEKÁ)'
        else:
            pct = float(currentts - downloadts) / (endts - startts) * 100
            title = encode(title) + ' (' + str(int(pct)) + '%)'
        list_item = xbmcgui.ListItem(label=title)
        list_item.setProperty('IsPlayable', 'false')
        list_item.setContentLookup(False)
        list_item.addContextMenuItems([
            ('Smazat z fronty', 'RunPlugin(plugin://' + plugin_id +
             '?action=remove_from_queue&epgId=' + str(epgId) + ')')
        ])
        url = get_url(action='list_downloads', label=label)
        xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
    close_db()
예제 #16
0
def list_subcategories(category, label):
    xbmcplugin.setPluginCategory(_handle, label)
    categories, subcategories, slugs = load_categories()  # pylint: disable=unused-variable
    subcategory_keys = {}
    for num in subcategories[category].keys():
        subcategory_keys.update({int(num): num})
    for num in sorted(subcategory_keys.keys()):
        subcategory = subcategory_keys[num]
        if subcategories[category][subcategory][
                'type'] == 'programs' and encode(
                    subcategories[category][subcategory]['filter']
                    ['contentType']) != 'živý přenos':
            filtr = encode(
                json.dumps({
                    'genres':
                    subcategories[category][subcategory]['filter']['genres'],
                    'notGenres':
                    subcategories[category][subcategory]['filter']
                    ['notGenres'],
                    'containsAllGenres':
                    subcategories[category][subcategory]['filter']
                    ['containsAllGenres'],
                    'contentType':
                    subcategories[category][subcategory]['filter']
                    ['contentType']
                }))
            list_item = xbmcgui.ListItem(
                label=encode(subcategories[category][subcategory]['name']))
            url = get_url(
                action='list_category',
                category=encode(subcategories[category][subcategory]['name']),
                dataSource=subcategories[category][subcategory]['dataSource'],
                filtr=filtr,
                label=label + ' / ' +
                encode(subcategories[category][subcategory]['name']))
            xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle)
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()
예제 #18
0
def list_menu():
    icons_dir = os.path.join(addon.getAddonInfo('path'), 'resources', 'images')

    list_item = xbmcgui.ListItem(label='Živé vysílání')
    url = get_url(action='list_live', page=1, label='Živé vysílání')
    list_item.setArt({
        'thumb': os.path.join(icons_dir, 'livetv.png'),
        'icon': os.path.join(icons_dir, 'livetv.png')
    })
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    list_item = xbmcgui.ListItem(label='Archiv')
    url = get_url(action='list_archiv', label='Archiv')
    list_item.setArt({
        'thumb': os.path.join(icons_dir, 'archive.png'),
        'icon': os.path.join(icons_dir, 'archive.png')
    })
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    list_item = xbmcgui.ListItem(label='Kategorie')
    url = get_url(action='list_categories', label='Kategorie')
    list_item.setArt({
        'thumb': os.path.join(icons_dir, 'categories.png'),
        'icon': os.path.join(icons_dir, 'categories.png')
    })
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    list_item = xbmcgui.ListItem(label='Nahrávky')
    url = get_url(action='list_recordings', label='Nahrávky')
    list_item.setArt({
        'thumb': os.path.join(icons_dir, 'recordings.png'),
        'icon': os.path.join(icons_dir, 'recordings.png')
    })
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    list_item = xbmcgui.ListItem(label='Vyhledávání')
    url = get_url(action='list_search', label='Vyhledávání')
    list_item.setArt({
        'thumb': os.path.join(icons_dir, 'search.png'),
        'icon': os.path.join(icons_dir, 'search.png')
    })
    xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    if addon.getSetting('download_streams') == 'true':
        list_item = xbmcgui.ListItem(label='Stahování')
        url = get_url(action='list_downloads', label='Stahování')
        list_item.setArt({
            'thumb': os.path.join(icons_dir, 'downloads.png'),
            'icon': os.path.join(icons_dir, 'downloads.png')
        })
        xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    if addon.getSetting('hide_channel_list_edit') != 'true':
        list_item = xbmcgui.ListItem(label='Nastavení O2TV')
        url = get_url(action='list_settings', label='Nastavení O2TV')
        list_item.setArt({
            'thumb': os.path.join(icons_dir, 'settings.png'),
            'icon': os.path.join(icons_dir, 'settings.png')
        })
        xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    # list_item = xbmcgui.ListItem(label='Test session')
    # url = get_url(action='test_session')
    # list_item.setArt({ 'thumb' : os.path.join(icons_dir , 'settings.png'), 'icon' : os.path.join(icons_dir , 'settings.png') })
    # xbmcplugin.addDirectoryItem(_handle, url, list_item, True)

    xbmcplugin.endOfDirectory(_handle)
예제 #19
0
def list_category(category, dataSource, filtr, page, label):
    xbmcplugin.setPluginCategory(_handle, label)
    addon = xbmcaddon.Addon()
    page_limit = int(addon.getSetting('category_pagesize'))
    filtr = json.loads(filtr)
    params = ''
    genres = []
    nongenres = []
    for genre in filtr['genres']:
        if len(genre) > 0:
            params = params + '&genres=' + quote_plus(encode(genre))
            genres.append(genre)
    for nongenre in filtr['notGenres']:
        if len(nongenre) > 0:
            params = params + '&notGenres=' + quote_plus(encode(nongenre))
            nongenres.append(nongenre)
    contentType = filtr['contentType']

    channels = Channels()
    channels_list = channels.get_channels_list()

    events = {}
    data = call_o2_api(
        url='https://api.o2tv.cz' + dataSource + '?containsAllGenres=' +
        str(filtr['containsAllGenres']).lower() + '&contentType=' +
        contentType + params + '&encodedChannels=' +
        channels.get_encoded_channels() +
        '&sort=-o2rating&grouped=true&isFuture=false&limit=500&offset=0',
        data=None,
        header=get_header_unity())
    if 'err' in data:
        xbmcgui.Dialog().notification('Sledování O2TV',
                                      'Problém s načtením kategorie',
                                      xbmcgui.NOTIFICATION_ERROR, 5000)
        sys.exit()
    if 'result' in data and len(data['result']) > 0:
        num = 0
        cnt = 0
        characters = []
        for event in data['result']:
            cnt = cnt + 1
            if addon.getSetting('categories_sorting') == 'ratingu':
                events.update({num: event})
                num = num + 1
            else:
                events.update({remove_diacritics(event['name']): event})
                if remove_diacritics(
                        event['name'][:1].upper()) not in characters:
                    characters.append(
                        remove_diacritics(event['name'][:1].upper()))
        if addon.getSetting(
                'categories_sorting'
        ) == 'názvu' and page is None and page_limit > 0 and len(
                events) > page_limit:
            characters.sort()
            for character in characters:
                list_item = xbmcgui.ListItem(label=character)
                url = get_url(action='list_category',
                              category=contentType,
                              dataSource=dataSource,
                              filtr=json.dumps(filtr),
                              page=encode(character),
                              label=label + ' / ' +
                              encode(character.decode('utf-8')))
                xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
        else:
            if addon.getSetting(
                    'categories_sorting') == 'ratingu' and page_limit > 0:
                if page is None:
                    page = 1
                startitem = (int(page) - 1) * page_limit
            cnt = 0
            for key in sorted(events.keys()):
                if page is None or page_limit == 0 or (
                        page is not None
                        and addon.getSetting('categories_sorting') == 'názvu'
                        and remove_diacritics(events[key]['name'][:1].upper())
                        == page.encode('utf-8')
                ) or (page is not None
                      and addon.getSetting('categories_sorting') == 'ratingu'
                      and cnt >= startitem and cnt < startitem + page_limit):
                    event = events[key]
                    startts = event['start'] / 1000
                    start = datetime.fromtimestamp(event['start'] / 1000)
                    endts = event['end'] / 1000
                    end = datetime.fromtimestamp(event['end'] / 1000)
                    epgId = event['epgId']
                    isSeries = 0
                    if event['channelKey'] in channels_list:
                        if 'seriesInfo' in event and 'seriesName' in event[
                                'seriesInfo'] and len(
                                    event['seriesInfo']['seriesName']) > 0:
                            isSeries = 1
                            event['name'] = event['seriesInfo']['seriesName']
                            if 'seasonNumber' in event['seriesInfo']:
                                event['name'] = event[
                                    'name']  # + ' ['+ str(event['seriesInfo']['seasonNumber']) + ']'
                            list_item = xbmcgui.ListItem(
                                label=event['name'] + ' (' +
                                channels_list[event['channelKey']]['name'] +
                                ')')
                        else:
                            list_item = xbmcgui.ListItem(
                                label=event['name'] + ' (' +
                                channels_list[event['channelKey']]['name'] +
                                ' | ' + decode(utils.day_translation_short[
                                    start.strftime('%w')]) + ' ' +
                                start.strftime('%d.%m %H:%M') + ' - ' +
                                end.strftime('%H:%M') + ')')
                        cast = []
                        directors = []
                        genres = []
                        list_item.setInfo(
                            'video', {
                                'mediatype':
                                'movie',
                                'title':
                                event['name'] + ' (' +
                                channels_list[event['channelKey']]['name'] +
                                ')'
                            })
                        if 'images' in event and len(event['images']) > 0:
                            list_item.setArt({
                                'poster':
                                'https://img1.o2tv.cz/' +
                                event['images'][0]['cover'],
                                'thumb':
                                'https://img1.o2tv.cz/' +
                                event['images'][0]['cover'],
                                'icon':
                                'https://img1.o2tv.cz/' +
                                event['images'][0]['cover']
                            })
                        if 'longDescription' in event and len(
                                event['longDescription']) > 0:
                            list_item.setInfo(
                                'video', {'plot': event['longDescription']})
                        if 'ratings' in event and len(event['ratings']) > 0:
                            for rating, rating_value in event['ratings'].items(
                            ):
                                list_item.setRating(rating,
                                                    int(rating_value) / 10)
                        if 'castAndCrew' in event and len(
                                event['castAndCrew']
                        ) > 0 and 'cast' in event['castAndCrew'] and len(
                                event['castAndCrew']['cast']) > 0:
                            for person in event['castAndCrew']['cast']:
                                cast.append(encode(person['name']))
                            list_item.setInfo('video', {'cast': cast})
                        if 'castAndCrew' in event and len(
                                event['castAndCrew']
                        ) > 0 and 'directors' in event['castAndCrew'] and len(
                                event['castAndCrew']['directors']) > 0:
                            for person in event['castAndCrew']['directors']:
                                directors.append(encode(person['name']))
                            list_item.setInfo('video', {'director': directors})
                        if 'origin' in event and len(event['origin']) > 0:
                            if 'year' in event['origin'] and len(
                                    str(event['origin']['year'])) > 0:
                                list_item.setInfo(
                                    'video', {'year': event['origin']['year']})
                            if 'country' in event['origin'] and len(
                                    event['origin']['country']) > 0:
                                list_item.setInfo('video', {
                                    'country':
                                    event['origin']['country']['name']
                                })
                        if 'origName' in event and len(event['origName']) > 0:
                            list_item.setInfo(
                                'video', {'originaltitle': event['origName']})
                        if 'ext' in event and len(
                                event['ext']) > 0 and 'imdbId' in event[
                                    'ext'] and len(event['ext']['imdbId']) > 0:
                            list_item.setInfo(
                                'video',
                                {'imdbnumber': event['ext']['imdbId']})
                        if 'genreInfo' in event and len(
                                event['genreInfo']
                        ) > 0 and 'genres' in event['genreInfo'] and len(
                                event['genreInfo']['genres']) > 0:
                            for genre in event['genreInfo']['genres']:
                                genres.append(encode(genre['name']))
                            list_item.setInfo('video', {'genre': genres})
                        menus = [
                            ('Související pořady',
                             'Container.Update(plugin://' + plugin_id +
                             '?action=list_related&epgId=' + str(epgId) +
                             '&label=Související / ' + encode(event['name']) +
                             ')'),
                            ('Vysílání pořadu',
                             'Container.Update(plugin://' + plugin_id +
                             '?action=list_same&epgId=' + str(epgId) +
                             '&label=' + encode(event['name']) + ')'),
                            ('Přidat nahrávku', 'RunPlugin(plugin://' +
                             plugin_id + '?action=add_recording&channelKey=' +
                             event['channelKey'] + '&epgId=' + str(epgId) +
                             ')')
                        ]
                        if addon.getSetting('download_streams') == 'true':
                            menus.append(
                                ('Stáhnout', 'RunPlugin(plugin://' +
                                 plugin_id + '?action=add_to_queue&epgId=' +
                                 str(epgId) + ')'))
                        list_item.addContextMenuItems(menus)
                        if isSeries == 0:
                            list_item.setProperty('IsPlayable', 'true')
                            list_item.setContentLookup(False)
                            url = get_url(action='play_archiv',
                                          channelKey=encode(
                                              event['channelKey']),
                                          start=startts,
                                          end=endts,
                                          epgId=epgId)
                            xbmcplugin.addDirectoryItem(
                                _handle, url, list_item, False)
                        else:
                            if 'seasonNumber' in event['seriesInfo'] and int(
                                    event['seriesInfo']['seasonNumber']) > 0:
                                season = int(
                                    event['seriesInfo']['seasonNumber'])
                            else:
                                season = -1
                            list_item.setProperty('IsPlayable', 'false')
                            url = get_url(action='list_series',
                                          epgId=epgId,
                                          season=season,
                                          label=encode(event['name']))
                            xbmcplugin.addDirectoryItem(
                                _handle, url, list_item, True)
                cnt = cnt + 1

            if page is not None and addon.getSetting(
                    'categories_sorting'
            ) == 'ratingu' and int(page) * page_limit <= cnt:
                list_item = xbmcgui.ListItem(label='další strana')
                url = get_url(action='list_category',
                              category=contentType,
                              dataSource=dataSource,
                              filtr=json.dumps(filtr),
                              page=int(page) + 1,
                              label=label)
                list_item.setProperty('IsPlayable', 'false')
                xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle)
def list_program(channelKey, day_min, label):
    label = label.replace('Archiv /', '')
    xbmcplugin.setPluginCategory(_handle, label)
    addon = xbmcaddon.Addon()
    channelKey = decode(channelKey)
    channels = Channels()
    channels_list = channels.get_channels_list()
    if int(day_min) == 0:
        from_datetime = datetime.combine(date.today(), datetime.min.time())
        to_datetime = datetime.now()
    else:
        from_datetime = datetime.combine(
            date.today(), datetime.min.time()) - timedelta(days=int(day_min))
        to_datetime = datetime.combine(from_datetime, datetime.max.time())
    from_ts = int(time.mktime(from_datetime.timetuple()))
    to_ts = int(time.mktime(to_datetime.timetuple()))

    events = {}
    events = get_epg_ts(channelKey, from_ts, to_ts, 8)

    if addon.getSetting('archive_reverse_sort') == "true":
        archive_reverse = True
    else:
        archive_reverse = False

    for key in sorted(events.keys(), reverse=archive_reverse):
        if int(events[key]['endts']) > int(
                time.mktime(datetime.now().timetuple())) - 60 * 60 * 24 * 7:
            list_item = xbmcgui.ListItem(
                label=decode(utils.day_translation_short[
                    events[key]['start'].strftime('%w')]) + ' ' +
                events[key]['start'].strftime('%d.%m %H:%M') + ' - ' +
                events[key]['end'].strftime('%H:%M') + ' | ' +
                events[key]['title'])
            list_item.setInfo('video', {
                'mediatype': 'movie',
                'title': events[key]['title']
            })
            list_item = get_listitem_epg_details(
                list_item, str(events[key]['epgId']),
                channels_list[channelKey]['logo'])
            list_item.setProperty('IsPlayable', 'true')
            list_item.setContentLookup(False)
            menus = [
                ('Přidat nahrávku', 'RunPlugin(plugin://' + plugin_id +
                 '?action=add_recording&channelKey=' + channelKey + '&epgId=' +
                 str(events[key]['epgId']) + ')'),
                ('Související pořady',
                 'Container.Update(plugin://' + plugin_id +
                 '?action=list_related&epgId=' + str(events[key]['epgId']) +
                 '&label=Související / ' + encode(events[key]['title']) + ')'),
                ('Vysílání pořadu', 'Container.Update(plugin://' + plugin_id +
                 '?action=list_same&epgId=' + str(events[key]['epgId']) +
                 '&label=' + encode(events[key]['title']) + ')')
            ]
            if addon.getSetting('download_streams') == 'true':
                menus.append(('Stáhnout', 'RunPlugin(plugin://' + plugin_id +
                              '?action=add_to_queue&epgId=' +
                              str(events[key]['epgId']) + ')'))
            list_item.addContextMenuItems(menus)
            url = get_url(action='play_archiv',
                          channelKey=encode(channelKey),
                          start=events[key]['startts'],
                          end=events[key]['endts'],
                          epgId=events[key]['epgId'])
            xbmcplugin.addDirectoryItem(_handle, url, list_item, False)
    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)
예제 #22
0
def list_live(page, label):
    addon = xbmcaddon.Addon()
    xbmcplugin.setPluginCategory(_handle, label)
    channels = Channels()
    channels_list = channels.get_channels_list('number')
    num = 0
    pagesize = int(addon.getSetting('live_pagesize'))
    channels_details = get_epg_live(len(channels_list.keys()))
    color = get_color(addon.getSetting('label_color_live'))
    startitem = (int(page) - 1) * pagesize
    i = 0

    for num in sorted(channels_list.keys()):
        if i >= startitem and i < startitem + pagesize:
            channelName = channels_list[num]['name']
            channelKey = channels_list[num]['channelKey']
            if channelName in channels_details:
                title = channels_details[channelName]['title']
                start = channels_details[channelName]['start']
                end = channels_details[channelName]['end']
                live = '[COLOR ' + str(
                    color) + '] | ' + title + ' | ' + start.strftime(
                        '%H:%M') + ' - ' + end.strftime('%H:%M') + '[/COLOR]'
                live_noncolor = ' | ' + title + ' | ' + start.strftime(
                    '%H:%M') + ' - ' + end.strftime('%H:%M')
                list_item = xbmcgui.ListItem(label=encode(channelName) +
                                             encode(live))
                list_item.setInfo(
                    'video', {
                        'mediatype': 'movie',
                        'title': encode(channelName) + ' | ' + encode(title)
                    })
                list_item = get_listitem_epg_details(
                    list_item, str(channels_details[channelName]['epgId']),
                    channels_list[num]['logo'])
            else:
                live = ''
                live_noncolor = ''
                list_item = xbmcgui.ListItem(label=encode(channelName) +
                                             encode(live))
                list_item.setInfo(
                    'video', {
                        'mediatype': 'movie',
                        'title': encode(channelName) + encode(live)
                    })
            list_item.setContentLookup(False)
            list_item.setProperty('IsPlayable', 'true')
            if channelName in channels_details:
                list_item.addContextMenuItems([
                    ('Související pořady', 'Container.Update(plugin://' +
                     plugin_id + '?action=list_related&epgId=' +
                     str(channels_details[channelName]['epgId']) +
                     '&label=Související / ' +
                     encode(channels_details[channelName]['title']) + ')'),
                    ('Vysílání pořadu', 'Container.Update(plugin://' +
                     plugin_id + '?action=list_same&epgId=' +
                     str(channels_details[channelName]['epgId']) + '&label=' +
                     encode(channels_details[channelName]['title']) + ')')
                ])
            url = get_url(action='play_live',
                          channelKey=encode(channelKey),
                          title=encode(channelName) + encode(live_noncolor))
            xbmcplugin.addDirectoryItem(_handle, url, list_item, False)
        i = i + 1

    if int(page) * pagesize <= i:
        list_item = xbmcgui.ListItem(label='další strana')
        url = get_url(action='list_live',
                      page=int(page) + 1,
                      label='další strana')
        list_item.setProperty('IsPlayable', 'false')
        xbmcplugin.addDirectoryItem(_handle, url, list_item, True)
    xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)