def print_pre_intro(): try: middle_height, middle_width = ss.window_res(screen) screen.border() # Y componet offset for players X ussed in percent_print array y_offset = 11 j = 4 x = 0 screen.addstr(middle_height-8,middle_width-35, " __ __ _ _____ _____ _ ", curses.A_BOLD) screen.addstr(middle_height-7,middle_width-35, "/ / /\ \ \___| | ___ ___ _ __ ___ ___ /__ \___ /__ \ |__ ___ ", curses.A_BOLD) screen.addstr(middle_height-6,middle_width-35, "\ \/ \/ / _ \ |/ __/ _ \| '_ ` _ \ / _ \ / /\/ _ \ / /\/ '_ \ / _ \\", curses.A_BOLD) screen.addstr(middle_height-5,middle_width-35, " \ /\ / __/ | (_| (_) | | | | | | __/ / / | (_) | / / | | | | __/ ", curses.A_BOLD) screen.addstr(middle_height-4,middle_width-35, " \/ \/ \___|_|\___\___/|_| |_| |_|\___| \/ \___/ \/ |_| |_|\___| ", curses.A_BOLD) screen.addstr(middle_height-3,middle_width-45," _ ___ ___ _ _ ",curses.A_BOLD) screen.addstr(middle_height-2,middle_width-45," /\ /\___ | |_ / \___ __ _ / \_____ ___ __ | | ___ __ _ __| | ___ _ __ ",curses.A_BOLD) screen.addstr(middle_height-1,middle_width-45," / /_/ / _ \| __| / /\ / _ \ / _` | / /\ / _ \ \ /\ / / '_ \| |/ _ \ / _` |/ _` |/ _ \ '__| ",curses.A_BOLD) screen.addstr(middle_height,middle_width-45, "/ __ / (_) | |_ / /_// (_) | (_| | / /_// (_) \ V V /| | | | | (_) | (_| | (_| | __/ | ",curses.A_BOLD) screen.addstr(middle_height+1,middle_width-45,"\/ /_/ \___/ \__| /___,' \___/ \__, | /___,' \___/ \_/\_/ |_| |_|_|\___/ \__,_|\__,_|\___|_| ",curses.A_BOLD) screen.addstr(middle_height+2,middle_width-45," |___/ ", curses.A_BOLD) # Determining the file sizes for the stats page #temp = Downloader() #for i in range(0, 5, 1): # temp.get_size_runtime(dis.url_array[i]) # Audio File for welcome screen with open(os.devnull, 'wb') as devnull: subprocess.Popen(['aplay', dis.file_directory + 'welcome.wav'], stdout=devnull, stderr=subprocess.STDOUT) screen.refresh() except KeyboardInterrupt: curses.endwin() sys.exit("Keyboard, Interrupt Quitting...") screen.clear() try: # Determining the file sizes for the stats page temp = Downloader() for i in range(0, 5, 1): temp.get_size_runtime(dis.url_array[i]) # Determining he latancy to the host k = 0 for p in dis.players_array: p.server, directories = p.parse_server_info(str(dis.url_array[k])) p.determine_latancy() k += 1 except KeyboardInterrupt: curses.endwin() sys.exit("Keyboard Interupt Quitting...")
def print_hotdog(): with open(os.devnull, 'wb') as devnull: subprocess.Popen(['aplay', dis.file_directory + 'countdown.wav'], stdout=devnull, stderr=subprocess.STDOUT) try: for k in range(3,0,-1): count = 0 while(count != 12): middle_height, middle_width = ss.window_res(screen) screen.clear() screen.border() screen.addstr(middle_height - 4, middle_width - 22 , '(>0.0)> -_-_COUNTDOWN HYPE_-_- <(0.0<)', curses.color_pair(yellow_background)) screen.addch(middle_height-2, middle_width - 1, str(k) , curses.color_pair(yellow_background)) screen.addstr(middle_height,middle_width-40+19, ',,,,,,,,,,,,' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+1, middle_width-40+15, '..,,,,,,,,,,,,,,,......' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+2, middle_width-40+13, '.........,,,,,,,*******,,,,,,,,...' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+2, middle_width-40+11, '.,,,,,,...' ,curses.color_pair(red)) screen.addstr(middle_height+3, middle_width-40+32, '.....,,,************,,,,,...' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+3, middle_width-40+9, '.*/(((((((((//*,,..... ' ,curses.color_pair(red)) screen.addstr(middle_height+4, middle_width-40+37, '.......,,,**********,,,,...' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+4, middle_width-40+8, '.,**//((((((((((((((((//**,,.' ,curses.color_pair(red)) screen.addstr(middle_height+5, middle_width-40+8, '.....,,**///((((((((((((((###(((/*,,.' ,curses.color_pair(red)) screen.addstr(middle_height+5, middle_width-40+45, '.....,,*********,,,...' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+6, middle_width-40+53, '..,,**///**,,,..' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+6, middle_width-40+8, '.,,,,.......,,***///(((((((((((((#(((((//*,,.' ,curses.color_pair(red)) screen.addstr(middle_height+7, middle_width-40+12, '****,,,.........,,**//((((((((((((((#####(//*,,,*' ,curses.color_pair(red)) screen.addstr(middle_height+7, middle_width-40+10, '.,' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+7, middle_width-40+61, '*//**,,..' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+8, middle_width-40+63, '***,,,.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+8, middle_width-40+15, '*********,,,,......,,***///((((((((##########(/*' ,curses.color_pair(red)) screen.addstr(middle_height+8, middle_width-40+11, '..,,' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+9, middle_width-40+19, '***/////******,,,,,....,,**//((((###########(/*,..' ,curses.color_pair(red)) screen.addstr(middle_height+9, middle_width-40+66, ',..' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+9, middle_width-40+13, '...,,*' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+10, middle_width-40+66, '.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+10, middle_width-40+26, '*****//////****,,,,,,,,***//((######(((*' ,curses.color_pair(red)) screen.addstr(middle_height+10, middle_width-40+16, '.....,,***' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+11, middle_width-40+34, '****///////*****,,***/(((#####(/.' ,curses.color_pair(red)) screen.addstr(middle_height+11, middle_width-40+21, '....,,,,,,****.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+12, middle_width-40+39, '***///////////////(((####(*.' ,curses.color_pair(red)) screen.addstr(middle_height+12, middle_width-40+26, '.....,,,,,***' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+13, middle_width-40+45, '****///(((//(((###(*.' ,curses.color_pair(red)) screen.addstr(middle_height+13, middle_width-40+66, '.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+13, middle_width-40+32, '....,,,,*****' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+14, middle_width-40+36, '........,,,***,***//' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+14, middle_width-40+54, '///*****,' ,curses.color_pair(red)) screen.addstr(middle_height+14, middle_width-40+63, ',.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+15, middle_width-40+39, '.....,,,,,,,****/***,,,,,.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+16, middle_width-40+44, '....,,,,,********,.' ,curses.color_pair(yellow_text)) screen.refresh() time.sleep(.1) count += 1 count1 = 0 while(count1 != 12): middle_height, middle_width = ss.window_res(screen) screen.clear() screen.border() screen.addstr(middle_height - 4, middle_width - 22 , '(>0.0)> -_-_COUNTDOWN HYPE_-_- <(0.0<)', curses.color_pair(yellow_background)) screen.addstr(middle_height -2, middle_width - 2, 'GO!', curses.color_pair(yellow_background)) screen.addstr(middle_height,middle_width-40+19, ',,,,,,,,,,,,' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+1, middle_width-40+15, '..,,,,,,,,,,,,,,,......' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+2, middle_width-40+13, '.........,,,,,,,*******,,,,,,,,...' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+2, middle_width-40+11, '.,,,,,,...' ,curses.color_pair(red)) screen.addstr(middle_height+3, middle_width-40+32, '.....,,,************,,,,,...' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+3, middle_width-40+9, '.*/(((((((((//*,,..... ' ,curses.color_pair(red)) screen.addstr(middle_height+4, middle_width-40+37, '.......,,,**********,,,,...' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+4, middle_width-40+8, '.,**//((((((((((((((((//**,,.' ,curses.color_pair(red)) screen.addstr(middle_height+5, middle_width-40+8, '.....,,**///((((((((((((((###(((/*,,.' ,curses.color_pair(red)) screen.addstr(middle_height+5, middle_width-40+45, '.....,,*********,,,...' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+6, middle_width-40+53, '..,,**///**,,,..' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+6, middle_width-40+8, '.,,,,.......,,***///(((((((((((((#(((((//*,,.' ,curses.color_pair(red)) screen.addstr(middle_height+7, middle_width-40+12, '****,,,.........,,**//((((((((((((((#####(//*,,,*' ,curses.color_pair(red)) screen.addstr(middle_height+7, middle_width-40+10, '.,' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+7, middle_width-40+61, '*//**,,..' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+8, middle_width-40+63, '***,,,.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+8, middle_width-40+15, '*********,,,,......,,***///((((((((##########(/*' ,curses.color_pair(red)) screen.addstr(middle_height+8, middle_width-40+11, '..,,' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+9, middle_width-40+19, '***/////******,,,,,....,,**//((((###########(/*,..' ,curses.color_pair(red)) screen.addstr(middle_height+9, middle_width-40+66, ',..' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+9, middle_width-40+13, '...,,*' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+10, middle_width-40+66, '.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+10, middle_width-40+26, '*****//////****,,,,,,,,***//((######(((*' ,curses.color_pair(red)) screen.addstr(middle_height+10, middle_width-40+16, '.....,,***' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+11, middle_width-40+34, '****///////*****,,***/(((#####(/.' ,curses.color_pair(red)) screen.addstr(middle_height+11, middle_width-40+21, '....,,,,,,****.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+12, middle_width-40+39, '***///////////////(((####(*.' ,curses.color_pair(red)) screen.addstr(middle_height+12, middle_width-40+26, '.....,,,,,***' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+13, middle_width-40+45, '****///(((//(((###(*.' ,curses.color_pair(red)) screen.addstr(middle_height+13, middle_width-40+66, '.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+13, middle_width-40+32, '....,,,,*****' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+14, middle_width-40+36, '........,,,***,***//' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+14, middle_width-40+54, '///*****,' ,curses.color_pair(red)) screen.addstr(middle_height+14, middle_width-40+63, ',.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+15, middle_width-40+39, '.....,,,,,,,****/***,,,,,.' ,curses.color_pair(yellow_text)) screen.addstr(middle_height+16, middle_width-40+44, '....,,,,,********,.' ,curses.color_pair(yellow_text)) screen.refresh() time.sleep(.1) count1 += 1 screen.clear() except KeyboardInterrupt: curses.endwin() sys.exit("Keyboard Interrupt, Quitting...") '''
import curses import screen_setup as ss import sys import os import time import subprocess import distro_obj as dis from downloader_class import Downloader import downloader_class as dc from subprocess import DEVNULL, STDOUT, run, Popen screen, red, yellow_background, blue, default, yellow_text, cyan_dots = ss.curses_setup() window_height, window_width = ss.window_res(screen) def odds_screen(): # Audio File for welcome screen "smash themed sound effects" with open(os.devnull, 'wb') as devnull: subprocess.Popen(['aplay', dis.file_directory + 'smash.wav'], stdout=devnull, stderr=subprocess.STDOUT) # Printing PLayer info while True: try: middle_height, middle_width = ss.window_res(screen) screen.addstr(5,middle_width - 10, "*press space to start*") screen.addstr(3,middle_width - 8, "Odds Display Page", curses.A_UNDERLINE) screen.border() # Y componet offset for players X ussed in percent_print array y_offset = 5 j = 4
def odds_screen(): # Audio File for welcome screen "smash themed sound effects" with open(os.devnull, 'wb') as devnull: subprocess.Popen(['aplay', dis.file_directory + 'smash.wav'], stdout=devnull, stderr=subprocess.STDOUT) # Printing PLayer info while True: try: middle_height, middle_width = ss.window_res(screen) screen.addstr(5,middle_width - 10, "*press space to start*") screen.addstr(3,middle_width - 8, "Odds Display Page", curses.A_UNDERLINE) screen.border() # Y componet offset for players X ussed in percent_print array y_offset = 5 j = 4 x = 0 for p in dis.players_array: # Displaying the OS being downloaded for player screen.addstr(y_offset+4, 13, "Player"+str(x+1)+" |::| OS:", curses.A_BOLD) screen.addstr(y_offset+4, 26, str(dis.url_array_random_os[x]), curses.color_pair(cyan_dots)) screen.addstr(y_offset+10, 10, "-"*(window_width*2-20)) # Displaying File Name screen.addstr(y_offset+4, 45, "| File: ", curses.A_BOLD) screen.addstr(y_offset+4, 53, str(dis.five_files[x]),curses.color_pair(default)) # Displaying URL screen.addstr(y_offset+8, 24, '| URL:') screen.addstr(y_offset+8, 30, str(dis.url_array[x])) # Displaying Latency screen.addch(y_offset+6, 24, '|',curses.A_BOLD) screen.addstr(y_offset+6, 26, 'Latency: ',curses.A_BOLD) screen.addstr(y_offset+6, 35, p.latency + ' ms',curses.A_STANDOUT) # Displaying File Size screen.addstr(y_offset+6, 45, '| File Size: ', curses.A_BOLD) screen.addstr(y_offset+6, 58, '~ ' + dc.file_size_run[x] +' Mbs', curses.color_pair(cyan_dots)) # Offesting the next racer in y-direction and updating x for player percent_print array y_offset += 8 x += 1 # Space to continue to next screen key = screen.getkey() if(key == ' '): with open(os.devnull, 'wb') as devnull: subprocess.Popen(['aplay', dis.file_directory + 'smash-effect.wav'], stdout=devnull, stderr=subprocess.STDOUT) time.sleep(1.5) break screen.clear() screen.refresh() time.sleep(.1) except KeyboardInterrupt: curses.endwin() sys.exit("Keyboard, Interrupt Quitting...")
def func(): players, threads = player_setup() dis.players_array = players # Print to screen pre intro hd.print_pre_intro() # Odds screen display to terminal hd.odds_screen() #initial screen with countdown hd.print_hotdog() # Starting the array of threads for thread in threads: thread.start() # Setting color for the race window screen.bkgd(curses.color_pair(default)) try: finish_flag = False ranking_x_offset = 24 max_download_speed = 0 split_timer = time.time() start_time = time.time() while (True): # Setting middle_width and height middle_height, middle_width = ss.window_res(screen) # Getting window size window_height, window_width = screen.getmaxyx() # Clearing each for each new frame of print screen.clear() # Displaying border screen.border() percent_print = [] for p in players: percent_print.append( int((window_width - 23) * p.data_length / p.total_length)) # Determing peak_download and highest overall peak_download for p in players: p.peak_download = (p.chunk_rate / 1024 / 1024) if p.peak_download > max_download_speed: max_download_speed = p.peak_download # Displaying overall peak download to screen screen.addstr(46, 13, "| Overall Peak Download Rate Recorded: ", curses.color_pair(blue)) screen.addstr(46, 52, "%.3f MBs" % (max_download_speed), curses.color_pair(yellow_text)) # Title for the race window screen.addstr(1, middle_width - 13, '========================', curses.color_pair(yellow_text)) screen.addstr(2, middle_width - 14, '(-- Hot Dog Downloader --)', curses.color_pair(red)) screen.addstr(3, middle_width - 13, '========================', curses.color_pair(yellow_text)) screen.addstr(1, middle_width + 23, '======================', curses.color_pair(yellow_text)) screen.addstr(2, middle_width + 22, '(- LIVE RANKINGS BOII -)', curses.color_pair(red)) screen.addstr(3, middle_width + 23, '======================', curses.color_pair(yellow_text)) screen.addstr(3, middle_width + 48, 'MIN|SEC|MS', curses.A_UNDERLINE) screen.addstr(4, middle_width + ranking_x_offset, '1st Place ::', curses.A_BOLD) screen.addstr(5, middle_width + ranking_x_offset, '2nd Place ::', curses.A_BOLD) screen.addstr(6, middle_width + ranking_x_offset, '3rd Place ::', curses.A_BOLD) screen.addstr(7, middle_width + ranking_x_offset, 'Hard Rip ::', curses.A_BOLD) screen.addstr(8, middle_width + ranking_x_offset, 'Mega Rip ::', curses.A_BOLD) # Y componet offset for players X ussed in percent_print array y_offset = 11 j = 4 x = 0 for p in players: # Displaying the OS being downloaded for player screen.addstr(y_offset + 4, 13, "| OS: ", curses.COLOR_WHITE) screen.addstr(y_offset + 4, 20, str(dis.url_array_random_os[x]), curses.A_BOLD) # Displaying File Name screen.addstr(y_offset + 4, 33, "| File: ", curses.COLOR_WHITE) screen.addstr(y_offset + 4, 41, str(dis.five_files[x]), curses.A_BOLD) # Displaying size of file being downloaded screen.addstr(y_offset + 4, 89, "| Size: ", curses.color_pair(red)) screen.addstr( y_offset + 4, 98, str(round(p.total_length / 1024 / 1024, 2)) + ' MB', curses.color_pair(blue)) # Displaying the player, rate, percent downloaded and start/finish animation screen.addstr(y_offset, 2, "Player" + str(x + 1) + " ::", curses.color_pair(cyan_dots)) screen.addstr( y_offset, 13, "| Rate: %.3f MBs" % (round(p.chunk_rate / 1024 / 1024, 3))) screen.addstr( y_offset, 33, "| Percent Downloaded: %s%%" % (p.get_percent_done())) screen.addstr( y_offset + 5, 2, "start |%s:]%s| finish!" % ('-' * percent_print[x], ' ' * (window_width - 23 - percent_print[x])), curses.color_pair(yellow_text)) # Displaying the peak download if (p.chunk_rate > p.peak_download_high): p.peak_download_high = p.chunk_rate screen.addstr(y_offset + 2, 13, "| Peak Download Rate Recorded:", curses.color_pair(blue)) screen.addstr( y_offset + 2, 43, " %.3f MBs" % (p.peak_download_high / 1024 / 1024), curses.color_pair(yellow_text)) # If done hen print static image for load animation but can still be resized if (p.get_percent_done() == 100): screen.addstr(y_offset, 20, " 0.000", curses.color_pair(red)) screen.addstr( y_offset + 5, 2, "start |%s:]%s| finish!" % ('-' * percent_print[x], ' ' * (window_width - 22 - percent_print[x])), curses.color_pair(yellow_text)) j += 1 p.done_flag = True # Display overall average download when done if (p.done_flag == True and p.get_percent_done() == 100): if (finish_flag == False): # playing airhorn with open(os.devnull, 'wb') as devnull: subprocess.Popen( ['aplay', dis.file_directory + 'horn.wav'], stdout=devnull, stderr=subprocess.STDOUT) finish_flag = True if (p.stop_avg_flag == False): p.time_end = time.time() p.stop_avg_flag = True p.ranking_array.append(str(x + 1)) # Displaying the finish times for the racers ms_first = round((p.time_end - start_time) * 1000, 0) dc.timing_array.append(dc.get_time(ms_first)) p.overall_average_download = round( ((p.total_length / (p.time_end - start_time)) / 1024 / 1024), 3) screen.addstr(y_offset + 2, 56, "| Overall Average Download Speed:", curses.color_pair(blue)) screen.addstr(y_offset + 2, 89, " %.3f MBs" % (p.overall_average_download), curses.color_pair(yellow_text)) screen.addstr(j - 1, middle_width + ranking_x_offset + 13, 'Player ', curses.color_pair(red)) screen.addstr(j - 1, middle_width + ranking_x_offset + 20, str(p.ranking_array[j - 5]), curses.color_pair(yellow_text)) screen.addstr(j - 1, middle_width + ranking_x_offset + 25, str(dc.timing_array[j - 5]), curses.A_BOLD) else: pass # Offesting the next racer in y-direction and updating x for player percent_print array y_offset += 7 x += 1 screen.refresh() time.sleep(.1) # If User Ctr ^C, threads will get celaned up and exit except KeyboardInterrupt: for p in players: p.run_thread = False curses.endwin() sys.exit("Keyboard Interrupt, Quitting...")