Code Monkey home page Code Monkey logo

ansi-zenikanard's Introduction

Zenikanards in the terminal

Transcode zenikanard png image to ansi sequences viewable in a terminal.

zenikanard-png

to

zenikanard-ansi

Also provides a webserver to serve transcoded zenikanards.

Quickstart

Using Docker

git clone https://github.com/gfeun/ansi-zenikanard
cd ansi-zenikanard
docker build -t ansi-zenikanard .
docker run -p 8080:8080 ansi-zenikanard

You can mount the cache directory to save the zenikanard cache across docker run:

docker run -v $PWD/cache:/cache -p 8080:8080 ansi-zenikanard

The default docker image built using docker build is heavy because it includes a web browser to scrape the zenikanard gallery.

If you want to build a lighter image you can use:

docker build --target light -t ansi-zenikanard:light .
docker run -p 8080:8080 ansi-zenikanard:light

This will build an image including only the webserver. This requires that you run the heavy image once to get and convert zenikanards in the cache directory. You can then pass the cache to the light image by mounting the cache directory as a volume.

Manually

Dependencies

You need one of the following transcoding backend installed:

  • viu - Follow repo installation instructions
  • img2txt - Debian: apt-get install caca-utils on Debian
  • pixterm - go get -u github.com/eliukblau/pixterm/cmd/pixterm

You also need an OS compatible with playwright-go. x86-64 machines Windows/Mac/Linux should be ok.

Tested only on linux.

Run

Ensure you have $GOPATH/bin in your path or call with full path.

The following commands will download the module and start the program.

The program will create a directory called cache in your working directory.

go get github.com/gfeun/ansi-zenikanard
ansi-zenikanard

In another terminal run:

curl http://localhost:8080

If using another backend than viu you need to specify it at the cli:

ansi-zenikanard -image-transcoder img2txt

Other options are available, see Usage section.

Usage

Usage of ansi-zenikanard:
  -cache
      use local cache (default true)
  -cache-dir string
      cache directory to store zenikanards (default "./cache")
  -cache-only
      don't scrape website, use only local cache. Useful on machine where playwright is not supported, raspi for example. Assumes cache enabled
  -fetch-only
      fetch zenikanard and stop
  -h  help
  -image-transcoder string
      program to transcode png to ansi. one of viu, img2txt, pixterm (default "viu")
  -listen-addr string
      adress and port fed to http.ListenAndServe (default ":8080")
  -playwright-install
      install browsers
  -transition-time int
      time to sleep between zenikanard in millisecond (default 500)
  -v  enable debug output

Internals

This project first fetches the zenikanards from https://theduckgallery.zenika.com/ using https://github.com/mxschmitt/playwright-go Playwright launches a headless browser which loads the duck gallery. A query selector is then used to get all img tag corresponding to zenikanards.

I first tried to download the main page and parse it manually but the list of zenikanard is downloaded with Javascript, so it is not available in the base html.

I could have downloaded the https://theduckgallery.zenika.com/contributors.js and parsed the zenikanard list from there but it was less fun than using playwright :).

Once the list of zenikanard is obtained, each zenikanard is sent on a download channel.

A pool of download worker is started and each worker listens on the download channel. When it receives a zenikanard it first checks if it is available in a local cache. If not it downloads it using its URL.

If the zenikanard is not recovered from cache, the downloaded image still needs to be converted to ANSI. In this case it is sent through another channel: the transcoding channel.

Behind this channel is another pool of workers. When a transcode worker receives a zenikanard it launches an external process and passes the png image to it. The default process called is viu which will output sequences viewable in most terminals. The resulting ansi output is stored in the zenikanard struct and in a local cache file if the cache is enabled

Finally once all zenikanards have been processed, a webserver is started providing two routes:

  • GET /[github username] -> Get zenikanard of the provided github username
  • GET / -> circles through all the gallery zenikanard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.