mirror of
https://git.checksum.fail/alec/uriel.git
synced 2026-05-26 13:27:39 +00:00
Add custom styles and experimental (horrifying, glitchy, mostly non-working) WebM support.
This commit is contained in:
@@ -2,18 +2,117 @@
|
||||
#define URIEL_NAVBACK 0x11
|
||||
#define URIEL_NAVFWD 0x12
|
||||
#define URIEL_THUMB 0x13
|
||||
#define URIEL_WEBM 0x14
|
||||
|
||||
#define URIEL_DL_PATH "::/Home/Downloads/"
|
||||
#define URIEL_THUMB_BMP "/Tmp/UrielThumb.bmp"
|
||||
#define URIEL_VERSION "Uriel/0.2"
|
||||
|
||||
Bool URIEL_INSTANCE=FALSE;
|
||||
CDC *URIEL_WEBM_DC;
|
||||
CFileBMP *URIEL_WEBM_BITMAP;
|
||||
U8 URIEL_USER_AGENT[64];
|
||||
U8 URIEL_WEBM_FRAME[5000];
|
||||
U8 *URIEL_WEBM_PTR;
|
||||
StrCpy(URIEL_USER_AGENT, URIEL_VERSION);
|
||||
StrCpy(URIEL_USER_AGENT+StrLen(URIEL_USER_AGENT), " (");
|
||||
StrCpy(URIEL_USER_AGENT+StrLen(URIEL_USER_AGENT), Define("DD_OS_NAME_VERSION"));
|
||||
StrCpy(URIEL_USER_AGENT+StrLen(URIEL_USER_AGENT), ")");
|
||||
|
||||
U0 U_ZeroWebMFrameBuf()
|
||||
{
|
||||
I64 z=0;
|
||||
while (z<5000) {
|
||||
URIEL_WEBM_FRAME[z] = 0x0;
|
||||
z++;
|
||||
};
|
||||
}
|
||||
|
||||
public CDC *U_WebMFrame(Bool dither_probability=FALSE,
|
||||
Bool use_ms_paint_palette=FALSE)
|
||||
{
|
||||
I64 i,j,cnt;
|
||||
U8 *palette_map;
|
||||
Bool rle;
|
||||
CDC *res=NULL;
|
||||
URIEL_WEBM_PTR=URIEL_WEBM_FRAME;
|
||||
URIEL_WEBM_BITMAP=URIEL_WEBM_PTR;
|
||||
if (0<URIEL_WEBM_BITMAP->width<I32_MAX && 0<URIEL_WEBM_BITMAP->height<I32_MAX) {
|
||||
res=DCNew(URIEL_WEBM_BITMAP->width,URIEL_WEBM_BITMAP->height);
|
||||
URIEL_WEBM_PTR+=URIEL_WEBM_BITMAP->data_offset;
|
||||
if (URIEL_WEBM_BITMAP->compression==2)
|
||||
rle=TRUE;
|
||||
else
|
||||
rle=FALSE;
|
||||
if (use_ms_paint_palette)
|
||||
palette_map=ms_paint_palette;
|
||||
else
|
||||
palette_map=BMPPaletteNew(URIEL_WEBM_BITMAP);
|
||||
if (URIEL_WEBM_BITMAP->bit_cnt==4) {
|
||||
for (i=URIEL_WEBM_BITMAP->height-1;i>=0;i--)
|
||||
if (rle) {//We don't support full RLE4, just our own subset
|
||||
j=0;
|
||||
while (cnt=*URIEL_WEBM_PTR++) {
|
||||
if (cnt==1) {
|
||||
res->color=palette_map[*URIEL_WEBM_PTR++&15];
|
||||
GrPlot(res,j++,i);
|
||||
} else {
|
||||
if (cnt==2 && *URIEL_WEBM_PTR>>4!=*URIEL_WEBM_PTR&15) {
|
||||
res->color=palette_map[*URIEL_WEBM_PTR&15];
|
||||
GrPlot(res,j+1,i);
|
||||
res->color=palette_map[*URIEL_WEBM_PTR>>4];
|
||||
GrPlot(res,j,i);
|
||||
URIEL_WEBM_PTR++;
|
||||
j+=2;
|
||||
} else {
|
||||
res->color=palette_map[*URIEL_WEBM_PTR++&15];
|
||||
while (cnt--)
|
||||
GrPlot(res,j++,i);
|
||||
}
|
||||
}
|
||||
}
|
||||
URIEL_WEBM_PTR++;
|
||||
} else
|
||||
for (j=0;j<(URIEL_WEBM_BITMAP->width+7)&~7;) {
|
||||
res->color=palette_map[*URIEL_WEBM_PTR&15];
|
||||
GrPlot(res,j+1,i);
|
||||
res->color=palette_map[*URIEL_WEBM_PTR>>4];
|
||||
GrPlot(res,j,i);
|
||||
URIEL_WEBM_PTR++;
|
||||
j+=2;
|
||||
}
|
||||
if (!use_ms_paint_palette)
|
||||
Free(palette_map);
|
||||
} else if (URIEL_WEBM_BITMAP->bit_cnt==24) {
|
||||
for (i=URIEL_WEBM_BITMAP->height-1;i>=0;i--) {
|
||||
for (j=0;j<URIEL_WEBM_BITMAP->width;j++,URIEL_WEBM_PTR+=3) {
|
||||
res->color=BMP24Color(URIEL_WEBM_PTR,dither_probability);
|
||||
GrPlot(res,j,i);
|
||||
}
|
||||
URIEL_WEBM_PTR+=URIEL_WEBM_BITMAP->width&3;
|
||||
}
|
||||
if (!use_ms_paint_palette)
|
||||
Free(palette_map);
|
||||
} else if (URIEL_WEBM_BITMAP->bit_cnt>=32) {
|
||||
for (i=URIEL_WEBM_BITMAP->height-1;i>=0;i--)
|
||||
for (j=0;j<URIEL_WEBM_BITMAP->width;j++,URIEL_WEBM_PTR+=4) {
|
||||
res->color=BMP24Color(URIEL_WEBM_PTR,dither_probability);
|
||||
GrPlot(res,j,i);
|
||||
}
|
||||
if (!use_ms_paint_palette)
|
||||
Free(palette_map);
|
||||
} else {
|
||||
"Format Not Supported.\n";
|
||||
DCDel(res);
|
||||
res=NULL;
|
||||
}
|
||||
} else {
|
||||
DCDel(res);
|
||||
res=NULL;
|
||||
};
|
||||
return res;
|
||||
}
|
||||
|
||||
U0 U_CloseBrowser()
|
||||
{
|
||||
Bool close=FALSE;
|
||||
@@ -51,6 +150,46 @@ U0 U_InsertThumb(U8 *anchor, U8 *indent, U8 *outdent, U8 *url)
|
||||
DocAnchorFind(DocPut,anchor);
|
||||
}
|
||||
|
||||
U0 U_PlayWebM(U8 *anchor, U8 *url)
|
||||
{
|
||||
DCFill;
|
||||
DocAnchorFind(DocPut,anchor);
|
||||
I64 webm_x = ms.pos.x;
|
||||
I64 webm_y = ms.pos.y;
|
||||
I64 frame=0;
|
||||
I64 mframes,size;
|
||||
ZeroParamBuf;
|
||||
StrCpy(HGBD_PARAM_BUF,URIEL_USER_AGENT);
|
||||
WriteParamBuf;
|
||||
BlkWrite(HGBD,url,1,(StrLen(url)/BLK_SIZE)+1);
|
||||
HGExec(URIEL_WEBM);
|
||||
ReadParamBuf;
|
||||
size = Str2I64(HGBD_PARAM_BUF);
|
||||
if (size<1) {
|
||||
PopUpOk("Error loading WebM.");
|
||||
return;
|
||||
};
|
||||
mframes = Str2I64(HGBD_PARAM_BUF+128);
|
||||
if (mframes<1) {
|
||||
PopUpOk("Error loading WebM.");
|
||||
return;
|
||||
};
|
||||
BlkRead(HGBD,HGFS_BUF,1,(size/BLK_SIZE)+1);
|
||||
DocAnchorFind(DocPut,anchor);
|
||||
while (!ScanKey) {
|
||||
U_ZeroWebMFrameBuf;
|
||||
MemCpy(URIEL_WEBM_FRAME, HGFS_BUF+(frame*(size/mframes)), (size/mframes));
|
||||
URIEL_WEBM_DC = U_WebMFrame;
|
||||
GrBlot(,webm_x,webm_y,URIEL_WEBM_DC);
|
||||
if (URIEL_WEBM_DC==NULL) { frame=0; };
|
||||
DCDel(URIEL_WEBM_DC);
|
||||
Sleep(30);
|
||||
frame++;
|
||||
if (frame>(mframes-1)) { frame=0; };
|
||||
};
|
||||
DCFill;
|
||||
}
|
||||
|
||||
U0 U_Browser(U8 *url)
|
||||
{
|
||||
Bool savefile=FALSE;
|
||||
@@ -126,7 +265,6 @@ U0 U_Browser(U8 *url)
|
||||
U0 U_HistNav(I64 index)
|
||||
{
|
||||
I64 size;
|
||||
U8 *cmd;
|
||||
ZeroParamBuf;
|
||||
if (index==0) { HGExec(URIEL_NAVBACK); };
|
||||
if (index==1) { HGExec(URIEL_NAVFWD); };
|
||||
|
||||
@@ -6,6 +6,7 @@ URIEL_NAVBACK = 0x11
|
||||
URIEL_NAVFWD = 0x12
|
||||
URIEL_STR_SIZE = 144
|
||||
URIEL_THUMB = 0x13
|
||||
URIEL_WEBM = 0x14
|
||||
|
||||
class Uriel:
|
||||
download_buffer = ''
|
||||
@@ -26,6 +27,8 @@ def uriel(data):
|
||||
UrielNavFwd()
|
||||
if data == URIEL_THUMB:
|
||||
UrielThumb()
|
||||
if data == URIEL_WEBM:
|
||||
UrielWebM()
|
||||
|
||||
def UrielGetPage():
|
||||
global Uriel
|
||||
@@ -332,6 +335,86 @@ def UrielThumb():
|
||||
logger.error("[Uriel] error reading url " + url)
|
||||
conn.send(chr(URIEL_THUMB))
|
||||
|
||||
def UrielWebM():
|
||||
global Uriel
|
||||
os.lseek(HGBD,0,os.SEEK_SET)
|
||||
HGBD_PARAM_BUF = os.read(HGBD,BLK_SIZE)
|
||||
os.lseek(HGBD,BLK_SIZE,os.SEEK_SET)
|
||||
HGBD_URL_BUF = os.read(HGBD,BLK_SIZE*4)
|
||||
if Uriel.user_agent == '':
|
||||
Uriel.user_agent = HGBD_PARAM_BUF[:HGBD_PARAM_BUF.find('\x00')]
|
||||
url_comp = urlparse.urlparse(HGBD_URL_BUF[:HGBD_URL_BUF.find('\x00')])
|
||||
scheme = ''
|
||||
netloc = ''
|
||||
path = ''
|
||||
if url_comp.scheme == '':
|
||||
scheme = Uriel.rel.scheme
|
||||
else:
|
||||
scheme = url_comp.scheme
|
||||
if url_comp.netloc == '':
|
||||
netloc = Uriel.rel.netloc
|
||||
else:
|
||||
netloc = url_comp.netloc
|
||||
|
||||
if url_comp.path != '':
|
||||
if url_comp.path.find('/') != -1:
|
||||
if url_comp.scheme == '' or url_comp.netloc == '':
|
||||
if url_comp.path[:1] != '/':
|
||||
path = Uriel.rel.path + url_comp.path
|
||||
Uriel.rel.path += url_comp.path[:url_comp.path.rfind('/')+1]
|
||||
else:
|
||||
path = url_comp.path
|
||||
Uriel.rel.path = url_comp.path[:url_comp.path.rfind('/')+1]
|
||||
else:
|
||||
path = url_comp.path
|
||||
Uriel.rel.path = url_comp.path[:url_comp.path.rfind('/')+1]
|
||||
else:
|
||||
path = Uriel.rel.path + url_comp.path
|
||||
|
||||
post_scheme = netloc + "/" + urllib.quote(path)
|
||||
post_scheme = post_scheme.replace('//','/')
|
||||
if url_comp.query != '':
|
||||
post_scheme += '?'+url_comp.query
|
||||
url = scheme + "://" + post_scheme
|
||||
|
||||
tmp_webm_path = '/tmp/' + str(uuid.uuid4()) + '/'
|
||||
while os.path.exists(tmp_webm_path):
|
||||
tmp_webm_path = '/tmp/' + str(uuid.uuid4()) + '/'
|
||||
os.mkdir(tmp_webm_path)
|
||||
os.system('cd "' + tmp_webm_path + '"; wget -q -O - -U "' + Uriel.user_agent + '" "' + url + '" 2>/dev/null | ffmpeg -i - %04d.jpg -hide_banner')
|
||||
for t in glob.glob(tmp_webm_path + '*.jpg'):
|
||||
os.system('gm convert -resize 100x100 "' + t + '" -colors 16 "' + t.replace('jpg','bmp') + '"')
|
||||
os.remove(t)
|
||||
webm_frames = 0
|
||||
for webm_frame in sorted(glob.glob(tmp_webm_path+'*.bmp')):
|
||||
webm_frames += 1
|
||||
os.system('cd "' + tmp_webm_path + '"; cat ' + webm_frame + ' >> output.bin')
|
||||
|
||||
filedata = open(tmp_webm_path+'output.bin',"rb").read()
|
||||
try:
|
||||
os.remove(tmp_webm_path+'output.bin')
|
||||
except:
|
||||
pass
|
||||
if len(tmp_webm_path)>0:
|
||||
os.system('rm -rf "' + tmp_webm_path + '"')
|
||||
filesize = len(filedata)
|
||||
if filesize>0:
|
||||
ZeroParamBuf()
|
||||
os.lseek(HGBD,0,os.SEEK_SET)
|
||||
os.write(HGBD,str(filesize))
|
||||
os.lseek(HGBD,128,os.SEEK_SET)
|
||||
os.write(HGBD,str(webm_frames))
|
||||
os.lseek(HGBD,BLK_SIZE,os.SEEK_SET)
|
||||
os.write(HGBD,filedata)
|
||||
logger.info("[Uriel] get WebM " + url)
|
||||
else:
|
||||
filesize = -1
|
||||
ZeroParamBuf()
|
||||
os.lseek(HGBD,0,os.SEEK_SET)
|
||||
os.write(HGBD,str(filesize))
|
||||
logger.error("[Uriel] error reading url " + url)
|
||||
conn.send(chr(URIEL_WEBM))
|
||||
|
||||
def UrielPreProcess(htm1, l_url):
|
||||
title_text = ''
|
||||
hb_header = '$WW,1$$BLACK$$MA+LIS,"[Close]",LM="U_CloseBrowser;"$ $MA+LIS,"[Back]",LM="U_HistNav(0);"$ $MA+LIS,"[Fwd]",LM="U_HistNav(1);"$ $MA+LIS,"[Go]",LM="U_Browser(GetStr(\\"\nURL> \\"));"$ ' + title_text + '\n\n'
|
||||
@@ -411,6 +494,9 @@ def UrielPreProcess(htm1, l_url):
|
||||
if img_pos > 0:
|
||||
img_src = img_text[img_text.upper().find('SRC'):].split('"')[1]
|
||||
img_el = '[URIEL_IMG]' + img_src + '[/URIEL_IMG]'
|
||||
# Experimental WebM tags
|
||||
if html.lower().find(img_src.lower()[:img_src.lower().rfind('.')-1]+'.webm') != -1:
|
||||
img_el = '[URIEL_WEBM]' + img_src[:img_src.rfind('.')-1] + '.webm' + '[/URIEL_WEBM]'
|
||||
html = html[:a_pos] + img_el + html[1+html.upper().find('>', a_pos):]
|
||||
a_pos = html.upper().find('<IMG ')
|
||||
|
||||
@@ -508,6 +594,14 @@ def UrielPreProcess(htm1, l_url):
|
||||
html = html[:html.find('[URIEL_IMG]')] + img_ma + html[12+html.find('[/URIEL_IMG]'):]
|
||||
img_a_ctr += 1
|
||||
|
||||
# WebM links
|
||||
webm_a_ctr = 0
|
||||
while html.find('[URIEL_WEBM]') != -1:
|
||||
webm_url = html[12+html.find('[URIEL_WEBM]'):html.find('[/URIEL_WEBM]')]
|
||||
webm_ma = '[WebM]",LM="U_PlayWebM(\\"WEBM' + str(webm_a_ctr) + '\\",\\"' + webm_url + '\\");"$$AN,"",A="WEBM' + str(webm_a_ctr) + '"$$MA+LIS,"'
|
||||
html = html[:html.find('[URIEL_WEBM]')] + webm_ma + html[13+html.find('[/URIEL_WEBM]'):]
|
||||
webm_a_ctr += 1
|
||||
|
||||
hb_header = '$WW,1$$BLACK$$MA+LIS,"[Close]",LM="U_CloseBrowser;"$ $MA+LIS,"[Back]",LM="U_HistNav(0);"$ $MA+LIS,"[Fwd]",LM="U_HistNav(1);"$ $MA+LIS,"[Go]",LM="U_Browser(GetStr(\\"URL> \\"));"$ ' + title_text + '\n\n'
|
||||
|
||||
ind_id = ''
|
||||
@@ -536,4 +630,20 @@ def UrielPreProcess(htm1, l_url):
|
||||
line = line.replace('$IMIE$','')
|
||||
o_html += line + '\n'
|
||||
|
||||
# Unicode fixes
|
||||
o_html = o_html.replace('\xE2\x80\xA2','\xF9')
|
||||
o_html = o_html.replace('\xC2\xA0',' ')
|
||||
|
||||
# Custom styles
|
||||
# (eventually, I will add minimal CSS support)
|
||||
|
||||
if l_url.lower().find('4chan.org') != -1:
|
||||
c_html = ''
|
||||
for line in o_html.split('\n'):
|
||||
if line.strip()[:1] == '>' and line.strip()[:2] != '>>':
|
||||
c_html += '$GREEN$' + line + '$BLACK$\n'
|
||||
else:
|
||||
c_html += line + '\n'
|
||||
return hb_header + c_html
|
||||
|
||||
return hb_header + o_html
|
||||
|
||||
Reference in New Issue
Block a user