From 9ee95e7a1b479731d27293a415e643e22d18369d Mon Sep 17 00:00:00 2001 From: Lionel Dricot Date: Sun, 30 Jul 2023 23:12:01 +0200 Subject: [PATCH] pictures are working --- CHANGELOG | 6 ++++++ ansirenderer.py | 17 +++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0a90d62..9ad3545 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ # Offpunk History +## 2.0 - unreleased +This is an an experimental and unstable release. Lot of breakages are expected. +Wait for 2.1 if you are not willing to do testing/bug reporting. +- New command-line tool: "netcache" +- New command-line tool: "ansirenderer" + ## 1.10 - unreleased - IMPORTANT : new optional dependency : python-chardet - IMPORTANT : Gopher directory index filename changed from "index.txt" to "gophermap". To update the cache to the new format run the `migrate-offpunk-cache` script (Sotiris Papatheodorou) diff --git a/ansirenderer.py b/ansirenderer.py index bf7dc46..22c2b92 100644 --- a/ansirenderer.py +++ b/ansirenderer.py @@ -11,6 +11,7 @@ import urllib import argparse import mimetypes import fnmatch +import netcache from offutils import run,term_width try: from readability import Document @@ -976,14 +977,12 @@ class HtmlRenderer(AbstractRenderer): if _RENDER_IMAGE and mode != "links_only" and imgurl: try: #4 followings line are there to translate the URL into cache path - #TODO: do that with netcache - g = GeminiItem(imgurl) - img = g.get_cache_path() + img = netcache.get_cache_path(imgurl) if imgdata: with open(img,"wb") as cached: cached.write(base64.b64decode(imgdata)) cached.close() - if g.is_cache_valid(): + if netcache.is_cache_valid(img): renderer = ImageRenderer(img,imgurl) # Image are 40px wide except if terminal is smaller if width > 40: @@ -1280,9 +1279,11 @@ def render(input,path=None,format="auto",mime=None,url=None): r= renderer_from_file(path,url) else: r = set_renderer(input,url,mime) - print("renderer is %s"%r) + print("DEBUG: renderer is %s"%r) if r: r.display() + else: + print("Could not render %s"%input) def main(): @@ -1302,7 +1303,11 @@ def main(): #we are interactive, not in stdin, we can have multiple files as input for f in args.content: path = os.path.abspath(f.name) - render(f.read(),path=path,format=args.format,url=args.url,mime=args.mime) + try: + content = f.read() + except UnicodeDecodeError: + content = f + render(content,path=path,format=args.format,url=args.url,mime=args.mime) else: #we are in stdin if not args.format and not args.mime: