Esempio n. 1
0
def channel_addition(option, channels):
    # option is either 'add' for -a
    # -a expects a list
    # OR 'sync' for -s
    # -s accepts only a string
    # Everything is converted to lowercase in the relevant function

    print(' ' + Colors.YELLOW + 'Additions to database:' + Colors.ENDC)

    # Get the numeric id of each channel that is to be added to the database
    if option == 'add':
        valid_channels = twitchy_api.name_id_translate('channels',
                                                       'id_from_name',
                                                       [channels])
    elif option == 'sync':
        valid_channels = twitchy_api.sync_from_id(channels)

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

    # Actual addition to the database takes place here
    added_channels = twitchy_database.DatabaseFunctions().add_channels(
        valid_channels)

    if not added_channels:
        raise YouAndTheHorseYouRodeInOn(' No valid channels.')
    else:
        for i in added_channels:
            print(' ' + i)
Esempio n. 2
0
def watch_vods(channel_name):
    channel_data = twitchy_api.name_id_translate('channels', 'id_from_name',
                                                 [channel_name])

    try:
        channel_id = channel_data[channel_name[0]]['id']
        display_name = channel_data[channel_name[0]]['display_name']
    except KeyError:
        raise YouAndTheHorseYouRodeInOn(' Invalid name.')

    vod_list = twitchy_api.get_vods(channel_id)
    print(' ' + Options.colors.numbers + f'VODs for {display_name}:' +
          Colors.ENDC)

    if not vod_list:
        raise YouAndTheHorseYouRodeInOn(' No VODs found.')

    final_selection = {
        display_name: twitchy_display.GenerateVODTable(vod_list).begin()
    }
    twitchy_config.time_tracking = False
    twitchy_config.vod_mode = True

    print(' q / Ctrl + C to quit \n Now watching:')
    twitchy_play.play_instance_generator(final_selection)
Esempio n. 3
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()
Esempio n. 4
0
        def fill_in_the_blanks(table):
            name_data = database_new.execute(
                f"SELECT Name FROM {table}").fetchall()
            valid_entries = twitchy_api.name_id_translate(
                table, 'id_from_name', name_data)

            if table == 'games':
                # In this case, valid_entries is a list
                # that contains 2 entires
                # 0 is the id number
                # 1 is the game name
                for i in valid_entries:
                    game_id = i[0]
                    game_name = i[1]
                    sql_command = (
                        f"UPDATE games SET GameID = '{game_id}' WHERE Name = '{game_name}'"
                    )
                    database_new.execute(sql_command)

                database_new.execute(f"DELETE FROM games WHERE GameID is NULL")

            elif table == 'channels':
                # In this case, valid_entires is a dictionary
                # That contains broadcaster_type, display_name, and id
                # couples to each channel name
                for i in valid_entries.items():
                    channel_name = i[0]
                    display_name = i[1]['display_name']
                    channel_id = i[1]['id']
                    is_partner = False
                    if i[1]['broadcaster_type'] == 'partner':
                        is_partner = True

                    sql_command = (
                        f"UPDATE channels SET "
                        f"ChannelID = '{channel_id}', DisplayName = '{display_name}', "
                        f"IsPartner = '{is_partner}' "
                        f"WHERE Name = '{channel_name}'")
                    database_new.execute(sql_command)

                database_new.execute(
                    f"DELETE FROM channels WHERE ChannelID is NULL")

            database_new.commit()
Esempio n. 5
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)