# 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 1. **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`). 2. **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. 3. **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/download` with JSON: ```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: ```bash 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: ```bash 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 1. Open Firefox and navigate to: ```text about:debugging#/runtime/this-firefox ``` 2. Click **"Load Temporary Add-on..."** 3. Select the `manifest.json` file inside `magnetflix-extension/`. 4. 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 1. In Firefox, open the test page: ```text file:///home/kiskaadee/Projects/learning/extensions/magnetflix-extension/test_page.html ``` 2. Click on any of the magnet links (e.g. **Perfect Blue (1997)**). 3. The in-page popup modal will appear: - Notice the **"Magnet link captured!"** message. - Click the **Continue** button. 4. A new tab opens with `app.html` pre-populated with your captured magnet link in **Section 1**. 5. In **Section 2 (Movie)**, type in the search field (e.g. `perfect blue 1997` or `black swan` or `tt0156887`). 6. Notice the dynamic search updating on keystrokes and displaying the top 5 IMDb matches. 7. Click on any movie card to select it: - Notice both sections become fixed / locked. - The **SEND** button appears. 8. Click **SEND**: - The request is dispatched to `http://localhost:8000/download`. - The success response `{"message": "download started"}` is displayed on screen!