Merge pull request 'asset-tool: add AssetDetails + DownloadVersionV2' (#11) from staging into master
Reviewed-on: #11
This commit is contained in:
commit
89a478eaac
462
Cargo.lock
generated
462
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
|||||||
workspace = { members = ["rbx_asset", "rox_compiler"] }
|
workspace = { members = ["rbx_asset", "rox_compiler"] }
|
||||||
[package]
|
[package]
|
||||||
name = "asset-tool"
|
name = "asset-tool"
|
||||||
version = "0.4.9"
|
version = "0.4.10"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rbx_asset"
|
name = "rbx_asset"
|
||||||
version = "0.2.6"
|
version = "0.3.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = ["strafesnet"]
|
publish = ["strafesnet"]
|
||||||
repository = "https://git.itzana.me/StrafesNET/asset-tool"
|
repository = "https://git.itzana.me/StrafesNET/asset-tool"
|
||||||
|
@ -72,6 +72,10 @@ pub struct UploadResponse{
|
|||||||
pub AssetId:u64,
|
pub AssetId:u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct GetAssetDetailsRequest{
|
||||||
|
pub asset_id:u64,
|
||||||
|
}
|
||||||
#[allow(nonstandard_style,dead_code)]
|
#[allow(nonstandard_style,dead_code)]
|
||||||
pub struct GetAssetRequest{
|
pub struct GetAssetRequest{
|
||||||
pub asset_id:u64,
|
pub asset_id:u64,
|
||||||
@ -91,6 +95,108 @@ impl std::fmt::Display for GetError{
|
|||||||
}
|
}
|
||||||
impl std::error::Error for GetError{}
|
impl std::error::Error for GetError{}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum GetAssetV2Error{
|
||||||
|
ParseError(url::ParseError),
|
||||||
|
Response(ResponseError),
|
||||||
|
VersionHeaderMissing,
|
||||||
|
ToStr(reqwest::header::ToStrError),
|
||||||
|
ParseInt(std::num::ParseIntError),
|
||||||
|
Reqwest(reqwest::Error),
|
||||||
|
}
|
||||||
|
impl std::fmt::Display for GetAssetV2Error{
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f,"{self:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::error::Error for GetAssetV2Error{}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct GetAssetV2AssetMetadata{
|
||||||
|
pub metadataType:u32,
|
||||||
|
pub value:String,
|
||||||
|
}
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct GetAssetV2Location{
|
||||||
|
pub assetFormat:String,// "source"
|
||||||
|
location:String,// this value is private so users cannot mutate it
|
||||||
|
#[serde(default)]
|
||||||
|
pub assetMetadatas:Vec<GetAssetV2AssetMetadata>,
|
||||||
|
}
|
||||||
|
impl GetAssetV2Location{
|
||||||
|
pub fn location(&self)->&str{
|
||||||
|
&self.location
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct GetAssetV2Info{
|
||||||
|
pub locations:Vec<GetAssetV2Location>,
|
||||||
|
pub requestId:String,
|
||||||
|
pub IsHashDynamic:bool,
|
||||||
|
pub IsCopyrightProtected:bool,
|
||||||
|
pub isArchived:bool,
|
||||||
|
pub assetTypeId:u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct GetAssetV2{
|
||||||
|
pub version:u64,
|
||||||
|
pub info:GetAssetV2Info,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone,Copy,Debug,Eq,PartialEq,Hash)]
|
||||||
|
#[derive(serde::Deserialize,serde::Serialize)]
|
||||||
|
pub enum CreatorType{
|
||||||
|
User,
|
||||||
|
Group,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct Creator{
|
||||||
|
pub Id:u64,
|
||||||
|
pub Name:String,
|
||||||
|
pub CreatorType:CreatorType,
|
||||||
|
pub CreatorTargetId:u64,
|
||||||
|
pub HasVerifiedBadge:bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
#[allow(nonstandard_style,dead_code)]
|
||||||
|
pub struct AssetDetails{
|
||||||
|
pub TargetId:u64,
|
||||||
|
pub ProductType:Option<String>,
|
||||||
|
pub AssetId:u64,
|
||||||
|
pub ProductId:u64,
|
||||||
|
pub Name:String,
|
||||||
|
pub Description:String,
|
||||||
|
pub AssetTypeId:u32,
|
||||||
|
pub Creator:Creator,
|
||||||
|
pub IconImageAssetId:u64,
|
||||||
|
pub Created:chrono::DateTime<chrono::Utc>,
|
||||||
|
pub Updated:chrono::DateTime<chrono::Utc>,
|
||||||
|
pub PriceInRobux:Option<u32>,
|
||||||
|
pub PriceInTickets:Option<u32>,
|
||||||
|
pub Sales:u32,
|
||||||
|
pub IsNew:bool,
|
||||||
|
pub IsForSale:bool,
|
||||||
|
pub IsPublicDomain:bool,
|
||||||
|
pub IsLimited:bool,
|
||||||
|
pub IsLimitedUnique:bool,
|
||||||
|
pub Remaining:Option<u32>,
|
||||||
|
pub MinimumMembershipLevel:u32,
|
||||||
|
pub ContentRatingTypeId:u32,
|
||||||
|
pub SaleAvailabilityLocations:Option<String>,
|
||||||
|
pub SaleLocation:Option<String>,
|
||||||
|
pub CollectibleItemId:Option<u64>,
|
||||||
|
pub CollectibleProductId:Option<u64>,
|
||||||
|
pub CollectiblesItemDetails:Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct AssetVersionsPageRequest{
|
pub struct AssetVersionsPageRequest{
|
||||||
pub asset_id:u64,
|
pub asset_id:u64,
|
||||||
pub cursor:Option<String>,
|
pub cursor:Option<String>,
|
||||||
@ -101,7 +207,7 @@ pub struct AssetVersion{
|
|||||||
pub Id:u64,
|
pub Id:u64,
|
||||||
pub assetId:u64,
|
pub assetId:u64,
|
||||||
pub assetVersionNumber:u64,
|
pub assetVersionNumber:u64,
|
||||||
pub creatorType:String,
|
pub creatorType:CreatorType,
|
||||||
pub creatorTargetId:u64,
|
pub creatorTargetId:u64,
|
||||||
pub creatingUniverseId:Option<u64>,
|
pub creatingUniverseId:Option<u64>,
|
||||||
pub created:chrono::DateTime<chrono::Utc>,
|
pub created:chrono::DateTime<chrono::Utc>,
|
||||||
@ -350,12 +456,63 @@ impl CookieContext{
|
|||||||
).await.map_err(GetError::Response)?
|
).await.map_err(GetError::Response)?
|
||||||
.bytes().await.map_err(GetError::Reqwest)?;
|
.bytes().await.map_err(GetError::Reqwest)?;
|
||||||
|
|
||||||
match maybe_gzip_decode(&mut std::io::Cursor::new(body)){
|
match maybe_gzip_decode(std::io::Cursor::new(body)){
|
||||||
Ok(ReaderType::GZip(readable))=>read_readable(readable),
|
Ok(ReaderType::GZip(readable))=>read_readable(readable),
|
||||||
Ok(ReaderType::Raw(readable))=>read_readable(readable),
|
Ok(ReaderType::Raw(readable))=>read_readable(readable),
|
||||||
Err(e)=>Err(e),
|
Err(e)=>Err(e),
|
||||||
}.map_err(GetError::IO)
|
}.map_err(GetError::IO)
|
||||||
}
|
}
|
||||||
|
pub async fn get_asset_v2(&self,config:GetAssetRequest)->Result<GetAssetV2,GetAssetV2Error>{
|
||||||
|
let mut url=reqwest::Url::parse("https://assetdelivery.roblox.com/v2/asset").map_err(GetAssetV2Error::ParseError)?;
|
||||||
|
//url borrow scope
|
||||||
|
{
|
||||||
|
let mut query=url.query_pairs_mut();//borrow here
|
||||||
|
query.append_pair("ID",config.asset_id.to_string().as_str());
|
||||||
|
if let Some(version)=config.version{
|
||||||
|
query.append_pair("version",version.to_string().as_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let response=crate::response_ok(
|
||||||
|
self.get(url).await.map_err(GetAssetV2Error::Reqwest)?
|
||||||
|
).await.map_err(GetAssetV2Error::Response)?;
|
||||||
|
|
||||||
|
let version=response
|
||||||
|
.headers()
|
||||||
|
.get("roblox-assetversionnumber")
|
||||||
|
.ok_or(GetAssetV2Error::VersionHeaderMissing)?
|
||||||
|
.to_str()
|
||||||
|
.map_err(GetAssetV2Error::ToStr)?
|
||||||
|
.parse()
|
||||||
|
.map_err(GetAssetV2Error::ParseInt)?;
|
||||||
|
|
||||||
|
let info=response.json().await.map_err(GetAssetV2Error::Reqwest)?;
|
||||||
|
|
||||||
|
Ok(GetAssetV2{
|
||||||
|
version,
|
||||||
|
info,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub async fn get_asset_v2_download(&self,config:&GetAssetV2Location)->Result<Vec<u8>,GetError>{
|
||||||
|
let url=reqwest::Url::parse(config.location.as_str()).map_err(GetError::ParseError)?;
|
||||||
|
|
||||||
|
let body=crate::response_ok(
|
||||||
|
self.get(url).await.map_err(GetError::Reqwest)?
|
||||||
|
).await.map_err(GetError::Response)?
|
||||||
|
.bytes().await.map_err(GetError::Reqwest)?;
|
||||||
|
|
||||||
|
match maybe_gzip_decode(std::io::Cursor::new(body)){
|
||||||
|
Ok(ReaderType::GZip(readable))=>read_readable(readable),
|
||||||
|
Ok(ReaderType::Raw(readable))=>read_readable(readable),
|
||||||
|
Err(e)=>Err(e),
|
||||||
|
}.map_err(GetError::IO)
|
||||||
|
}
|
||||||
|
pub async fn get_asset_details(&self,config:GetAssetDetailsRequest)->Result<AssetDetails,GetError>{
|
||||||
|
let url=reqwest::Url::parse(format!("https://economy.roblox.com/v2/assets/{}/details",config.asset_id).as_str()).map_err(GetError::ParseError)?;
|
||||||
|
crate::response_ok(
|
||||||
|
self.get(url).await.map_err(GetError::Reqwest)?
|
||||||
|
).await.map_err(GetError::Response)?
|
||||||
|
.json().await.map_err(GetError::Reqwest)
|
||||||
|
}
|
||||||
pub async fn get_asset_versions_page(&self,config:AssetVersionsPageRequest)->Result<AssetVersionsPageResponse,PageError>{
|
pub async fn get_asset_versions_page(&self,config:AssetVersionsPageRequest)->Result<AssetVersionsPageResponse,PageError>{
|
||||||
let mut url=reqwest::Url::parse(format!("https://develop.roblox.com/v1/assets/{}/saved-versions",config.asset_id).as_str()).map_err(PageError::ParseError)?;
|
let mut url=reqwest::Url::parse(format!("https://develop.roblox.com/v1/assets/{}/saved-versions",config.asset_id).as_str()).map_err(PageError::ParseError)?;
|
||||||
//url borrow scope
|
//url borrow scope
|
||||||
|
109
src/main.rs
109
src/main.rs
@ -20,8 +20,11 @@ struct Cli{
|
|||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Commands{
|
enum Commands{
|
||||||
|
AssetDetails(AssetDetailsSubcommand),
|
||||||
DownloadHistory(DownloadHistorySubcommand),
|
DownloadHistory(DownloadHistorySubcommand),
|
||||||
Download(DownloadSubcommand),
|
Download(DownloadSubcommand),
|
||||||
|
DownloadVersion(DownloadVersionSubcommand),
|
||||||
|
DownloadVersionV2(DownloadVersionSubcommand),
|
||||||
DownloadDecompile(DownloadDecompileSubcommand),
|
DownloadDecompile(DownloadDecompileSubcommand),
|
||||||
DownloadCreationsJson(DownloadCreationsJsonSubcommand),
|
DownloadCreationsJson(DownloadCreationsJsonSubcommand),
|
||||||
DownloadUserInventoryJson(DownloadUserInventoryJsonSubcommand),
|
DownloadUserInventoryJson(DownloadUserInventoryJsonSubcommand),
|
||||||
@ -59,7 +62,19 @@ struct DownloadHistorySubcommand{
|
|||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
end_version:Option<u64>,
|
end_version:Option<u64>,
|
||||||
}
|
}
|
||||||
/// Download a single asset by id.
|
/// Print the details for an asset
|
||||||
|
#[derive(Args)]
|
||||||
|
struct AssetDetailsSubcommand{
|
||||||
|
#[arg(long,group="cookie",required=true)]
|
||||||
|
cookie_literal:Option<String>,
|
||||||
|
#[arg(long,group="cookie",required=true)]
|
||||||
|
cookie_envvar:Option<String>,
|
||||||
|
#[arg(long,group="cookie",required=true)]
|
||||||
|
cookie_file:Option<PathBuf>,
|
||||||
|
#[arg(required=true)]
|
||||||
|
asset_id:AssetID,
|
||||||
|
}
|
||||||
|
/// Download a list of assets by id.
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
struct DownloadSubcommand{
|
struct DownloadSubcommand{
|
||||||
#[arg(long,group="cookie",required=true)]
|
#[arg(long,group="cookie",required=true)]
|
||||||
@ -73,6 +88,22 @@ struct DownloadSubcommand{
|
|||||||
#[arg(required=true)]
|
#[arg(required=true)]
|
||||||
asset_ids:Vec<AssetID>,
|
asset_ids:Vec<AssetID>,
|
||||||
}
|
}
|
||||||
|
/// Download a single asset by id, optionally specifying the version to download.
|
||||||
|
#[derive(Args)]
|
||||||
|
struct DownloadVersionSubcommand{
|
||||||
|
#[arg(long,group="cookie",required=true)]
|
||||||
|
cookie_literal:Option<String>,
|
||||||
|
#[arg(long,group="cookie",required=true)]
|
||||||
|
cookie_envvar:Option<String>,
|
||||||
|
#[arg(long,group="cookie",required=true)]
|
||||||
|
cookie_file:Option<PathBuf>,
|
||||||
|
#[arg(long)]
|
||||||
|
output_folder:Option<PathBuf>,
|
||||||
|
#[arg(long)]
|
||||||
|
asset_id:AssetID,
|
||||||
|
#[arg(long)]
|
||||||
|
asset_version:Option<u64>,
|
||||||
|
}
|
||||||
/// Download the list of asset ids (not the assets themselves) created by a group or user. The output is written to `output_folder/versions.json`
|
/// Download the list of asset ids (not the assets themselves) created by a group or user. The output is written to `output_folder/versions.json`
|
||||||
#[derive(Args)]
|
#[derive(Args)]
|
||||||
struct DownloadCreationsJsonSubcommand{
|
struct DownloadCreationsJsonSubcommand{
|
||||||
@ -137,7 +168,7 @@ struct CreateAssetMediaSubcommand{
|
|||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
model_name:String,
|
model_name:String,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
description:Option<String>,
|
description:String,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
input_file:PathBuf,
|
input_file:PathBuf,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
@ -402,6 +433,16 @@ impl AssetType{
|
|||||||
async fn main()->AResult<()>{
|
async fn main()->AResult<()>{
|
||||||
let cli=Cli::parse();
|
let cli=Cli::parse();
|
||||||
match cli.command{
|
match cli.command{
|
||||||
|
Commands::AssetDetails(subcommand)=>{
|
||||||
|
asset_details(
|
||||||
|
cookie_from_args(
|
||||||
|
subcommand.cookie_literal,
|
||||||
|
subcommand.cookie_envvar,
|
||||||
|
subcommand.cookie_file,
|
||||||
|
).await?,
|
||||||
|
subcommand.asset_id
|
||||||
|
).await
|
||||||
|
},
|
||||||
Commands::DownloadHistory(subcommand)=>download_history(DownloadHistoryConfig{
|
Commands::DownloadHistory(subcommand)=>download_history(DownloadHistoryConfig{
|
||||||
continue_from_versions:subcommand.continue_from_versions.unwrap_or(false),
|
continue_from_versions:subcommand.continue_from_versions.unwrap_or(false),
|
||||||
end_version:subcommand.end_version,
|
end_version:subcommand.end_version,
|
||||||
@ -429,6 +470,40 @@ async fn main()->AResult<()>{
|
|||||||
}).collect()
|
}).collect()
|
||||||
).await
|
).await
|
||||||
},
|
},
|
||||||
|
Commands::DownloadVersion(subcommand)=>{
|
||||||
|
let output_folder=subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap());
|
||||||
|
download_version(
|
||||||
|
cookie_from_args(
|
||||||
|
subcommand.cookie_literal,
|
||||||
|
subcommand.cookie_envvar,
|
||||||
|
subcommand.cookie_file,
|
||||||
|
).await?,
|
||||||
|
subcommand.asset_id,
|
||||||
|
subcommand.asset_version,
|
||||||
|
{
|
||||||
|
let mut path=output_folder.clone();
|
||||||
|
path.push(subcommand.asset_id.to_string());
|
||||||
|
path
|
||||||
|
},
|
||||||
|
).await
|
||||||
|
},
|
||||||
|
Commands::DownloadVersionV2(subcommand)=>{
|
||||||
|
let output_folder=subcommand.output_folder.unwrap_or_else(||std::env::current_dir().unwrap());
|
||||||
|
download_version_v2(
|
||||||
|
cookie_from_args(
|
||||||
|
subcommand.cookie_literal,
|
||||||
|
subcommand.cookie_envvar,
|
||||||
|
subcommand.cookie_file,
|
||||||
|
).await?,
|
||||||
|
subcommand.asset_id,
|
||||||
|
subcommand.asset_version,
|
||||||
|
{
|
||||||
|
let mut path=output_folder.clone();
|
||||||
|
path.push(subcommand.asset_id.to_string());
|
||||||
|
path
|
||||||
|
},
|
||||||
|
).await
|
||||||
|
},
|
||||||
Commands::DownloadDecompile(subcommand)=>{
|
Commands::DownloadDecompile(subcommand)=>{
|
||||||
download_decompile(DownloadDecompileConfig{
|
download_decompile(DownloadDecompileConfig{
|
||||||
cookie:cookie_from_args(
|
cookie:cookie_from_args(
|
||||||
@ -492,7 +567,7 @@ async fn main()->AResult<()>{
|
|||||||
input_file:subcommand.input_file,
|
input_file:subcommand.input_file,
|
||||||
asset_type:subcommand.asset_type.cloud(),
|
asset_type:subcommand.asset_type.cloud(),
|
||||||
model_name:subcommand.model_name,
|
model_name:subcommand.model_name,
|
||||||
description:subcommand.description.unwrap_or_else(||String::with_capacity(0)),
|
description:subcommand.description,
|
||||||
expected_price:subcommand.expected_price,
|
expected_price:subcommand.expected_price,
|
||||||
}).await,
|
}).await,
|
||||||
Commands::CreateAssetMedias(subcommand)=>create_asset_medias(CreateAssetMediasConfig{
|
Commands::CreateAssetMedias(subcommand)=>create_asset_medias(CreateAssetMediasConfig{
|
||||||
@ -906,6 +981,34 @@ async fn upload_place(config:UploadPlaceConfig)->AResult<()>{
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn asset_details(cookie:Cookie,asset_id:AssetID)->AResult<()>{
|
||||||
|
let context=CookieContext::new(cookie);
|
||||||
|
let details=context.get_asset_details(rbx_asset::cookie::GetAssetDetailsRequest{asset_id}).await?;
|
||||||
|
println!("details:{details:?}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn download_version(cookie:Cookie,asset_id:AssetID,version:Option<u64>,dest:PathBuf)->AResult<()>{
|
||||||
|
let context=CookieContext::new(cookie);
|
||||||
|
let data=context.get_asset(rbx_asset::cookie::GetAssetRequest{asset_id,version}).await?;
|
||||||
|
tokio::fs::write(dest,data).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn download_version_v2(cookie:Cookie,asset_id:AssetID,version:Option<u64>,dest:PathBuf)->AResult<()>{
|
||||||
|
let context=CookieContext::new(cookie);
|
||||||
|
|
||||||
|
// v2 has two steps
|
||||||
|
let info=context.get_asset_v2(rbx_asset::cookie::GetAssetRequest{asset_id,version}).await?;
|
||||||
|
println!("version:{}",info.version);
|
||||||
|
|
||||||
|
let location=info.info.locations.first().ok_or(anyhow::Error::msg("No locations"))?;
|
||||||
|
let data=context.get_asset_v2_download(location).await?;
|
||||||
|
|
||||||
|
tokio::fs::write(dest,data).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn download_list(cookie:Cookie,asset_id_file_map:AssetIDFileMap)->AResult<()>{
|
async fn download_list(cookie:Cookie,asset_id_file_map:AssetIDFileMap)->AResult<()>{
|
||||||
let context=CookieContext::new(cookie);
|
let context=CookieContext::new(cookie);
|
||||||
futures::stream::iter(asset_id_file_map.into_iter()
|
futures::stream::iter(asset_id_file_map.into_iter()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user