Add a script to download articles

This commit is contained in:
Andreas Zweili 2024-05-15 21:17:45 +02:00
parent 680a102d9d
commit 517db5fe53
2 changed files with 47 additions and 1 deletions

View File

@ -1,4 +1,4 @@
{ pkgs, ... }:
{ inputs, pkgs, ... }:
let
az-media = pkgs.writeShellScriptBin "az-media" ''
videos="videos"
@ -8,6 +8,7 @@ let
nvidia-offload mpv --shuffle --mute=yes "/run/user/1000/gvfs/smb-share:server=10.7.89.108,share=various/$directory/" &
done
'';
send-to-kindle = pkgs.callPackage "${inputs.self}/pkgs/send-to-kindle" { };
in
{
imports = [ ./management.nix ];
@ -19,6 +20,7 @@ in
freetube
nodejs # needed for ansible-language-server
plexamp
send-to-kindle
sound-juicer
unstable.tagger
az-media

View File

@ -0,0 +1,44 @@
{
bash,
cacert,
curl,
gnome,
gnused,
perl,
recode,
writeShellApplication,
}:
writeShellApplication {
name = "rebuild";
runtimeInputs = [
bash
cacert
curl
gnused
gnome.nautilus
perl
recode
];
text = ''
url=$1
# get the title of the page
title=$(curl -s $url | perl -l -0777 -ne 'print $1 if /<title.*?>\s*(.*?)\s*<\/title/si' | recode html..)
# remove non-ascii characters
title=$(echo $title | LANG=C sed 's/[^[:blank:][:print:]]//g')
# remove special characters
title=$(echo $title | sed 's/[^a-zA-Z0-9]/_/g')
# replace multiple underlines with a single one
title=$(echo $title | sed 's/_\+/_/g')
curl \
--data-urlencode "param=" \
--data-urlencode "context=download" \
--data-urlencode "format=epub" \
--data-urlencode "url=$url" \
--location https://pushtokindle.fivefilters.org/send2-html.php \
--output "$HOME/Downloads/$title.epub"
nautilus "$HOME"/Downloads
$DEFAULT_BROWSER "https://www.amazon.com/sendtokindle"
'';
}