diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c8f9d71 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +NOSTR_PRIVATE_KEY = YOUR_NOSTR_PRIVATE_KEY_HERE \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3ec544c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +.env \ No newline at end of file diff --git a/README.md b/README.md index e8065ad..13d0316 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,9 @@ It’s built for freedom, experimentation, and creativity — turning simple cod FreeWave listens for Nostr events that start with a prefix like: +```bash PLAY_SONG: +``` Once received, it automatically: 1. Finds the song on YouTube. @@ -48,77 +50,125 @@ Before running FreeWave, make sure you have: ## Installation Guide ### 1️⃣ Clone the Repository -``bash +```bash git clone https://github.com//FreeWave.git cd FreeWave +``` -2️⃣ Install Dependencies - +### 2️⃣ Install Dependencies +``` npm install +npm install dotenv +``` -3️⃣ Install System Tools +### 3️⃣ Install System Tools -Ubuntu / Debian +### i) Ubuntu / Debian +```bash sudo apt update sudo apt install mpv pip install yt-dlp +``` -macOS +### ii) macOS +```bash brew install mpv yt-dlp +``` -Windows +### iii) Windows -Install Node.js from nodejs.org +Install `Node.js` from [nodejs.org](https://nodejs.org/en) Download yt-dlp.exe and mpv.exe, and add both to PATH +### 4️⃣ Setup Your Nostr Private Key + +#### Step 1 — Generate a private key + +In Node.js: + ```bash + node +> const { generateSecretKey, getPublicKey } = await import("nostr-tools"); +> const sk = generateSecretKey(); +> console.log("PRIVATE KEY (hex):", sk); +> console.log("PUBLIC KEY:", getPublicKey(sk)); +``` + +#### Step 2 — Save it in a .env file +FreeWave never stores your key in code. Use an environment variable instead. + +Rename the `.env.example` file to `.env`. You can find it in the project root folder. +```bash +FreeWave/ +├── scripts/ +│ ├── send-song-command.mjs +│ └── listen-and-play-song.mjs +├── package.json +├── .gitignore +├── .env.example +└── README.md +``` +Then, on the `.env` file, replace `YOUR_NOSTR_PRIVATE_KEY_HERE` with your nost private key +#### Step 3 — Verify +```bash +node -e "import('dotenv/config'); console.log(process.env.NOSTR_PRIVATE_KEY)" +``` +You should see your 64-character hex key printed. - Exporting Your Keys +### 5. Exporting Your Keys To protect privacy, FreeWave never stores your keys directly inside the script. Instead, export them as environment variables. Example: +```bash export NOSTR_PRIVKEY_HEX="your_private_key_here" +``` If you only have an nsec key, you can convert it to hex: +```bash node > const { nip19 } = await import("nostr-tools"); > const result = nip19.decode("nsec1yourkeyhere"); > console.log(Buffer.from(result.data).toString("hex")); +``` Then export the result again: +```bash export NOSTR_PRIVKEY_HEX="converted_hex_key_here" +``` Now your scripts can access it automatically! - - Usage +## Usage Send a Song Command +```bash npm run send-song "Blinding Lights by The Weeknd" +``` Start the Listener +```bash npm run start-listener +``` FreeWave will automatically detect your Nostr commands, download, play, and clean up after itself. - - Folder Structure - + #### Folder Structure: +```bash FreeWave/ ├── scripts/ │ ├── send-song-command.mjs @@ -126,49 +176,47 @@ FreeWave/ ├── package.json ├── .gitignore └── README.md +``` - - - Gadgets & Hardware Setup (Optional) +## Gadgets & Hardware Setup (Optional) You can go beyond the terminal — build your own FreeWave Node! -Gadget Purpose / Use +| Gadget | Purpose / Use | +|---------------------------|--------------------------------------------------| +| Old Android Phone | Run FreeWave via Termux or Node.js as a portable Nostr node | +| Raspberry Pi (3 or 4) | 24/7 listener connected to a speaker or display | +| Arduino (ESP32 / ESP8266) | Control LEDs, buttons, or visual indicators | +| OLED / LCD Display | Show current track name, artist, or connection status | +| Bluetooth Speaker | Wireless music playback | +| RGB LEDs or Neopixels | Flash, pulse, or animate with the beat | +| Powerbank or UPS | Run your setup off-grid | +| WiFi Dongle / Ethernet | Ensure a stable connection | +| Buttons / Rotary Knob | Control play, pause, or skip directly | +| Mini Amplifier (PAM8403) | Boost small speaker setups | +| 3D-Printed Case | Make your node look like a futuristic jukebox | - Old Android Phone Run FreeWave via Termux or Node.js as a portable Nostr node - Raspberry Pi (3 or 4) 24/7 listener connected to a speaker or display - Arduino (ESP32 / ESP8266) Control LEDs, buttons, or visual indicators - OLED / LCD Display Show current track name, artist, or connection status - Bluetooth Speaker Wireless music playback - RGB LEDs or Neopixels Flash, pulse, or animate with the beat - Powerbank or UPS Run your setup off-grid - WiFi Dongle / Ethernet Ensure a stable connection - Buttons / Rotary Knob Control play, pause, or skip directly - Mini Amplifier (PAM8403) Boost small speaker setups - 3D-Printed Case Make your node look like a futuristic jukebox - How to Make It Interactive +## How to Make It Interactive Want to bring your FreeWave to life? -Use an ESP32 board to detect song events and light up LEDs. +- Use an ESP32 board to detect song events and light up LEDs. -Add an OLED display to show track titles and relay names. +- Add an OLED display to show track titles and relay names. -Control playback with buttons using simple serial commands. +- Control playback with buttons using simple serial commands. Your FreeWave becomes a smart, physical music player powered by Nostr! +### package.json (For Reference) ---- - - package.json (For Reference) - +```bash { "name": "freewave", "version": "1.0.0", @@ -186,30 +234,29 @@ Your FreeWave becomes a smart, physical music player powered by Nostr! "nostr-tools": "^2.17.2" } } +``` - - Contributing +## Contributing FreeWave is community-built — feel free to fork, open issues, or submit pull requests! -Ideas welcome: - -Add a GUI or web dashboard +## Ideas welcome: -Add LED sync effects +- Add a GUI or web dashboard -Integrate more Nostr event types +- Add LED sync effects -Create themed hardware builds +- Integrate more Nostr event types +- Create themed hardware builds -Credits +## Credits Developed by Martin Arts & contributors -Powered by Nostr, yt-dlp, and mpv +Powered by `Nostr`, `yt-dlp`, and `mpv` > “Let the music flow freely across the network — this is the wave of sound, not control.” diff --git a/scripts/send-song-command.mjs b/scripts/send-song-command.mjs index 5e6d5c3..1a2f393 100644 --- a/scripts/send-song-command.mjs +++ b/scripts/send-song-command.mjs @@ -1,8 +1,9 @@ // send-song-command.mjs import { Relay, getPublicKey, finalizeEvent } from "nostr-tools"; +import 'dotenv/config'; // ----------------- YOUR HEX PRIVATE KEY ----------------- -const myHexPrivKey = ""; +const myHexPrivKey = process.env.NOSTR_PRIVATE_KEY; // -------------------------------------------------------- // Get public key directly from hex