# MoneyPrinterV2 Cache File Structure: How the .mp/ Directory Organizes Data

> Understand the MoneyPrinterV2 cache file structure and how the .mp/ directory organizes persistent state and temporary media files. Learn about its configuration and scratch file separation.

- Repository: [FujiwaraChoki/MoneyPrinterV2](https://github.com/FujiwaraChoki/MoneyPrinterV2)
- Tags: internals
- Published: 2026-03-20

---

**MoneyPrinterV2 stores all persistent state and temporary media files in a hidden `.mp/` directory at the project root, separating JSON configuration files for YouTube, Twitter, and affiliate marketing from transient WAV, PNG, and MP4 scratch files that are automatically cleaned after each run.**

The **MoneyPrinterV2 cache file structure** provides a clear separation between durable account data and temporary processing artifacts. Located in the `FujiwaraChoki/MoneyPrinterV2` repository, this file-based persistence layer eliminates the need for external databases while keeping the workspace clean through automated garbage collection.

## Overview of the .mp/ Cache Directory

The `.mp/` directory serves as the central storage hub for the application. It is created at the project root and is excluded from version control via `.gitignore`. The directory follows a strict organizational philosophy:

- **JSON files** ([`youtube.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/youtube.json), [`twitter.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/twitter.json), [`afm.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/afm.json)) store structured account and product data indefinitely
- **CSV files** (`scraper_results.csv`) cache scraped data for analysis
- **Non-JSON files** (WAV, MP4, PNG, SRT) are treated as temporary scratch space

## Persistent JSON State Files

The core of the MoneyPrinterV2 cache file structure consists of three provider-specific JSON files that maintain account configurations between sessions.

### YouTube Account Storage

The [`.mp/youtube.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/.mp/youtube.json) file maintains the list of managed YouTube accounts including channel IDs, API keys, and upload settings.

In [`src/cache.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/cache.py), the path is resolved via:

```python
def get_youtube_cache_path() -> str:
    return os.path.join(get_cache_path(), 'youtube.json')

```

To add a new account programmatically:

```python
from cache import add_account

new_account = {
    "id": "UC1234567890abcdef",
    "name": "MyChannel",
    "api_key": "xxxxxxxxxxxxxxxx"
}
add_account("youtube", new_account)

```

### Twitter Account Storage

Similarly, [`.mp/twitter.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/.mp/twitter.json) stores Twitter API credentials and account metadata. The retrieval function `get_twitter_cache_path()` in [`src/cache.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/cache.py) constructs this path, while `get_accounts("twitter")` loads the persisted data:

```python
from cache import get_accounts

twitter_accounts = get_accounts("twitter")
print(twitter_accounts)   # Loads from .mp/twitter.json

```

### Affiliate Marketing Product Cache

The [`.mp/afm.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/.mp/afm.json) file stores product data for the Affiliate Marketing module. Unlike account files, this uses `add_product()` to persist SKU details:

```python
from cache import add_product

product = {
    "id": "prod-001",
    "title": "Super Gadget",
    "price": 49.99
}
add_product(product)   # Persists into .mp/afm.json

```

## Scraper Results and CSV Caching

Beyond JSON configuration, the MoneyPrinterV2 cache file structure includes `.mp/scraper_results.csv` for temporary data persistence during scraping operations.

The path is defined in [`src/cache.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/cache.py):

```python
def get_results_cache_path() -> str:
    return os.path.join(get_cache_path(), 'scraper_results.csv')

```

Accessing this cache directly:

```python
from cache import get_results_cache_path
import pandas as pd

csv_path = get_results_cache_path()
df = pd.read_csv(csv_path)   # Reads .mp/scraper_results.csv

```

## Temporary Media File Handling

The `.mp/` directory doubles as scratch space for media processing. During video generation, the system writes temporary **WAV** audio files, **PNG** image frames, **SRT** subtitle files, and intermediate **MP4** clips to this directory.

These files are distinguished from persistent state by their non-JSON extensions. According to the source architecture documented in [`CLAUDE.md`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/CLAUDE.md), this transient data is automatically purged after each execution cycle.

## Core Implementation in src/cache.py

All path resolution logic is centralized in [`src/cache.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/cache.py). The **base cache folder** is established through:

```python
def get_cache_path() -> str:
    """Gets the path to the cache folder"""
    return os.path.join(ROOT_DIR, '.mp')

```

This modular design ensures that all components reference the same `.mp/` location, whether storing YouTube credentials, Twitter tokens, or affiliate product catalogs.

## Automatic Cleanup with rem_temp_files()

To prevent disk bloat, MoneyPrinterV2 implements automatic garbage collection via `rem_temp_files()` in [`src/utils.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/utils.py). This function targets the `.mp/` directory and removes all media files matching common audio and video extensions including `.mp3`, `.wav`, `.m4a`, `.aac`, `.ogg`, `.flac`, `.png`, `.jpg`, `.mp4`, and `.srt`.

While this cleanup runs automatically after most operations, you can trigger it manually:

```python
from utils import rem_temp_files

rem_temp_files()   # Deletes all non-JSON files under .mp/

```

## Summary

- The **MoneyPrinterV2 cache file structure** centers on a hidden `.mp/` directory at the project root that separates persistent JSON state from temporary media files.
- **Configuration persistence** is handled through three dedicated JSON files: [`.mp/youtube.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/.mp/youtube.json), [`.mp/twitter.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/.mp/twitter.json), and [`.mp/afm.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/.mp/afm.json), managed via functions in [`src/cache.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/cache.py).
- **Scraped data** is cached in `.mp/scraper_results.csv` for downstream processing.
- **Temporary artifacts** (WAV, PNG, MP4, SRT) are stored in `.mp/` during video generation but automatically purged by `rem_temp_files()` in [`src/utils.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/utils.py) to keep the workspace clean.

## Frequently Asked Questions

### What types of files are stored permanently in the .mp/ directory?

Only **JSON files** are considered permanent residents of the `.mp/` directory. Specifically, [`.mp/youtube.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/.mp/youtube.json), [`.mp/twitter.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/.mp/twitter.json), and [`.mp/afm.json`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/.mp/afm.json) store account credentials and product data indefinitely. All other file types—including audio, video, image, and subtitle files—are treated as temporary scratch data and are deleted automatically after each run.

### How does MoneyPrinterV2 prevent the cache directory from filling up with old media files?

The system uses the `rem_temp_files()` function located in [`src/utils.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/utils.py) to perform automatic garbage collection. This utility scans the `.mp/` directory and deletes files with extensions commonly used for media processing, such as `.wav`, `.mp3`, `.png`, `.mp4`, and `.srt`. This cleanup typically runs automatically at the end of execution cycles, ensuring that persistent JSON state remains while transient processing artifacts are purged.

### Where is the base path for the cache folder defined in the source code?

The root location of the cache directory is defined in [`src/cache.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/cache.py) within the `get_cache_path()` function. This function joins the project's `ROOT_DIR` with the string `.mp` to produce the absolute path to the hidden cache folder. All other cache-related path helpers—such as `get_youtube_cache_path()` and `get_results_cache_path()`—build upon this base path to ensure consistency across the application.

### Can I manually access the scraper results stored in the cache?

Yes, the scraper results are stored in `.mp/scraper_results.csv` and can be accessed directly using the `get_results_cache_path()` helper from [`src/cache.py`](https://github.com/FujiwaraChoki/MoneyPrinterV2/blob/main/src/cache.py). Since the file is a standard CSV, you can read it with pandas, plain Python, or any spreadsheet application. The data persists between runs unless explicitly cleared, making it useful for auditing scraped content or debugging affiliate marketing product lookups.