Add support for scraping classic Skyrim mods
Not adding it to the update.sh script quite yet since I need to run the very long process of downloading every classic skyrim mod that currently exists on the nexus first.
This commit is contained in:
@@ -8,7 +8,7 @@ use tokio::fs::File;
|
||||
use tokio_util::compat::FuturesAsyncReadCompatExt;
|
||||
use tracing::{info, instrument};
|
||||
|
||||
use super::{rate_limit_wait_duration, warn_and_sleep, GAME_NAME, USER_AGENT};
|
||||
use super::{rate_limit_wait_duration, warn_and_sleep, USER_AGENT};
|
||||
|
||||
pub struct DownloadLinkResponse {
|
||||
pub wait: Duration,
|
||||
@@ -16,12 +16,12 @@ pub struct DownloadLinkResponse {
|
||||
}
|
||||
|
||||
#[instrument(skip(client))]
|
||||
pub async fn get(client: &Client, mod_id: i32, file_id: i64) -> Result<DownloadLinkResponse> {
|
||||
pub async fn get(client: &Client, game_name: &str, mod_id: i32, file_id: i64) -> Result<DownloadLinkResponse> {
|
||||
for attempt in 1..=3 {
|
||||
let res = match client
|
||||
.get(format!(
|
||||
"https://api.nexusmods.com/v1/games/{}/mods/{}/files/{}/download_link.json",
|
||||
GAME_NAME, mod_id, file_id
|
||||
game_name, mod_id, file_id
|
||||
))
|
||||
.header("accept", "application/json")
|
||||
.header("apikey", env::var("NEXUS_API_KEY")?)
|
||||
|
||||
@@ -5,7 +5,7 @@ use serde_json::Value;
|
||||
use std::{env, time::Duration};
|
||||
use tracing::{info, instrument};
|
||||
|
||||
use super::{rate_limit_wait_duration, warn_and_sleep, GAME_NAME, USER_AGENT};
|
||||
use super::{rate_limit_wait_duration, warn_and_sleep, USER_AGENT};
|
||||
|
||||
pub struct FilesResponse {
|
||||
pub wait: Duration,
|
||||
@@ -25,12 +25,12 @@ pub struct ApiFile<'a> {
|
||||
}
|
||||
|
||||
#[instrument(skip(client))]
|
||||
pub async fn get(client: &Client, nexus_mod_id: i32) -> Result<FilesResponse> {
|
||||
pub async fn get(client: &Client, game_name: &str, nexus_mod_id: i32) -> Result<FilesResponse> {
|
||||
for attempt in 1..=3 {
|
||||
let res = match client
|
||||
.get(format!(
|
||||
"https://api.nexusmods.com/v1/games/{}/mods/{}/files.json",
|
||||
GAME_NAME, nexus_mod_id
|
||||
game_name, nexus_mod_id
|
||||
))
|
||||
.header("accept", "application/json")
|
||||
.header("apikey", env::var("NEXUS_API_KEY")?)
|
||||
|
||||
@@ -5,7 +5,7 @@ use serde_json::Value;
|
||||
use std::{env, time::Duration};
|
||||
use tracing::{info, instrument};
|
||||
|
||||
use super::{rate_limit_wait_duration, warn_and_sleep, GAME_NAME, USER_AGENT};
|
||||
use super::{rate_limit_wait_duration, warn_and_sleep, USER_AGENT};
|
||||
|
||||
pub struct ModResponse {
|
||||
pub wait: Duration,
|
||||
@@ -13,12 +13,12 @@ pub struct ModResponse {
|
||||
}
|
||||
|
||||
#[instrument(skip(client))]
|
||||
pub async fn get(client: &Client, mod_id: i32) -> Result<ModResponse> {
|
||||
pub async fn get(client: &Client, game_name: &str, mod_id: i32) -> Result<ModResponse> {
|
||||
for attempt in 1..=3 {
|
||||
let res = match client
|
||||
.get(format!(
|
||||
"https://api.nexusmods.com/v1/games/{}/mods/{}.json",
|
||||
GAME_NAME, mod_id
|
||||
game_name, mod_id
|
||||
))
|
||||
.header("accept", "application/json")
|
||||
.header("apikey", env::var("NEXUS_API_KEY")?)
|
||||
|
||||
@@ -11,10 +11,20 @@ pub mod files;
|
||||
pub mod game_mod;
|
||||
pub mod metadata;
|
||||
|
||||
pub static GAME_NAME: &str = "skyrimspecialedition";
|
||||
pub const GAME_ID: u32 = 1704;
|
||||
pub const SKYRIM_GAME_NAME: &str = "skyrim";
|
||||
pub const SKYRIM_GAME_ID: i32 = 110;
|
||||
pub const SSE_GAME_NAME: &str = "skyrimspecialedition";
|
||||
pub const SSE_GAME_ID: i32 = 1704;
|
||||
pub static USER_AGENT: &str = "mod-mapper/0.1";
|
||||
|
||||
pub fn get_game_id(name: &str) -> Option<i32> {
|
||||
match name {
|
||||
SKYRIM_GAME_NAME => Some(SKYRIM_GAME_ID),
|
||||
SSE_GAME_NAME => Some(SSE_GAME_ID),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn rate_limit_wait_duration(res: &Response) -> Result<std::time::Duration> {
|
||||
let daily_remaining: i32 = res
|
||||
.headers()
|
||||
|
||||
Reference in New Issue
Block a user