From b9e361c4b2fa935b7225be625ef029a1431b3c6f Mon Sep 17 00:00:00 2001 From: aszlig Date: Sun, 10 Sep 2017 05:19:23 +0200 Subject: games/fetch-itch: Allow to pass a version So far we had a similar "experience" with itch.io as we had with humblebundle having upstream URLs being updated in-place and thus whenever we're trying to get an earlier revision than the latest one, our fetcher would fail. However, itch.io has build IDs which even contain version string that we can actually use in our packages as-is and they directly map to a build ID. This commit implements just that, so that whenever a version attribute is passed to fetchItch, an explicit version is selected. If such a version couldn't be found, a list of the most recent versions is displayed, which should also make it easier for updating packages. Signed-off-by: aszlig --- pkgs/games/itch/fetch-itch/default.nix | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'pkgs/games/itch') diff --git a/pkgs/games/itch/fetch-itch/default.nix b/pkgs/games/itch/fetch-itch/default.nix index ed1ac7f6..3700f5c6 100644 --- a/pkgs/games/itch/fetch-itch/default.nix +++ b/pkgs/games/itch/fetch-itch/default.nix @@ -3,7 +3,7 @@ , apiKey }: -{ name, gameId, uploadId, sha256 }: +{ name, gameId, uploadId, sha256, version ? null }: let cafile = "${cacert}/etc/ssl/certs/ca-bundle.crt"; @@ -21,15 +21,41 @@ let NAME = os.getenv('name') GAME_ID = int(os.getenv('gameId')) UPLOAD_ID = int(os.getenv('uploadId')) + VERSION = os.getenv('version', None) def request(path): with urlopen(urljoin(API_BASE, path)) as u: return json.loads(u.read()) + def get_versions(key): + url = 'upload/{}/builds'.format(UPLOAD_ID) + return request(url + '?download_key_id=' + str(key))['builds'] + + def print_download_url(key): + if VERSION is not None: + versions = get_versions(key) + wanted = [ver for ver in versions if ver['user_version'] == VERSION] + if len(wanted) == 1: + url = 'upload/{}/download/builds/{}?download_key_id={}'.format( + UPLOAD_ID, wanted[0]['id'], key + ) + sys.stdout.write(request(url)['archive']['url'] + '\n') + return + else: + msg = 'Unknown version {}, recent versions are:\n'.format(VERSION) + sys.stderr.write(msg) + for ver in versions[:20]: + sys.stderr.write('Update date: {}, version: {}\n'.format( + ver['updated_at'], ver['user_version'] + )) + raise SystemExit(1) + + url = 'download-key/{}/download/{}'.format(key, UPLOAD_ID) + sys.stdout.write(request(url)['url'] + '\n') + for key in request('my-owned-keys')['owned_keys']: if key['game']['id'] == GAME_ID: - url = 'download-key/{}/download/{}'.format(key['id'], UPLOAD_ID) - sys.stdout.write(request(url)['url'] + '\n') + print_download_url(key['id']) raise SystemExit(0) sys.stderr.write('Unable to find download for game {}!'.format(NAME)) @@ -37,7 +63,7 @@ let ''; in stdenv.mkDerivation { - inherit name apiKey gameId uploadId; + inherit name apiKey gameId uploadId version; outputHashAlgo = "sha256"; outputHash = sha256; -- cgit 1.4.1