Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support project id #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,29 @@ Worry no more, because here you got
> Warning: If you are so afraid of cmd, better go away from here. Here you got something with [GUI written in Java](https://github.com/Vazkii/CMPDL), I don't know how it works, use at your own responsibility. Maybe I will add some GUI to this project later

## Usage
First you need project name, you take it from modpack url
![](img/1.png)
Now just open your terminal/cmd, enter the directory when you want to download modpack and type
### Using Project ID
Find the project ID on the modpack's CurseForge page.

![](img/3.png)

Open your terminal/cmd, enter the directory when you want to download modpack and type `cmpdl <project id>`

For example, [Project Ozone Lite (https://www.curseforge.com/minecraft/modpacks/project-ozone-lite)](https://www.curseforge.com/minecraft/modpacks/project-ozone-lite)
```bash
cmpdl <project name>
cmpdl 273726
```
For example

### Using Project Name/Slug
Or you can try using the project name taken from modpack url, but this method is slower and not always successful.

![](img/1.png)

Now just open your terminal/cmd, enter the directory when you want to download modpack and type `cmpdl <project name>`

For example, [Project Ozone Lite (https://www.curseforge.com/minecraft/modpacks/project-ozone-lite)](https://www.curseforge.com/minecraft/modpacks/project-ozone-lite)
```bash
cmpdl project-ozone-light
```
And wait until it's downloaded

# Installation
## Install node with npm for your operating system from [here](https://nodejs.org/en/)
Expand Down
36 changes: 31 additions & 5 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ async function getProjectById(projectId) {
const res = await requestPromise.get(`${BASE_URL}/addon/${projectId}`);
return JSON.parse(res);
} catch (err) {
console.error(err);
if (err.statusCode == 404) {
console.error(`Can't find project ${projectId}.`);
}
else {
console.error(err);
}
process.exit(1);
}
}
Expand All @@ -93,7 +98,7 @@ async function getProjectFiles(projectId) {

/**
*
* @param {string} project project name
* @param {string} projectSlug project slug
* @returns { { url: string, version: string, fileName: string } }
*/
async function getLatestProjectFileUrl(projectSlug) {
Expand All @@ -106,6 +111,21 @@ async function getLatestProjectFileUrl(projectSlug) {
}
}

/**
*
* @param {string} projectId project ID
* @returns { { url: string, version: string, fileName: string } }
*/
async function getLatestProjectFileUrlById(projectId) {
const project = await getProjectById(projectId);
const defaultFile = project.latestFiles.filter(x => x.id == project.defaultFileId)[0];
return {
url: defaultFile.downloadUrl,
version: defaultFile.displayName,
fileName: defaultFile.fileName
}
}

/**
*
* @param {string} projectId project ID
Expand Down Expand Up @@ -154,12 +174,18 @@ function removeIllegalCharactersFromFilename(filename) {
*/
async function main(argv) {
if(argv.length < 3) {
console.error("Usage: cmpdl <project name>");
console.error("Usage: cmpdl <project id|project name>");
process.exit(1);
}
const project = argv[2];
console.log("Searching for project main file");
const latest = await getLatestProjectFileUrl(project);
let latest;
if (isNaN(parseInt(project, 10))) {
console.log("Searching for project main file");
latest = await getLatestProjectFileUrl(project);
}
else {
latest = await getLatestProjectFileUrlById(project);
}
createModpacksFolder();
const projectFolderName = removeIllegalCharactersFromFilename(latest.version);
createProjectFolder(projectFolderName);
Expand Down
Binary file modified img/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.