Skip to content

Instantly share code, notes, and snippets.

@brecert
Created March 11, 2022 03:55
Show Gist options
  • Save brecert/28f30df1989c07a2d781d7415679c76c to your computer and use it in GitHub Desktop.
Save brecert/28f30df1989c07a2d781d7415679c76c to your computer and use it in GitHub Desktop.
// deno-lint-ignore-file camelcase
import { writableStreamFromWriter } from "https://deno.land/[email protected]/streams/mod.ts";
const text = await Deno.readTextFile("./mods.txt");
const [query, ...urls] = text.split(/\n/).map((l) => l.trim()).filter((l) =>
l.length > 0 && !l.startsWith("#")
);
const [loader, version] = query.split(" ");
const HOST = "https://api.modrinth.com";
const API = `${HOST}/api/v1`;
const URL_REGEX = /https:\/\/modrinth\.com\/mod\/(.+)/;
type VersionFile = {
hashes: Record<string, string>;
url: string;
filename: string;
primary: boolean;
};
type Version = {
id: string;
mod_id: string;
author_id: string;
featured: string;
name: string;
version_number: string;
changelog?: string;
date_published: number;
downloads: number;
version_type: string;
files: VersionFile[];
dependencies: {
dependency_type: "required" | "optional" | "incompatable";
version_id?: string;
project_id?: string;
}[];
game_versions: string[];
loaders: string[];
};
async function getDownload(idp: string) {
console.log(`Getting mod info for '${idp}'`);
const [id, options = ""] = idp.split("#");
// const modInfo = await fetch(`${API}/search/${id}`).then(res => res.json())
console.log(`Getting download info for '${idp}'`);
const downloadInfo: Version[] = await fetch(`${API}/mod/${id}/version`)
.then((res) => res.json());
const found = options.includes("force")
? downloadInfo.find((l) => l.loaders.includes(loader))
: downloadInfo.find((dl) =>
dl.game_versions.some((v) => v.includes(version))
);
if (!found) {
console.error(`No version '${version}' found for ${id}`);
return;
}
const fileInfo = found.files.at(
found.game_versions.findIndex((v) => v.includes(version)) %
found.files.length,
)!;
console.log(`Downloading '${fileInfo.filename}' ${options}`);
const data = await fetch(fileInfo.url);
const file = await Deno.open(`./mods/${fileInfo.filename}`, {
write: true,
create: true,
});
const writableStream = writableStreamFromWriter(file);
return data.body!.pipeTo(writableStream);
}
await Promise.all(urls.map((url) => url.match(URL_REGEX)![1]).map(getDownload));
fabric 1.18.2
# Core
https://modrinth.com/mod/fabric-api
# Performance
https://modrinth.com/mod/sodium
https://modrinth.com/mod/lithium
https://modrinth.com/mod/dynamic-fps
https://modrinth.com/mod/ferrite-core
https://modrinth.com/mod/starlight
https://modrinth.com/mod/ebe
# Tweaks/Fixes
https://modrinth.com/mod/hatlist
https://modrinth.com/mod/tiefix
https://modrinth.com/mod/better-mount-hud
https://modrinth.com/mod/statssearch
# https://modrinth.com/mod/bedrockIfy
# https://modrinth.com/mod/lambdacontrols
# https://modrinth.com/mod/lambdynamiclights
# https://modrinth.com/mod/inspecio
# https://modrinth.com/mod/brb
# https://modrinth.com/mod/easiercrafting
# Libraries / Dependencies / Modding
https://modrinth.com/mod/modmenu
# https://modrinth.com/mod/modmanager
https://modrinth.com/mod/fabric-language-kotlin
# Clientside
https://modrinth.com/mod/appleskin
https://modrinth.com/mod/ears
# https://modrinth.com/mod/presence-footsteps
# https://modrinth.com/mod/auto-third-person
# https://modrinth.com/mod/vistas
# https://modrinth.com/mod/void-fog
# Forced
https://modrinth.com/mod/fabulousclouds#force
# https://modrinth.com/mod/cleardespawn#force
# not 1.18 :(
# https://modrinth.com/mod/blame-fabric
# https://modrinth.com/mod/no-fade/versions
# https://modrinth.com/mod/fade-in-chunks
# https://modrinth.com/mod/custom-fog
# https://modrinth.com/mod/better-third-person
# https://modrinth.com/mod/smooth-chunks
# https://modrinth.com/mod/eating-animation#force
# [select.chunk-loading]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment