maunium-stickerpicker-nix/fetchers.nix
teutat3s f19ee88860
refactor: only download stickers with nix,
manually invoke sticker-pack from the devshell to upload stickers to
matrix, to avoid leaking the access token from config.json to the nix
store.

Nixify SigStickers https://github.com/FHPythonUtils/SigStickers and
dependency https://github.com/signalstickers/signalstickers-client to
download Signal stickers
2024-04-29 00:12:49 +02:00

61 lines
1.6 KiB
Nix

{ pkgs, lib, ... }: let
baseFetcher = { instructions, type, title, id ? "", dir }: let
dirname = "${type}-${dir}";
in ''
pushd $IMG_DIR
mkdir '${dirname}'
pushd '${dirname}'
${instructions}
popd
'';
in {
directory-deps = [ ];
directory-build = { src, id ? "", title ? "", ... }: baseFetcher {
inherit id title;
type = "directory";
dir = builtins.baseNameOf src;
instructions = ''
ln -s ${src}/* .
'';
};
chatsticker-deps = with pkgs; [ wget html-xml-utils ];
chatsticker-build = { name, id ? "", title ? "", ... }: baseFetcher {
inherit id title;
type = "chatsticker";
dir = name;
instructions = ''
wget "https://chatsticker.com/sticker/${name}" -O raw.html
hxnormalize -l 240 -x raw.html > normalized.html
cat normalized.html | hxselect -s '\n' -c ".img-fluid::attr(src)" > images.txt;
sed -i 's|;compress=true||' images.txt
for url in $(cat images.txt); do
wget $url
done
rm raw.html normalized.html images.txt
'';
};
stickers-cloud-deps = with pkgs; [ wget html-xml-utils ];
stickers-cloud-build = { name, id ? "", title ? "", ... }: baseFetcher {
inherit id title;
type = "stickers-cloud";
dir = name;
instructions = ''
wget "https://stickers.cloud/en/pack/${name}" -O raw.html
hxnormalize -l 240 -x raw.html > normalized.html
cat normalized.html | hxselect -s '\n' -c "img.d-block.image-ratio::attr(src)" > images.txt;
for url in $(cat images.txt); do
wget $url
done
rm raw.html normalized.html images.txt
'';
};
}