Re: ai in my file player can only add 256 items to a list before crashing
Yes this is a media player. Starting from your user folder, you can browse around the folders and files on your computer. It will compile a list of folders and files, sort them, and display the results for you to browse. When you press enter on a file, it adds it to the library. You can also have the bot choose files for you. The player is going to select random files from the library to play.
Here is my search function.
import os
import time
import options as o
import globals as gb
#global variables
you=True
#whether the user or bot is controlling events
guess=False
#a guessing game
library=[]
bot_folders=[]
#a list of empty folders for the bot to ignore
bot_files=[]
#a list of files the bot has already chosen
bot_remaining_files=0
#countdown for the bot collecting random files
bot_choose=False
#used for guessing game, not relevant
location_before_bot=""
#mark the position before bot takes over, and return to this spot when it is done
def search(path, last_folder="", view_type=0):
#path, the current path to search in.
#last_folder, the last folder clicked by the user, works like file explorer returning the last position with backspace.
#view_type, whether folders or files are being displayed.
if path=="C:":
path="C:\\"
full_directory = os.listdir(path)
folders=[]
files=[]
for x in full_directory:
if os.path.isdir(path+"\\"+x)==True:
if x not in gb.bot_folders:
folders.append(x)
else:
if gb.you==True and o.options["remove empty folders"]==False:
folders.append(x)
#if you don't want to remove empty folders from being shown, add the folder
else:
if x not in gb.bot_files or (gb.you==True and o.options["hide unsupported files"]):
#don't waste time checking file extension if bot has already selected, or you don't want to remove unsupported files
ext= str_trim(x, ".", "last", "after")
if ext in formats:
files.append(x)
time.sleep(0.1)
if len(folders)==0 and len(files)==0:
gb.bot_folders.append(path)
if gb.you==True:
lucia.output.speak("This folder is empty.")
p.play_stationary("sounds/nav/back.ogg")
path, last_folder =str_trim(path, "\\", "last", "both")
#this line is fancy for trim the last folder off of the path
else:
lucia.output.speak("Bot found empty folder {path}. No Content.")
path= str_trim(path, "\\", "last", "before")
#the fancy line, but we don't change the last_folder since it is the bot
search(path, last_folder)
#search the last folder
elif len(folders)>0 and len(files)==0:
view_type=1
lucia.output.speak("folders")
elif len(folders)==0 and len(files)>0:
view_type=2
lucia.output.speak("files")
elif len(folders)>0 and len(files)>0:
if view_type==0:
#if not switching view types in the same directory
if gb.you==True:
view_type= choose_view(path, last_folder)
#let's the user choose folders or files
else:
view_type=random.randint(1,2)
lucia.output.speak(f"both {view_type}")
#the bot chooses at random
else:
#if switching to the other view type in this directory
if gb.you==True:
p.play_stationary("sounds/nav/viewchange.ogg")
view_type-=1
if view_type==0:
view_type=2
if view_type==1:
active_directory = folders.copy()
elif view_type==2:
active_directory = files.copy()
browse(path, active_directory, view_type, last_folder)
def browse(path, active_directory, view_type, last_folder="", position=-1): bot_enter=False #virtual enter key for the bot to press enter gb.bot_choose=False #used for guessing game, not important ext="" #check file extensions #if you are in control and you pressed backspace, use last_folder to return position in the list while 1: lucia.process_events() #only semicolon and enter keys are important in this sample if lucia.key_pressed(pygame.K_SEMICOLON) or gb.you==False: #the arg gb.you==False refers to the bot collecting files if gb.guess==True and bot_chose==True: lucia.output.speak("play fair, I already chose. Now it's your turn") else: #this is what we care about if gb.you==True: gb.location_before_bot= path gb.you=False #type in how many files for the bot to collect if gb.bot_remaining_files<1: gb.bot_remaining_files=1 if gb.bot_remaining_files>300: gb.bot_remaining_files=300 #we give control over to the bot position= random.randint(0, len(active_directory)-1) bot_enter=True if (lucia.key_pressed(pygame.K_RETURN) and position>-1) or bot_enter: #we will ignore folder code for this sample. If it is needed I will add it elif view_type==2: ext= str_trim(active_directory[position], ".", "last", "after") if ext in formats: selected= path+"\\"+active_directory[position] if gb.guess==False: gb.library.append(selected) #after checking extension and if guessing game is active, add file to the library if gb.you==True: lucia.output.speak("added") else: gb.bot_remaining_files-=1 if gb.bot_remaining_files==0: gb.you=True search(gb.location_before_bot, last_folder) #if bot is done collecting files, give control back and return to your last path else: if gb.bot_remaining_files%50 ==0: time.sleep(1) #after every 50 files, breathe for a second rv= random.randint(1, 3) #option 1 selects another random file from same folder #option 2 presses backspace if rv==2: path= str_trim(path, "\\", "last", "before") search(path, last_folder) #option 3 goes back to the marked location elif rv==3 or o.options["absolute randomization for bot"]: search(gb.location_before_bot, last_folder) time.sleep(0.1)
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector