Beispiel #1
0
def non_interactive(mode, channel_name=None):
    if mode == 'get_online':
        # Output format:
        # Game name, Game display name (if present)...
        # Channel name, Channel display name (always present)
        channel_data = database_instance.fetch_data(('ChannelID', ),
                                                    'channels', None, 'LIKE')

        id_string_list = [str(i[0]) for i in channel_data]
        channels_online = twitchy_api.GetOnlineStatus(
            id_string_list).check_channels()

        # All standard channel parameters are available
        for i in channels_online.items():
            return_list = []
            config_correlate = {
                'GameName': i[1]['game'],
                'GameAltName': str(i[1]['game_display_name']),
                'ChannelName': i[0],
                'ChannelAltName': i[1]['display_name'],
                'Status': i[1]['status'],
                'Viewers': str(i[1]['viewers']),
                'Uptime': twitchy_display.time_convert(i[1]['uptime'])
            }

            for j in Options.non_int_display_scheme:
                return_list.append(config_correlate[j])

            print(Options.non_int_delimiter.join(return_list))

    if mode == 'kickstart':
        # Skip selection and just pass the channel name to the play module
        # All output is disabled except for error messages
        # Time tracking is disabled
        twitchy_config.print_to_stdout = False
        twitchy_config.time_tracking = False
        twitchy_config.non_interactive_mode = True

        if not channel_name:
            exit(1)

        try:
            api_reply = twitchy_api.name_id_translate('channels',
                                                      'id_from_name',
                                                      [channel_name])
            channel_id = api_reply[channel_name]['id']

            channel_status = twitchy_api.GetOnlineStatus([channel_id
                                                          ]).check_channels()
            # The video is started in default quality
            channel_status[channel_name][
                'quality'] = Options.video.default_quality
            twitchy_play.play_instance_generator(channel_status)
        except KeyError:
            exit()
Beispiel #2
0
def watch_channel(mode, database_search=None):
    if mode == 'watch':
        # database_search is expected to be a list
        # exact names of the channels the user wants to watch

        # Watch times are NOT tracked with -w
        # This greatly decreases the number of special conditions
        # that need to be accounted for
        twitchy_config.time_tracking = False

        id_string_list = []
        not_in_database = []

        database_search = [i.lower() for i in database_search]
        for i in database_search:
            search_criteria = {'Name': i}

            channel_data = database_instance.fetch_data(
                ('ChannelID', ), 'channels', search_criteria, 'EQUALS', True)

            if channel_data:
                # Channel data is expected as a string
                id_string_list.append(str(channel_data))
            else:
                not_in_database.append(i)

        if not_in_database:
            get_ids_from_api = twitchy_api.name_id_translate(
                'channels', 'id_from_name', [not_in_database])

            ids_only = [i[1]['id'] for i in get_ids_from_api.items()]
            id_string_list.extend(ids_only)

        if not id_string_list:
            raise YouAndTheHorseYouRodeInOn(' No valid channels.')

    else:
        # This is the standard watch() function
        # It expects only one argument
        if database_search:
            database_search = {
                'Name': database_search,
                'AltName': database_search
            }

        channel_data = database_instance.fetch_data(
            ('ChannelID', ), 'channels', database_search, 'LIKE')

        if channel_data:
            id_string_list = [str(i[0]) for i in channel_data]
        else:
            raise YouAndTheHorseYouRodeInOn(
                ' Database query returned nothing.')

    print(' ' + Options.colors.numbers +
          f'Checking {len(id_string_list)} channel(s)...' + Colors.ENDC)

    channels_online = twitchy_api.GetOnlineStatus(
        id_string_list).check_channels()
    if not channels_online:
        raise YouAndTheHorseYouRodeInOn(' All channels offline.')

    final_selection = twitchy_display.GenerateWatchTable(
        channels_online).begin()
    #print(' q / Ctrl + C to quit \n Now watching:')
    twitchy_play.play_instance_generator(final_selection)