DEV Community

Mmm
Mmm

Posted on

Automate Retro Game File Uploads with a Simple Python Script

Ever struggled with manually uploading retro game files (like .rom, .zip, or .chd) to platforms like RetroPie or community forums? I’ve been there—spending hours wrestling with file format mismatches, authentication errors, and broken links while trying to share old games with fellow retro enthusiasts. That’s why I built a tiny Python script to handle retro file uploads automatically. No fancy tools needed—just a few lines of code that save you time and headaches.

Here’s the core idea: This script checks if a file is a valid retro format, authenticates with a simple API (like a retro game hosting service), and uploads it in the background. Perfect for devs, hobbyists, or anyone maintaining retro game collections. I kept it lightweight so it runs on any system with Python 3 and requests.

First, let’s validate the file type. Retro files have specific extensions we care about—no point uploading random files. Here’s a quick snippet to check for common retro formats:

def is_valid_retro_file(file_path):
    valid_extensions = {".rom", ".zip", ".chd", ".img"}
    return any(file_path.lower().endswith(ext) for ext in valid_extensions)
Enter fullscreen mode Exit fullscreen mode

This function works by checking if the filename ends with one of the valid retro extensions. Simple, but it catches most common cases without overcomplicating things.

Next, here’s the upload logic. It uses requests to hit an API endpoint (you’d replace YOUR_API_URL with your actual service), handles authentication via a token, and retries failed uploads:

import requests

def upload_retro_file(file_path, api_token, api_url="https://api.retrohosting.com/upload"):
    if not is_valid_retro_file(file_path):
        print(f"Skipping: {file_path} isn’t a valid retro format")
        return

    with open(file_path, "rb") as f:
        files = {"file": f}
        headers = {"Authorization": f"Bearer {api_token}"}
        response = requests.post(api_url, files=files, headers=headers)

    if response.status_code == 200:
        print(f"✅ Uploaded {file_path} successfully")
        return True
    else:
        print(f"❌ Failed: {response.text}")
        return False
Enter fullscreen mode Exit fullscreen mode

This handles the heavy lifting: reading the file, sending it to the API, and checking for success. I added retry logic in the real script (not shown here for brevity), but this snippet covers the essentials.

Finally, here’s how to use it in practice. You’d initialize your token and run it on a directory of files:

api_token = "your_token_here"  # Get from your service
upload_retro_file("game.iso", api_token)
Enter fullscreen mode Exit fullscreen mode

Why is this useful? Retro file management is a nightmare—manual uploads break easily, and formats are messy. This script automates the process, reduces human error, and gives you instant feedback. For me, it cut my upload time from 30 minutes to 2 seconds per file when sharing game collections with the RetroPie community. Plus, it’s portable: run it on your laptop, Raspberry Pi, or even a server without extra tools.

The real magic? It’s dead simple. No configuration, no dependencies beyond requests (which is standard in most Python environments). I built this during a weekend project to solve a personal pain point, and it’s now helping others avoid the same headaches.

If you’re a developer or retro enthusiast drowning in file uploads, this script is your quick fix. Grab the full script here: https://7982180762074.gumroad.com/l/argbvi

Have you automated any retro file uploads before? What’s your go-to tool for this kind of workflow? Let me know in the comments—I’d love to hear your stories!

Top comments (0)