lib/fetchers: add Internet Archive fetcher

This commit is contained in:
Gabriel Arazas 2024-08-28 14:36:28 +08:00
parent 1a1421386c
commit e56c0a6136
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
4 changed files with 55 additions and 0 deletions

View File

@ -17,11 +17,13 @@ pkgs.lib.makeExtensible
builders = callLib ./builders.nix;
trivial = callLib ./trivial.nix;
data = callLib ./data.nix;
fetchers = callLib ./fetchers;
inherit (self.builders) makeXDGMimeAssociationList
makeXDGPortalConfiguration makeXDGDesktopEntry;
inherit (self.trivial) countAttrs;
inherit (self.data) importYAML renderTeraTemplate;
inherit (self.fetchers) fetchInternetArchive;
} // lib.optionalAttrs (builtins ? fetchTree) {
flake = callLib ./flake.nix;

5
lib/fetchers/default.nix Normal file
View File

@ -0,0 +1,5 @@
{ pkgs, lib, self }:
{
fetchInternetArchive = pkgs.callPackage ./fetch-internet-archive { };
}

View File

@ -0,0 +1,27 @@
{ stdenvNoCC, lib, fetchzip, fetchurl, curl }:
{
id,
file ? "",
formats ? [ ],
hash ? "",
name ? "internet-archive-${id}",
}@args:
let
isFormatIndiciated = formats != [ ];
url =
if isFormatIndiciated
then "https://archive.org/compress/${lib.escapeURL id}/formats=${lib.concatStringsSep "," formats}"
else "https://archive.org/download/${lib.escapeURL id}/${lib.escapeURL file}";
args' = lib.removeAttrs args [ "id" "file" "formats" ] // {
inherit url hash name;
} // lib.optionalAttrs isFormatIndiciated { inherit hash; };
fetcher =
if isFormatIndiciated
then fetchzip
else fetchurl;
in
fetcher args'

21
tests/lib/fetchers.nix Normal file
View File

@ -0,0 +1,21 @@
{
pkgs ? import <nixpkgs> { },
lib ? pkgs.lib,
self ? import ../../lib { inherit pkgs; },
}:
{
testsInternetArchiveFetcher =
self.fetchers.fetchInternetArchive {
id = "md_music_sonic_the_hedgehog";
file = "01 - Title Theme - Masato Nakamura.flac";
hash = "sha256-kGjsVjtjXK9imqyi4GF6qkFVmobiTAe/ZAeEwiouqS4=";
};
testsInternetArchiveFetcher2 =
self.fetchers.fetchInternetArchive {
id = "md_music_sonic_the_hedgehog";
formats = [ "TEXT" "PNG" ];
hash = "sha256-xbhasJ/wEgcY+EcBAJp5UoYB4N4It3QV/iIeGGdCET8=";
};
}