- Document magnet hooking workflow and pairing architecture - Detail FastAPI setup and run commands - Provide Firefox temporary add-on loading and verification steps
4.1 KiB
4.1 KiB
Magnetflix Browser Extension (Proof of Concept)
A cross-browser WebExtension (MVP for Firefox) that intercepts magnet links on web pages, opens a capture confirmation popup, redirects to a pairing page with dynamic real-time IMDb movie search, locks the selection, and dispatches the payload to a local FastAPI backend.
🚀 Features
-
Magnet Link Hooking:
- Automatically intercepts clicks on
magnet:links on any page. - Displays a non-intrusive in-page modal dialog:
- "Magnet link captured!"
- Preview of the torrent name and info hash
- Continue button
- Also integrates with the browser toolbar action popup (
popup.html).
- Automatically intercepts clicks on
-
Dedicated Pairing Page (
app.html):- Section 1 (Magnet Link): Displays the captured magnet link in a dedicated text field.
- Section 2 (Movie Search):
- Search field named
movie. - Dynamic search on character input (debounced real-time queries).
- Flexible queries: title (
black swan), title + year (perfect blue 1997), or IMDb ID (tt0156887,tt15560). - Renders top 5 matching results with movie posters, title, release year, IMDb ID badge, and cast.
- Search field named
-
Section Fixing & SEND Action:
- Selecting a movie fixes / locks both Section 1 and Section 2.
- A prominent SEND button appears.
- Clicking SEND triggers
POST http://localhost:8000/downloadwith JSON:{ "magnet": "magnet:?xt=urn:btih:...", "imdbid": "tt0156887" } - Displays live success or error feedback directly on the page.
📁 Project Structure
├── manifest.json # WebExtension manifest (Firefox & cross-browser)
├── background.js # Background event handler (storage, tabs, API proxy)
├── content.js # Injected script hooking magnet clicks & showing modal
├── content.css # Content script styling
├── popup.html / js / css # Browser toolbar popup
├── app.html / js / css # Main pairing page (two sections, IMDb search, SEND)
├── test_page.html # Test page with sample magnet links
├── icons/ # Extension icons (16, 48, 128)
└── dummy_api/ # FastAPI backend
├── src/dummy_api/main.py
└── pyproject.toml
🛠️ Step-by-Step Testing Guide
1. Start the FastAPI Backend
In your terminal:
cd dummy_api
./.venv/bin/python -m uvicorn dummy_api.main:app --port 8000 --reload
FastAPI will start listening at http://127.0.0.1:8000. You can test it via curl:
curl -X POST http://localhost:8000/download \
-H "Content-Type: application/json" \
-d '{"magnet": "magnet:?xt=urn:btih:1234567890abcdef1234567890abcdef12345678", "imdbid": "tt0156887"}'
2. Load the Extension in Firefox
- Open Firefox and navigate to:
about:debugging#/runtime/this-firefox - Click "Load Temporary Add-on..."
- Select the
manifest.jsonfile insidemagnetflix-extension/. - The extension Magnetflix will now be loaded!
(Alternatively, you can run npx web-ext run in the root folder to launch Firefox with the extension preloaded).
3. Test the Workflow
- In Firefox, open the test page:
file:///home/kiskaadee/Projects/learning/extensions/magnetflix-extension/test_page.html - Click on any of the magnet links (e.g. Perfect Blue (1997)).
- The in-page popup modal will appear:
- Notice the "Magnet link captured!" message.
- Click the Continue button.
- A new tab opens with
app.htmlpre-populated with your captured magnet link in Section 1. - In Section 2 (Movie), type in the search field (e.g.
perfect blue 1997orblack swanortt0156887). - Notice the dynamic search updating on keystrokes and displaying the top 5 IMDb matches.
- Click on any movie card to select it:
- Notice both sections become fixed / locked.
- The SEND button appears.
- Click SEND:
- The request is dispatched to
http://localhost:8000/download. - The success response
{"message": "download started"}is displayed on screen!
- The request is dispatched to