Brain.fm Automator

Enhanced audio downloader + auto-signup for Brain.fm with ID3 metadata embedding

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Аўтар
googgoogagag
Усталяванняў за дзень
0
Усяго ўсталяванняў
3
Рэйтынг
0 0 0
Версія
3.1.0
Створаны
03.05.2026
Абноўлены
03.05.2026
Памер
31.7 КБ
Ліцэнзія
Н/Д
Ужываецца на

🎧 Brain.fm Automator v3.1.0

Enhanced audio downloader + auto-signup for Brain.fm with ID3 metadata embedding

A powerful userscript that adds a draggable widget to Brain.fm, enabling one-click audio downloads with embedded metadata (title, artist, genre, and cover art), plus automated test account creation.


✨ Features

🎵 Audio Downloading

  • One-click download of currently playing tracks
  • ID3 metadata embedding (MP3 only):
    • Track title (TIT2)
    • Artist (TPE1) → "Brain.fm"
    • Genre (TCON)
    • Embedded cover art (APIC) with intelligent resizing & compression
  • Smart filename generation from track info or URL fallback
  • Multi-format support: MP3, WAV, OGG, M4A, AAC, FLAC, Opus
  • Fallback download methods: GM_xmlhttpRequestGM_download → anchor tag

🤖 Auto-Signup Automation

  • One-click creation of randomized test accounts
  • Automatic logout flow with modal confirmation handling
  • Visual success feedback on welcome page detection
  • Safe form filling with proper event dispatching

🎨 Widget UI

  • Glassmorphism design with backdrop blur & smooth animations
  • Fully draggable with position persistence (localStorage/GM storage)
  • Responsive & accessible: reduced-motion support, high contrast
  • Real-time track info display with ellipsis truncation
  • Visual feedback: loading states, error animations, success indicators

⚙️ Smart Detection

  • Works on both https://my.brain.fm/* and https://brain.fm/*
  • Auto-detects audio element changes via MutationObserver
  • Handles SPA navigation with URL change polling
  • Fallback parsing for track title/genre from DOM or URL patterns
  • Cover art extraction from player card or mini-player

📦 Installation

Requirements

  • Userscript Manager: Tampermonkey, Violentmonkey, or Greasemonkey
  • Browser: Modern Chromium, Firefox, or WebKit-based browser
  • Permissions: Script requires GM_download, GM_xmlhttpRequest, GM_addStyle, GM_getValue, GM_setValue

Steps

  1. Install your preferred userscript manager extension
  2. Click the "Install" button on the raw script file, or:
  3. Create a new script and paste the entire code
  4. Save and refresh any Brain.fm page
  5. The widget should appear in the top-right corner 🎉

🎛️ Configuration

Runtime Settings (via Widget)

Setting Default Description
Metadata Embedding ✅ Enabled Toggle ID3 tag embedding for MP3 downloads

Settings persist across sessions using GM_setValue or localStorage fallback.

Code-Level Constants (CONFIG object)

const CONFIG = {
  WIDGET_ID: 'brainfm-unified-widget-fixed',  // Widget DOM ID
  POS_KEY: 'brainfm_widget_pos',              // Storage key for position
  META_KEY: 'brainfm_meta_enabled',           // Storage key for metadata toggle
  DRAG_THRESHOLD: 3,                          // Pixels to start drag
  OBSERVER_DEBOUNCE: 250,                     // DOM scan debounce (ms)
  DOWNLOAD_TIMEOUT: 120000,                   // Download timeout (ms)
  STATE_CHECK_INTERVAL: 800,                  // Track info poll interval (ms)
  MAX_RETRY_ATTEMPTS: 3,                      // Unused placeholder
  METADATA_ENABLED: true,                     // Default metadata state

  SELECTORS: { /* DOM query selectors for Brain.fm elements */ }
};

⚠️ Modify code-level config only if you understand the script internals.


🚀 Usage Guide

Downloading Audio

  1. Navigate to any Brain.fm page with audio playing
  2. Locate the floating widget (top-right by default)
  3. Click "🎧 Download Audio"
  4. If metadata is enabled & file is MP3:
    • Cover art is fetched & compressed
    • ID3 tags are embedded client-side
    • Final file downloads with metadata intact
  5. Check your downloads folder for the file

Creating Test Accounts

  1. Click the "New Acc" button on the widget
  2. Script will:
    • Auto-logout if already signed in
    • Fill signup form with randomized credentials
    • Submit and monitor for welcome page
  3. Success shows green checkmark; credentials logged to console

Widget Controls

Control Action
Drag header Reposition widget (position saved)
↻ Refresh Re-scan page for audio/track info
🎧 Download Start download of current track
New Acc Run automated signup flow

🔧 Technical Details

ID3 Embedding Workflow

graph LR
    A[Download MP3] --> B{Metadata Enabled?}
    B -->|Yes| C[Fetch Cover Art URL]
    C --> D[Resize & Compress Image]
    D --> E[Create ID3 Frames: TIT2/TPE1/TCON/APIC]
    E --> F[Prepend ID3 Tag to Audio Buffer]
    F --> G[Download Tagged File]
    B -->|No| G

Download Method Fallback Chain

  1. GM_xmlhttpRequest (preferred): Full control, supports post-processing for metadata
  2. GM_download: Native manager download (no metadata embedding)
  3. Anchor tag: Universal fallback (no metadata, may trigger browser download UI)

Storage Strategy

// Abstracted storage wrapper
storage.get(key, fallback)  // Tries GM_getValue → localStorage
storage.set(key, value)     // Tries GM_setValue → localStorage

Selector Resilience

The script uses multiple fallback strategies to locate track info:

  1. Primary: [data-testid="currentTrackTitle"] (player page)
  2. Secondary: Styled-components class selectors (.bMnsXL, etc.)
  3. Tertiary: Parse filename from audio src attribute

🐛 Troubleshooting

Issue Possible Cause Solution
Widget not appearing Script not loaded / wrong domain Check userscript manager is active; ensure URL matches @match patterns
Download fails silently CORS / network error / timeout Check console for [BrainFM] warnings; try refreshing page
Metadata not embedding File not MP3 / cover fetch failed / ID3 error Verify file extension; check network tab for cover art 403/404
Widget stuck/dragging Pointer capture lost Click refresh button or reload page
Auto-signup hangs Brain.fm form structure changed Check console for selector warnings; script may need update
Position not saving Storage quota / permissions issue Clear localStorage for brain.fm; ensure GM_* permissions granted

Debugging Tips

  • Open browser DevTools → Console: All script logs prefixed with %c[BrainFM]
  • Look for:
    • ✅ Widget initialized → Script loaded successfully
    • 🎨 Metadata embedding: enabled → ID3 feature active
    • ⚠️ Metadata embedding skipped → Non-critical error, download continues
    • ❌ Download failed → Network or processing error

🛠️ Development Notes

Project Structure

Brain.fm Automator
├── CONFIG          // Global settings & selectors
├── ID3Embedder     // Minimal MP3 ID3v2.3 writer
├── Styles          // Glassmorphism CSS with fallbacks
├── Widget          // Draggable UI component manager
├── AudioHandler    // Track detection, info parsing, observer
├── Downloader      // Multi-method download with metadata pipeline
└── AutoSignup      // Form automation with modal handling

Security Considerations

  • All processing occurs client-side; no data sent to third parties
  • Cover art fetched via GM_xmlhttpRequest with same-origin referer
  • Randomized credentials for auto-signup are console-logged only (not stored)

📜 License & Credits

  • Author: Soul
  • License: MIT (free to use, modify, distribute)

Acknowledgements

  • Brain.fm team for the amazing focus music 🧠
  • Userscript community for GM API documentation
  • CSS glassmorphism trends for the widget aesthetic ✨

🔄 Version History

v3.1.0 (Current)

  • ✅ ID3 metadata embedding with cover art support
  • ✅ Intelligent cover resizing (max 600px, 85% quality JPEG)
  • ✅ Draggable widget with persistent position
  • ✅ Auto-signup with modal confirmation handling