Created
September 9, 2024 20:21
-
-
Save logixism/e36b9d82e2d887c53e8f80fcede50f8a to your computer and use it in GitHub Desktop.
A bad CLI tool to download Audio Assets from ROBLOX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import typer | |
| import os | |
| import requests | |
| from typing import List | |
| ASSET_DELIVERY_ENDPOINT = "https://assetdelivery.roblox.com/v1/assets/batch" | |
| ASSET_DETAILS_ENDPOINT = ( | |
| "https://apis.roblox.com/toolbox-service/v1/items/details?assetIds=" | |
| ) | |
| def get_metadata(asset_id: int): | |
| metadata = { | |
| "title": "Unknown", | |
| "artist": "Unknown", | |
| "album": "Unknown", | |
| "genre": "Unknown", | |
| } | |
| res = requests.get(f"{ASSET_DETAILS_ENDPOINT}{asset_id}") | |
| if res.ok: | |
| asset_details = res.json()["data"][0]["asset"] | |
| audio_details = asset_details["audioDetails"] | |
| metadata["title"] = audio_details["title"] | |
| metadata["artist"] = audio_details["artist"] | |
| metadata["genre"] = audio_details["musicGenre"] | |
| metadata["album"] = audio_details["musicAlbum"] | |
| return metadata | |
| def get_cdn_urls(asset_ids: list[int]): | |
| urls = {} | |
| for asset_id in asset_ids: | |
| res = requests.post( | |
| ASSET_DELIVERY_ENDPOINT, | |
| json=[{"requestId": asset_id, "assetId": asset_id}], | |
| headers={ | |
| "Roblox-Browser-Asset-Request": "true", | |
| "Cookie": f".ROBLOSECURITY={os.environ['ROBLOSECURITY']}", | |
| }, | |
| ) | |
| if res.ok: | |
| url = res.json()[0]["location"] | |
| urls[url] = get_metadata(asset_id) | |
| return urls | |
| def download_from_cdn(urls: dict[str, dict]): | |
| for url, data in urls.items(): | |
| res = requests.get(url) | |
| if res.ok: | |
| filename = f"{data['artist']} - {data['title']}.wav" | |
| with open(filename, "wb") as f: | |
| f.write(res.content) | |
| def main(asset_id: List[int]): | |
| urls = get_cdn_urls(asset_id) | |
| download_from_cdn(urls) | |
| if __name__ == "__main__": | |
| typer.run(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment