This commit is contained in:
decoded
2022-11-05 18:59:52 -05:00
parent 3a1f8e1eea
commit a3cdc80706

View File

@@ -1,9 +1,15 @@
########################################################################################### dr1p4ns1 version 2.666 ##### SOF ########################################################################################### dr1p4ns1 version 2.667 ##### SOF
#################################################################################################### ####################### #################################################################################################### #######################
import os
import shutil
import sys
import termios
import threading
import tty
from collections import namedtuple
from glob import glob from glob import glob
from time import sleep from time import sleep
from collections import namedtuple
import sys,tty,os,termios,shutil
#################################################################################################### ####################### #################################################################################################### #######################
#################################################################################################### ####################### #################################################################################################### #######################
##### #####
@@ -47,7 +53,10 @@ FIFO_PATH = f"{os.path.expanduser('~')}/.weechat/weechat_fifo"
FIFO_ENABLED = True ##### FIFO_ENABLED = True #####
COPY_PATH = f"{os.path.expanduser('~')}/Pictures" ##### COPY_PATH = f"{os.path.expanduser('~')}/Pictures" #####
DELETE_PATH = "/tmp" ##### DELETE_PATH = "/tmp" #####
FLOODRATE_INTERVAL_SECONDS = 0.335 ##### FLOODRATE_INTERVAL_SECONDS = 0.125 #####
global SHOW_FILENAME #####
SHOW_FILENAME=True #####
DR1P_VERSION="2.667 - 11/05/22 - https://git.tcp.direct/decoded/dr1p4ns1" #####
#################################################################################################### ####################### #################################################################################################### #######################
#################################################################################################### ####################### #################################################################################################### #######################
##### #####
@@ -102,7 +111,6 @@ class D:
self.delay=FLOODRATE_INTERVAL_SECONDS self.delay=FLOODRATE_INTERVAL_SECONDS
self.correct=0 self.correct=0
########################################################################################################## CLASS DR1P4NS1 - 2 ########################################################################################################## CLASS DR1P4NS1 - 2
class dr1p4ns1: class dr1p4ns1:
############################################################################################################ LOOKUP TABLE ############################################################################################################ LOOKUP TABLE
commands = { commands = {
@@ -117,7 +125,8 @@ class dr1p4ns1:
's': 'save_cursor', 's': 'save_cursor',
'u': 'restore_cursor', 'u': 'restore_cursor',
'm': 'color', 'm': 'color',
'R': 'report_cursor_position'} 'R': 'report_cursor_position',
't': 'nfi'}
############################################################################################################ LOOKUP TABLE ############################################################################################################ LOOKUP TABLE
asc_table="""\ asc_table="""\
╟ⁿΘΓΣαστΩδΦ∩ε∞─┼╔µ╞⌠÷≥√∙ ╓▄óúÑ₧ƒ\ ╟ⁿΘΓΣαστΩδΦ∩ε∞─┼╔µ╞⌠÷≥√∙ ╓▄óúÑ₧ƒ\
@@ -190,6 +199,9 @@ class dr1p4ns1:
f.close() f.close()
######################################################################################################### FILE OPERATIONS ######################################################################################################### FILE OPERATIONS
def openansi(self,s): def openansi(self,s):
f=open('log','w')
f.write(f'{s}\n')
f.close()
f=open(s,'rb') f=open(s,'rb')
self.ansifile=f.read().decode('cp437') self.ansifile=f.read().decode('cp437')
f.close() f.close()
@@ -322,6 +334,7 @@ class dr1p4ns1:
uniques=[] uniques=[]
codes=[] codes=[]
processing='' processing=''
try:
for i,_optype in enumerate(self.optype): for i,_optype in enumerate(self.optype):
if _optype==2: if _optype==2:
processing+=self.op[i] processing+=self.op[i]
@@ -380,12 +393,16 @@ class dr1p4ns1:
codes.append(__[code_start:code_end]) codes.append(__[code_start:code_end])
for code in codes: for code in codes:
for _ in code.replace('m','').split('[')[1].split(';'): for _ in code.replace('m','').split('[')[1].split(';'):
try:
if 0 <= int(_) <= 9: if 0 <= int(_) <= 9:
color_set=_ color_set=_
if 30 <= int(_) <= 39: if 30 <= int(_) <= 39:
color_fg=_ color_fg=_
if 40 <= int(_) <= 49: if 40 <= int(_) <= 49:
color_bg=_ color_bg=_
except:
print('error')
pass
colors=f"{color_set}" colors=f"{color_set}"
processed_colors.append(colors) processed_colors.append(colors)
self.processed = processed self.processed = processed
@@ -477,6 +494,8 @@ class dr1p4ns1:
_line=_line.replace(code_replace,newcode,1) _line=_line.replace(code_replace,newcode,1)
irc_processed.append(_line) irc_processed.append(_line)
terminal_processed.append(line) terminal_processed.append(line)
except Exception as e:
print(f'bp error: {e}')
#################################################################################################################### TOOL #################################################################################################################### TOOL
def getsauce(self): def getsauce(self):
f=open(self.filename,'rb') f=open(self.filename,'rb')
@@ -486,6 +505,9 @@ class dr1p4ns1:
self.sauce_found=True self.sauce_found=True
self.width=self.sauce[96] self.width=self.sauce[96]
self.height=self.sauce[98] self.height=self.sauce[98]
if self.width==0:
print("ERROR: sauce.width has 0 value, defaulting to 80 width")
self.width=80
offset=len("SAUCE") offset=len("SAUCE")
self.sauce_version=str(int(self.sauce[offset:offset+2].strip())) self.sauce_version=str(int(self.sauce[offset:offset+2].strip()))
offset+=2 offset+=2
@@ -604,6 +626,7 @@ class UI:
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
################################################################################### HUMAN INTERFACE * * * * * * * * * * * ################################################################################### HUMAN INTERFACE * * * * * * * * * * *
def uis_menu(self): def uis_menu(self):
global SHOW_FILENAME
index=0 index=0
try: try:
print(f'loading: {self.files[index]}') print(f'loading: {self.files[index]}')
@@ -616,8 +639,8 @@ class UI:
try: try:
while True: while True:
B='\x1b[1;94m'; C='\x1b[1;95m'; S='\x1b[1;36m'; M='\x1b[1;92m'; E='\x1b[0m'; R='\x1b[31m' B='\x1b[1;94m'; C='\x1b[1;95m'; S='\x1b[1;36m'; M='\x1b[1;92m'; E='\x1b[0m'; R='\x1b[31m'
msg=f"{B}[ {C}DR1P {B}] {B}- {B}[ {M}x{B}: {M}exit{B}, {M}c{B}: {M}copy{B}, {M}R{B}: {M}remove{B}, {M}q{B}: {M}pumpqueue{B}, {M}p{B}: {M}pump{B}, " msg=f"{B}[ {C}DR1P {B}] {B}- {B}[ {M}x{B}: {M}exit{B}, {M}c{B}: {M}copy{B}, {M}R{B}: {M}remove{B}, {M}f{B}: {M}show_filename{B}:{C}{SHOW_FILENAME}{B}, {M}q{B}: {M}pumpqueue{B}, {M}z{B}/{M}p{B}: {M}auto{B}/{M}pump{B}, "
msg+=f"{M}left{B}/{M}right{B}: {M}browse {B}] {B}- [ {M}d{B}: {M}delay{B} - {M}{dr1p.delay}{B} ]" msg+=f"{M}left{B}/{M}right{B}: {M}browse {B}]\n[ {M}d{B}: {M}delay{B} - {M}{dr1p.delay}{B} ] {B}- "
msg+=f"{B}[ {S}pumpqueue{B}: {C}{len(self.QUEUE)} {B}- {S}index{B}: {C}{index+1}{B}/{C}{len(self.files)} {B}- {S}filename{B}: {C}{d.filename} {B}]{E}" msg+=f"{B}[ {S}pumpqueue{B}: {C}{len(self.QUEUE)} {B}- {S}index{B}: {C}{index+1}{B}/{C}{len(self.files)} {B}- {S}filename{B}: {C}{d.filename} {B}]{E}"
if self.REMOVED==True: msg+=f'{R} - FILE REMOVED' if self.REMOVED==True: msg+=f'{R} - FILE REMOVED'
print(msg) print(msg)
@@ -680,6 +703,11 @@ class UI:
sleep(1) sleep(1)
print('\x1bc') print('\x1bc')
decoder.as_terminal() decoder.as_terminal()
elif k == 'f':
if SHOW_FILENAME:
SHOW_FILENAME=False
else:
SHOW_FILENAME=True
elif k == 'd': elif k == 'd':
while True: while True:
print(f'{C}input floodrate delay{B}: {C}',end='') print(f'{C}input floodrate delay{B}: {C}',end='')
@@ -702,7 +730,39 @@ class UI:
sleep(1) sleep(1)
print('\x1bc') print('\x1bc')
decoder.as_terminal() decoder.as_terminal()
elif k == 'z':
import random
flag_done=False
if len(self.QUEUE)==0:
self.QUEUE=self.files
print(f'{R} pumpqueue empty: autopumping from directory index')
sleep(1)
else:
print(f'{R} autopumping from pump queue')
while not flag_done:
if len(self.QUEUE) > 0:
print('\x1bc')
d=dr1p4ns1(ansifile=self.QUEUE[0][0],width=self.QUEUE[-1][1],debug=False)
decoder=ANSIDecoder(self.QUEUE[0][0],d.width)
decoder.as_terminal()
self.QUEUE.reverse()
buffer_filename, buffer_width=self.QUEUE[-1]
self.QUEUE.pop()
self.QUEUE.reverse()
decoder=ANSIDecoder(buffer_filename,buffer_width)
decoder.as_irc()
N=random.randint(5,10)
print(f'{C}SLEEPING {M}{N}{C} SECONDS BEFORE NEXT AUTOPUMP: {self.QUEUE[0][0]}')
sleep(N)
else:
flag_done=True
print(f'{B}NO FILES LEFT IN QUEUE - {R} EXITING')
sleep(1)
break
elif k == 'p': elif k == 'p':
print(f'{C}p.u.m.p.i.n.g ', end = "")
PMSG="" PMSG=""
try: try:
if FIFO_ENABLED: if FIFO_ENABLED:
@@ -767,6 +827,9 @@ class ANSIDecodeError(ValueError):
############################################################################################################################# #############################################################################################################################
class ANSIDecoder: class ANSIDecoder:
############################################################################################################################# #############################################################################################################################
#################
ESCAPE_PUMP=False
#################
PALETTES = { PALETTES = {
'vga': { 'vga': {
False: ['000', 'a00', '0a0', 'a50', '00a', 'a0a', '0aa', 'aaa'], False: ['000', 'a00', '0a0', 'a50', '00a', 'a0a', '0aa', 'aaa'],
@@ -814,9 +877,13 @@ class ANSIDecoder:
self.width = width self.width = width
self.strict = False self.strict = False
self.filename=files self.filename=files
print(self.filename)
try:
stream=open(self.filename,'rt',encoding='cp437') stream=open(self.filename,'rt',encoding='cp437')
if stream: if stream:
self.play(stream) self.play(stream)
except:
pass
######################################################################################################################### #########################################################################################################################
def write_char(self, char): def write_char(self, char):
# Handle an ordinary character # Handle an ordinary character
@@ -1161,12 +1228,36 @@ class ANSIDecoder:
self.output_lines.append(processing) self.output_lines.append(processing)
processing='' processing=''
######################################################################################################################### #########################################################################################################################
def getkeythreaded(self):
tty.setcbreak(sys.stdin.fileno())
print('\x1b[31m<<< PRESS ANY KEY TO ABORT PUMP >>>')
b = os.read(sys.stdin.fileno(), 3).decode()
if len(b) == 3:
k = ord(b[2])
else:
k = ord(b)
self.ESCAPE_PUMP=True
#########################################################################################################################
def as_irc(self): def as_irc(self):
DID_I_ABORT=False
self.output_lines=[] self.output_lines=[]
self.as_irc_lines() self.as_irc_lines()
x=threading.Thread(target=self.getkeythreaded)
x.start()
for _ in self.output_lines: for _ in self.output_lines:
self.fifo(_) self.fifo(_)
sleep(dr1p.delay) sleep(dr1p.delay)
if self.ESCAPE_PUMP:
DID_I_ABORT=True
break
if SHOW_FILENAME:
self.fifo(f"\x035FILENAME\x034: \x035{self.filename.split('/')[-1]} \x034- \x035DR1P4NS1\x034:\x035 {DR1P_VERSION}")
x._stop()
self.ESCAPE_PUMP=False
if DID_I_ABORT:
print(f'\x1b[31m<<< ABORTED PUMP >>>')
self.fifo("\x035<<< ABORTED PUMP >>>")
sleep(3)
################################################################################################### RE-ENCODING ENCODINGS ################################################################################################### RE-ENCODING ENCODINGS
def as_terminal_lines(self): def as_terminal_lines(self):
default_fg=7 default_fg=7
@@ -1232,7 +1323,13 @@ class ANSIDecoder:
processing+=f'\x1b[0;{attr[0]+30};{attr[1]+40}m' processing+=f'\x1b[0;{attr[0]+30};{attr[1]+40}m'
processing+=char processing+=char
last_attr=attr last_attr=attr
self.output_lines.append(processing + '\x1b[40;37m') if len(self.buffer[i]) == 0:
self.output_lines.append(f"{''*self.width}")
else:
distance=int(self.width)-len(line)
processing+=f"{''*distance}"
self.output_lines.append(processing)
# self.output_lines.append(processing + '\x1b[40;37m')
processing='' processing=''
######################################################################################################################### #########################################################################################################################
def as_terminal(self): def as_terminal(self):
@@ -1240,6 +1337,7 @@ class ANSIDecoder:
self.as_terminal_lines() self.as_terminal_lines()
for _ in self.output_lines: for _ in self.output_lines:
print(_) print(_)
################################################################################################################### ENTRY - 1 ################################################################################################################### ENTRY - 1
if __name__=="__main__": if __name__=="__main__":
dr1p=D() dr1p=D()
@@ -1247,4 +1345,4 @@ if __name__=="__main__":
dr1p.files = getfiles(sys.argv) dr1p.files = getfiles(sys.argv)
ui = UI(dr1p.files) ui = UI(dr1p.files)
#################################################################################################### ####################### #################################################################################################### #######################
########################################################################################### dr1p4ns1 version 2.666 ##### EOF ########################################################################################### dr1p4ns1 version 2.667 ##### EOF