commit 9979697acf4572746525a6d9abc5111e2b347c37 Author: MrUnknownDE Date: Sun Dec 28 17:57:20 2025 +0100 first commit diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..f7a6170 --- /dev/null +++ b/.env.example @@ -0,0 +1,31 @@ +# Spotify API Credentials +# Get these from https://developer.spotify.com/dashboard/ +SPOTIFY_CLIENT_ID=your_spotify_client_id +SPOTIFY_CLIENT_SECRET=your_spotify_client_secret + +# YouTube/Google API Credentials +# Get these from https://console.cloud.google.com/ +# Enable "YouTube Data API v3" and create OAuth 2.0 credentials +YOUTUBE_CLIENT_ID=your_youtube_client_id +YOUTUBE_CLIENT_SECRET=your_youtube_client_secret + +# Session Secret (generate a random string) +SESSION_SECRET=your_random_session_secret_here + +# Server Port +PORT=3000 + +# Base URL (used for OAuth callbacks) +# IMPORTANT: Spotify requires HTTPS for callbacks! +# For local development, use a tool like local-ssl-proxy or ngrok +BASE_URL=https://localhost:3000 + +# Cache Settings +# Path where analysis jobs are cached (relative or absolute) +CACHE_PATH=./cache +# Maximum playlist size (tracks) that can be analyzed +MAX_PLAYLIST_SIZE=50 + +# Rate Limiting +# Delay between YouTube API calls in milliseconds +RATE_LIMIT_DELAY_MS=2000 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3224a90 --- /dev/null +++ b/.gitignore @@ -0,0 +1,144 @@ +# Created by https://www.toptal.com/developers/gitignore/api/node +# Edit at https://www.toptal.com/developers/gitignore?templates=node + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional stylelint cache +.stylelintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variable files +.env +.env.development.local +.env.test.local +.env.production.local +.env.local + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# vuepress v2.x temp and cache directory +.temp + +# Docusaurus cache and generated files +.docusaurus + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Node Patch ### +# Serverless Webpack directories +.webpack/ + +# Optional stylelint cache + +# SvelteKit build / generate output +.svelte-kit + +# End of https://www.toptal.com/developers/gitignore/api/node \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..eab78ef --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:22-alpine + +WORKDIR /app + +# Copy package files +COPY package*.json ./ + +# Install dependencies +RUN npm install --omit=dev + +# Copy source code +COPY src/ ./src/ + +# Expose port +EXPOSE 3000 + +# Start the application +CMD ["node", "src/server.js"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..b46f3d5 --- /dev/null +++ b/README.md @@ -0,0 +1,155 @@ +# Spotify to YouTube Music Migration Tool + +A Node.js web application that migrates your Spotify playlists to YouTube Music with a preview and review workflow. + +## โœจ Features + +- ๐Ÿ” **OAuth Login** - Secure authentication for Spotify and YouTube +- ๐Ÿ“‹ **Playlist Browser** - View and select your Spotify playlists +- ๐Ÿ” **Analysis Queue** - Pre-analyze tracks before migration with rate limiting +- ๐Ÿ‘€ **Review & Edit** - Side-by-side comparison of matches, add manual links for missing tracks +- ๐Ÿ”„ **Real-time Progress** - Live updates via Server-Sent Events +- ๐Ÿ’พ **Persistent Cache** - Search results cached to disk, survives restarts +- ๐Ÿ“Š **Quota Optimization** - Rate limiting and caching to preserve YouTube API quota +- ๐ŸŽจ **Modern UI** - Dark theme with glassmorphism design +- ๐Ÿณ **Docker Ready** - Easy deployment with Docker Compose + +## ๐Ÿ“‹ Prerequisites + +### 1. Spotify API Credentials + +1. Go to [Spotify Developer Dashboard](https://developer.spotify.com/dashboard/) +2. Create a new application +3. Add `http://localhost:3000/auth/spotify/callback` to Redirect URIs +4. Copy your **Client ID** and **Client Secret** + +### 2. YouTube/Google API Credentials + +1. Go to [Google Cloud Console](https://console.cloud.google.com/) +2. Create a new project (or select existing) +3. Enable **YouTube Data API v3** +4. Go to **Credentials** โ†’ **Create Credentials** โ†’ **OAuth 2.0 Client ID** +5. Configure OAuth consent screen (External, add your email as test user) +6. Create OAuth client ID (Web application) +7. Add `http://localhost:3000/auth/youtube/callback` to Authorized redirect URIs +8. Copy your **Client ID** and **Client Secret** + +## ๐Ÿš€ Setup + +### Option 1: Local Development + +```bash +# Clone and enter directory +cd sptify2yt + +# Install dependencies +npm install + +# Copy environment template and add your API credentials +cp .env.example .env +nano .env # or use your preferred editor + +# Start the server +npm start +``` + +Open http://localhost:3000 in your browser. + +### Option 2: Docker + +```bash +# Copy and configure environment +cp .env.example .env +nano .env + +# Build and run +docker compose up -d +``` + +Open http://localhost:3000 in your browser. + +## โš™๏ธ Configuration + +All settings are configured via environment variables (`.env` file): + +| Variable | Default | Description | +|----------|---------|-------------| +| `SPOTIFY_CLIENT_ID` | - | Spotify OAuth Client ID | +| `SPOTIFY_CLIENT_SECRET` | - | Spotify OAuth Client Secret | +| `YOUTUBE_CLIENT_ID` | - | Google OAuth Client ID | +| `YOUTUBE_CLIENT_SECRET` | - | Google OAuth Client Secret | +| `SESSION_SECRET` | - | Random string for session encryption | +| `PORT` | `3000` | Server port | +| `BASE_URL` | `http://localhost:3000` | Base URL for OAuth callbacks | +| `CACHE_PATH` | `./cache` | Directory for persistent cache | +| `MAX_PLAYLIST_SIZE` | `500` | Maximum tracks per playlist | +| `RATE_LIMIT_DELAY_MS` | `2000` | Delay between YouTube API calls (ms) | + +## ๐Ÿ“– Usage + +### Workflow + +1. **Login** - Connect your Spotify and YouTube accounts +2. **Select Playlist** - Choose a Spotify playlist to migrate +3. **Analyze** - Click "Analyze Playlist" to search for YouTube matches +4. **Review** - View side-by-side comparison: + - โœ… **Found** - Track matched on YouTube + - โŒ **Not found** - Add a manual YouTube link +5. **Migrate** - Start the migration to create the YouTube playlist + +### Caching + +The app uses two levels of caching: + +1. **Analysis Jobs** - Complete analysis results saved to `./cache/job_*.json` +2. **Search Cache** - Individual YouTube search results saved to `./cache/search_cache.json` + +Search results are cached for 30 days. If you analyze the same track again (even in a different playlist), it uses the cached result without making a new API call. + +## ๐Ÿ“Š YouTube API Quota + +YouTube Data API has a daily quota of **10,000 units**. Each search costs ~100 units, allowing approximately **100 searches per day**. + +### How this app optimizes quota: + +| Feature | Savings | +|---------|---------| +| **Search Cache** | Reuses results for duplicate tracks | +| **Rate Limiting** | 2s delay prevents burst usage | +| **Pre-Analysis** | Only searches once, migration uses cached data | +| **Manual Links** | Skip API calls for unknown tracks | + +## ๐Ÿ—‚๏ธ Project Structure + +``` +sptify2yt/ +โ”œโ”€โ”€ src/ +โ”‚ โ”œโ”€โ”€ server.js # Express server with SSE +โ”‚ โ”œโ”€โ”€ routes/ +โ”‚ โ”‚ โ”œโ”€โ”€ auth.js # OAuth routes +โ”‚ โ”‚ โ”œโ”€โ”€ spotify.js # Spotify API routes +โ”‚ โ”‚ โ””โ”€โ”€ youtube.js # YouTube API + migration +โ”‚ โ”œโ”€โ”€ services/ +โ”‚ โ”‚ โ”œโ”€โ”€ analysisQueue.js # Job queue with persistence +โ”‚ โ”‚ โ””โ”€โ”€ searchCache.js # YouTube search cache +โ”‚ โ””โ”€โ”€ public/ +โ”‚ โ”œโ”€โ”€ index.html # SPA frontend +โ”‚ โ”œโ”€โ”€ styles.css # Dark theme styles +โ”‚ โ””โ”€โ”€ app.js # Frontend logic +โ”œโ”€โ”€ cache/ # Persistent cache (auto-created) +โ”œโ”€โ”€ .env.example # Environment template +โ”œโ”€โ”€ Dockerfile +โ”œโ”€โ”€ docker-compose.yml +โ””โ”€โ”€ package.json +``` + +## โš ๏ธ Notes + +- **YouTube Music Playlists** - YouTube and YouTube Music share playlists, so migrated playlists appear in both +- **Track Matching** - Searches for "Artist - Track Name" in YouTube's Music category +- **Manual Links** - For rare/unavailable tracks, paste any YouTube video URL +- **Cache Cleanup** - Jobs older than 7 days and search results older than 30 days are automatically cleaned up + +## ๐Ÿ“„ License + +MIT diff --git a/cache/job_1766940808819_at6tdppx0.json b/cache/job_1766940808819_at6tdppx0.json new file mode 100644 index 0000000..27bff38 --- /dev/null +++ b/cache/job_1766940808819_at6tdppx0.json @@ -0,0 +1,134 @@ +{ + "id": "job_1766940808819_at6tdppx0", + "sessionId": "session_1766940791190_wjvz0ueby", + "playlist": { + "id": "6EmJB6Dtfrk54qBMJzyEHx", + "name": "pfank repeat", + "image": "https://mosaic.scdn.co/640/ab67616d00001e027e44b3c24e2bdef9928ce6c2ab67616d00001e02d43e8f24d477790a78c7b58fab67616d00001e02d5c0a5bc4afd1d9d16cac98eab67616d00001e02e908735737ca3e20be619da1" + }, + "tracks": [ + { + "spotifyId": "3f9RTvoln0k1FnIS5edKqD", + "name": "EASY PEAZY - Slowed & Reverb", + "artists": [ + "ROMANTICA", + "Lestmor" + ], + "album": "EASY PEAZY (Slowed & Sped Up)", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + }, + { + "spotifyId": "1yqaea9PLO8rttUlcNTlcB", + "name": "Komarovo (DVRST Phonk Remix)", + "artists": [ + "DVRST", + "Igor Sklyar", + "Atomic Heart" + ], + "album": "Atomic Heart (Original Game Soundtrack) Vol.1", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + }, + { + "spotifyId": "0C6DzlnpBBZ4T5KFFtNNQI", + "name": "STUCK IN A DAZE - SLOWED", + "artists": [ + "SHIIIKARNO" + ], + "album": "STUCK IN A DAZE (SLOWED)", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + }, + { + "spotifyId": "7ItZPW34p9g5hEBCRw5GOK", + "name": "Yours", + "artists": [ + "EVILDXER" + ], + "album": "Yours", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + }, + { + "spotifyId": "25u4PT1CAUcHwe3YQ3JfrH", + "name": "sorry mom, i'm making breakcore xd", + "artists": [ + "usedcvnt" + ], + "album": "ultraviolet", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + }, + { + "spotifyId": "0WVwOSGn9J8Ccq5wuBDLmJ", + "name": "143 ways to lose urself", + "artists": [ + "usedcvnt" + ], + "album": "ultraviolet", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + }, + { + "spotifyId": "0MFl9YQsAgxpBtEpXK8UA1", + "name": "wonderfulcore", + "artists": [ + "usedcvnt" + ], + "album": "wonderfulcore", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + }, + { + "spotifyId": "2p3LCdEMlQgs2ciXS3KIlM", + "name": "wake up Violet", + "artists": [ + "usedcvnt" + ], + "album": "wonderfulcore", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + }, + { + "spotifyId": "1e6ZXuLRtWnXhwvJftJYuB", + "name": "EASY PEAZY", + "artists": [ + "ROMANTICA", + "Lestmor" + ], + "album": "EASY PEAZY", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + }, + { + "spotifyId": "5Y4OwloGr9QSxZLZ5DXGte", + "name": "Broken Trust", + "artists": [ + "SAY3AM", + "Staarz" + ], + "album": "Broken Trust", + "youtubeMatch": null, + "manualVideoId": null, + "status": "not_found" + } + ], + "status": "complete", + "progress": { + "current": 10, + "total": 10 + }, + "createdAt": 1766940808819, + "completedAt": 1766940827781, + "error": null +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1e06a5f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + app: + build: . + ports: + - "${PORT:-3000}:3000" + env_file: + - .env + environment: + - NODE_ENV=production + restart: unless-stopped diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..39eae74 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1459 @@ +{ + "name": "sptify2yt", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "sptify2yt", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "axios": "^1.7.9", + "dotenv": "^16.4.7", + "express": "^4.21.2", + "express-session": "^1.18.1", + "googleapis": "^144.0.0", + "spotify-web-api-node": "^5.0.2" + }, + "engines": { + "node": ">=22.0.0" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/agent-base": { + "version": "7.1.4", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", + "integrity": "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ==", + "license": "MIT", + "engines": { + "node": ">= 14" + } + }, + "node_modules/array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==", + "license": "MIT" + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" + }, + "node_modules/axios": { + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.2.tgz", + "integrity": "sha512-VPk9ebNqPcy5lRGuSlKx752IlDatOjT9paPlm8A7yOuW2Fbvp4X3JznJtT4f0GzGLLiWE9W8onz51SqLYwzGaA==", + "license": "MIT", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.4", + "proxy-from-env": "^1.1.0" + } + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/bignumber.js": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.3.1.tgz", + "integrity": "sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==", + "license": "MIT", + "engines": { + "node": "*" + } + }, + "node_modules/body-parser": { + "version": "1.20.4", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.4.tgz", + "integrity": "sha512-ZTgYYLMOXY9qKU/57FAo8F+HA2dGX7bqGc71txDRC1rS4frdFI5R7NhluHxH6M0YItAP0sHB4uqAOcYKxO6uGA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "~1.2.0", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "on-finished": "~2.4.1", + "qs": "~6.14.0", + "raw-body": "~2.5.3", + "type-is": "~1.6.18", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/buffer-equal-constant-time": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", + "integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==", + "license": "BSD-3-Clause" + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/component-emitter": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.1.tgz", + "integrity": "sha512-T0+barUSQRTUQASh8bx02dl+DhF54GtIDY13Y3m9oWTklKbb3Wv974meRpeZ3lp1JpLVECWWNHC4vaG2XHXouQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/content-disposition": { + "version": "0.5.4", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", + "integrity": "sha512-FveZTNuGw04cxlAiWbzi6zTAL/lhehaWbTtgluJh4/E95DqMwTmha3KZN1aAWA8cFIhHzMZUvLevkw5Rqk+tSQ==", + "license": "MIT", + "dependencies": { + "safe-buffer": "5.2.1" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.7.tgz", + "integrity": "sha512-NXdYc3dLr47pBkpUCHtKSwIOQXLVn8dZEuywboCOJY/osA0wFSLlSawr3KN8qXJEyX66FcONTH8EIlVuK0yyFA==", + "license": "MIT" + }, + "node_modules/cookiejar": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", + "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==", + "license": "MIT" + }, + "node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/dotenv": { + "version": "16.6.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.6.1.tgz", + "integrity": "sha512-uBq4egWHTcTt33a72vpSG0z3HnPuIl6NqYcTrKEg2azoEyl2hpW0zqlxysq2pK9HlDIHyHyakeYaYnSAwd8bow==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ecdsa-sig-formatter": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", + "integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/express": { + "version": "4.22.1", + "resolved": "https://registry.npmjs.org/express/-/express-4.22.1.tgz", + "integrity": "sha512-F2X8g9P1X7uCPZMA3MVf9wcTqlyNp7IhH5qPCI0izhaOIYXaW9L535tGA3qmjRzpH+bZczqq7hVKxTR4NWnu+g==", + "license": "MIT", + "dependencies": { + "accepts": "~1.3.8", + "array-flatten": "1.1.1", + "body-parser": "~1.20.3", + "content-disposition": "~0.5.4", + "content-type": "~1.0.4", + "cookie": "~0.7.1", + "cookie-signature": "~1.0.6", + "debug": "2.6.9", + "depd": "2.0.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "~1.3.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.0", + "merge-descriptors": "1.0.3", + "methods": "~1.1.2", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "path-to-regexp": "~0.1.12", + "proxy-addr": "~2.0.7", + "qs": "~6.14.0", + "range-parser": "~1.2.1", + "safe-buffer": "5.2.1", + "send": "~0.19.0", + "serve-static": "~1.16.2", + "setprototypeof": "1.2.0", + "statuses": "~2.0.1", + "type-is": "~1.6.18", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express-session": { + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/express-session/-/express-session-1.18.2.tgz", + "integrity": "sha512-SZjssGQC7TzTs9rpPDuUrR23GNZ9+2+IkA/+IJWmvQilTr5OSliEHGF+D9scbIpdC6yGtTI0/VhaHoVes2AN/A==", + "license": "MIT", + "dependencies": { + "cookie": "0.7.2", + "cookie-signature": "1.0.7", + "debug": "2.6.9", + "depd": "~2.0.0", + "on-headers": "~1.1.0", + "parseurl": "~1.3.3", + "safe-buffer": "5.2.1", + "uid-safe": "~2.1.5" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "license": "MIT" + }, + "node_modules/fast-safe-stringify": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", + "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==", + "license": "MIT" + }, + "node_modules/finalhandler": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.3.2.tgz", + "integrity": "sha512-aA4RyPcd3badbdABGDuTXCMTtOneUCAYH/gxoYRTZlIJdF0YPWuGqiAsIrhNnnqdXGswYk6dGujem4w80UJFhg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "on-finished": "~2.4.1", + "parseurl": "~1.3.3", + "statuses": "~2.0.2", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.11", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.11.tgz", + "integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==", + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], + "license": "MIT", + "engines": { + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } + } + }, + "node_modules/form-data": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.5.tgz", + "integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/formidable": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.2.6.tgz", + "integrity": "sha512-KcpbcpuLNOwrEjnbpMC0gS+X8ciDoZE1kkqzat4a8vrprf+s9pKNQ/QIwWfbfs4ltgmFl3MD177SNTkve3BwGQ==", + "deprecated": "Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau", + "license": "MIT", + "funding": { + "url": "https://ko-fi.com/tunnckoCore/commissions" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gaxios": { + "version": "6.7.1", + "resolved": "https://registry.npmjs.org/gaxios/-/gaxios-6.7.1.tgz", + "integrity": "sha512-LDODD4TMYx7XXdpwxAVRAIAuB0bzv0s+ywFonY46k126qzQHT9ygyoa9tncmOiQmmDrik65UYsEkv3lbfqQ3yQ==", + "license": "Apache-2.0", + "dependencies": { + "extend": "^3.0.2", + "https-proxy-agent": "^7.0.1", + "is-stream": "^2.0.0", + "node-fetch": "^2.6.9", + "uuid": "^9.0.1" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/gcp-metadata": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-6.1.1.tgz", + "integrity": "sha512-a4tiq7E0/5fTjxPAaH4jpjkSv/uCaU2p5KC6HVGrvl0cDjA8iBZv4vv1gyzlmK0ZUKqwpOyQMKzZQe3lTit77A==", + "license": "Apache-2.0", + "dependencies": { + "gaxios": "^6.1.1", + "google-logging-utils": "^0.0.2", + "json-bigint": "^1.0.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/google-auth-library": { + "version": "9.15.1", + "resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-9.15.1.tgz", + "integrity": "sha512-Jb6Z0+nvECVz+2lzSMt9u98UsoakXxA2HGHMCxh+so3n90XgYWkq5dur19JAJV7ONiJY22yBTyJB1TSkvPq9Ng==", + "license": "Apache-2.0", + "dependencies": { + "base64-js": "^1.3.0", + "ecdsa-sig-formatter": "^1.0.11", + "gaxios": "^6.1.1", + "gcp-metadata": "^6.1.0", + "gtoken": "^7.0.0", + "jws": "^4.0.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/google-logging-utils": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/google-logging-utils/-/google-logging-utils-0.0.2.tgz", + "integrity": "sha512-NEgUnEcBiP5HrPzufUkBzJOD/Sxsco3rLNo1F1TNf7ieU8ryUzBhqba8r756CjLX7rn3fHl6iLEwPYuqpoKgQQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=14" + } + }, + "node_modules/googleapis": { + "version": "144.0.0", + "resolved": "https://registry.npmjs.org/googleapis/-/googleapis-144.0.0.tgz", + "integrity": "sha512-ELcWOXtJxjPX4vsKMh+7V+jZvgPwYMlEhQFiu2sa9Qmt5veX8nwXPksOWGGN6Zk4xCiLygUyaz7xGtcMO+Onxw==", + "license": "Apache-2.0", + "dependencies": { + "google-auth-library": "^9.0.0", + "googleapis-common": "^7.0.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/googleapis-common": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/googleapis-common/-/googleapis-common-7.2.0.tgz", + "integrity": "sha512-/fhDZEJZvOV3X5jmD+fKxMqma5q2Q9nZNSF3kn1F18tpxmA86BcTxAGBQdM0N89Z3bEaIs+HVznSmFJEAmMTjA==", + "license": "Apache-2.0", + "dependencies": { + "extend": "^3.0.2", + "gaxios": "^6.0.3", + "google-auth-library": "^9.7.0", + "qs": "^6.7.0", + "url-template": "^2.0.8", + "uuid": "^9.0.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gtoken": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-7.1.0.tgz", + "integrity": "sha512-pCcEwRi+TKpMlxAQObHDQ56KawURgyAf6jtIY046fJ5tIv3zDe/LEIubckAO8fj6JnAxLdmWkUfNyulQ2iKdEw==", + "license": "MIT", + "dependencies": { + "gaxios": "^6.0.0", + "jws": "^4.0.0" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "license": "MIT", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/https-proxy-agent": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", + "license": "MIT", + "dependencies": { + "agent-base": "^7.1.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/https-proxy-agent/node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/https-proxy-agent/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "license": "MIT", + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/json-bigint": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz", + "integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==", + "license": "MIT", + "dependencies": { + "bignumber.js": "^9.0.0" + } + }, + "node_modules/jwa": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz", + "integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==", + "license": "MIT", + "dependencies": { + "buffer-equal-constant-time": "^1.0.1", + "ecdsa-sig-formatter": "1.0.11", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/jws": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/jws/-/jws-4.0.1.tgz", + "integrity": "sha512-EKI/M/yqPncGUUh44xz0PxSidXFr/+r0pA70+gIYhjv+et7yxM+s29Y+VGDkovRofQem0fs7Uvf4+YmAdyRduA==", + "license": "MIT", + "dependencies": { + "jwa": "^2.0.1", + "safe-buffer": "^5.0.1" + } + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/merge-descriptors": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.3.tgz", + "integrity": "sha512-gaNvAS7TZ897/rVaZ0nMtAyxNyi/pdbjbAwUpFQpN70GqnVfOiXpeUUMKRBmzXaSQ8DdTX4/0ms62r2K+hE6mQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha512-iclAHeNqNm68zFtnZ0e+1L2yUIdvzNoauKU4WBA3VvH/vPFieF7qfRlwUZU+DA9P9bPXIS90ulxoUoCH23sV2w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/on-headers": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.1.0.tgz", + "integrity": "sha512-737ZY3yNnXy37FHkQxPzt4UZ2UWPWiCZWLvFZ4fu5cueciegX0zGPnrlY6bwRg4FdQOe9YU8MkmJwGhoMybl8A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-to-regexp": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.12.tgz", + "integrity": "sha512-RA1GjUVMnvYFxuqovrEqZoxxW5NUZqbwKtYz/Tt7nXerk0LbLblQmrsgdeOxV5SFHf0UDggjS/bSeOZwt1pmEQ==", + "license": "MIT" + }, + "node_modules/proxy-addr": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.7.tgz", + "integrity": "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" + }, + "node_modules/qs": { + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.14.0.tgz", + "integrity": "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w==", + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.1.0" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/random-bytes": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/random-bytes/-/random-bytes-1.0.0.tgz", + "integrity": "sha512-iv7LhNVO047HzYR3InF6pUcUsPQiHTM1Qal51DcGSuZFBil1aBBWG5eHPNek7bvILMaYJ/8RU1e8w1AMdHmLQQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/raw-body": { + "version": "2.5.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.3.tgz", + "integrity": "sha512-s4VSOf6yN0rvbRZGxs8Om5CWj6seneMwK3oDb4lWDH0UPhWcxwOWw5+qk24bxq87szX1ydrwylIOp2uG1ojUpA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.4.24", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/semver": { + "version": "7.7.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.3.tgz", + "integrity": "sha512-SdsKMrI9TdgjdweUSR9MweHA4EJ8YxHn8DFaDisvhVlUOe4BF1tLD7GAj0lIqWVl+dPb/rExr0Btby5loQm20Q==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/send": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.2.tgz", + "integrity": "sha512-VMbMxbDeehAxpOtWJXlcUS5E8iXh6QmN+BkRX1GARS3wRaXEEgzCcB10gTQazO42tpNIya8xIyNx8fll1OFPrg==", + "license": "MIT", + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "~0.5.2", + "http-errors": "~2.0.1", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "~2.4.1", + "range-parser": "~1.2.1", + "statuses": "~2.0.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/serve-static": { + "version": "1.16.3", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.3.tgz", + "integrity": "sha512-x0RTqQel6g5SY7Lg6ZreMmsOzncHFU7nhnRWkKgWuMTu5NN0DR5oruckMqRvacAN9d5w6ARnRBXl9xhDCgfMeA==", + "license": "MIT", + "dependencies": { + "encodeurl": "~2.0.0", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "~0.19.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/side-channel": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/spotify-web-api-node": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/spotify-web-api-node/-/spotify-web-api-node-5.0.2.tgz", + "integrity": "sha512-r82dRWU9PMimHvHEzL0DwEJrzFk+SMCVfq249SLt3I7EFez7R+jeoKQd+M1//QcnjqlXPs2am4DFsGk8/GCsrA==", + "license": "MIT", + "dependencies": { + "superagent": "^6.1.0" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/superagent": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/superagent/-/superagent-6.1.0.tgz", + "integrity": "sha512-OUDHEssirmplo3F+1HWKUrUjvnQuA+nZI6i/JJBdXb5eq9IyEQwPyPpqND+SSsxf6TygpBEkUjISVRN4/VOpeg==", + "deprecated": "Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net", + "license": "MIT", + "dependencies": { + "component-emitter": "^1.3.0", + "cookiejar": "^2.1.2", + "debug": "^4.1.1", + "fast-safe-stringify": "^2.0.7", + "form-data": "^3.0.0", + "formidable": "^1.2.2", + "methods": "^1.1.2", + "mime": "^2.4.6", + "qs": "^6.9.4", + "readable-stream": "^3.6.0", + "semver": "^7.3.2" + }, + "engines": { + "node": ">= 7.0.0" + } + }, + "node_modules/superagent/node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/superagent/node_modules/form-data": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.4.tgz", + "integrity": "sha512-f0cRzm6dkyVYV3nPoooP8XlccPQukegwhAnpoLcXy+X+A8KfpGOoXwDr9FLZd3wzgLaBGQBE3lY93Zm/i1JvIQ==", + "license": "MIT", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", + "hasown": "^2.0.2", + "mime-types": "^2.1.35" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/superagent/node_modules/mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/superagent/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, + "node_modules/type-is": { + "version": "1.6.18", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", + "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", + "license": "MIT", + "dependencies": { + "media-typer": "0.3.0", + "mime-types": "~2.1.24" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/uid-safe": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/uid-safe/-/uid-safe-2.1.5.tgz", + "integrity": "sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==", + "license": "MIT", + "dependencies": { + "random-bytes": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/url-template": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/url-template/-/url-template-2.0.8.tgz", + "integrity": "sha512-XdVKMF4SJ0nP/O7XIPB0JwAEuT9lDIYnNsK8yGVe43y0AWoKeJNdv3ZNWh7ksJ6KqQFjOO6ox/VEitLnaVNufw==", + "license": "BSD" + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "license": "MIT" + }, + "node_modules/utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..549edd7 --- /dev/null +++ b/package.json @@ -0,0 +1,31 @@ +{ + "name": "sptify2yt", + "version": "1.0.0", + "description": "Migrate Spotify playlists to YouTube Music", + "main": "src/server.js", + "type": "module", + "engines": { + "node": ">=22.0.0" + }, + "scripts": { + "start": "node src/server.js", + "dev": "node --watch src/server.js" + }, + "dependencies": { + "axios": "^1.7.9", + "dotenv": "^16.4.7", + "express": "^4.21.2", + "express-session": "^1.18.1", + "googleapis": "^144.0.0", + "spotify-web-api-node": "^5.0.2" + }, + "keywords": [ + "spotify", + "youtube", + "music", + "migration", + "playlist" + ], + "author": "", + "license": "MIT" +} diff --git a/src/public/app.js b/src/public/app.js new file mode 100644 index 0000000..8f5eda1 --- /dev/null +++ b/src/public/app.js @@ -0,0 +1,488 @@ +// State +let authStatus = { spotify: { connected: false }, youtube: { connected: false } }; +let playlists = []; +let selectedPlaylist = null; +let selectedTracks = []; +let currentJob = null; +let eventSource = null; + +// Generate unique session ID +const sessionId = `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; + +// Elements +const loginView = document.getElementById('loginView'); +const playlistView = document.getElementById('playlistView'); +const analysisView = document.getElementById('analysisView'); +const progressView = document.getElementById('progressView'); + +const spotifyLoginBtn = document.getElementById('spotifyLoginBtn'); +const youtubeLoginBtn = document.getElementById('youtubeLoginBtn'); +const spotifyStatus = document.getElementById('spotifyStatus'); +const youtubeStatus = document.getElementById('youtubeStatus'); +const continueBtn = document.getElementById('continueBtn'); +const logoutBtn = document.getElementById('logoutBtn'); + +const playlistGrid = document.getElementById('playlistGrid'); +const backFromAnalysis = document.getElementById('backFromAnalysis'); +const analysisPlaylistImage = document.getElementById('analysisPlaylistImage'); +const analysisPlaylistName = document.getElementById('analysisPlaylistName'); +const analysisPlaylistCount = document.getElementById('analysisPlaylistCount'); +const startAnalysisBtn = document.getElementById('startAnalysisBtn'); + +const analysisProgress = document.getElementById('analysisProgress'); +const analysisStatusText = document.getElementById('analysisStatusText'); +const analysisProgressBar = document.getElementById('analysisProgressBar'); +const analysisCurrentTrack = document.getElementById('analysisCurrentTrack'); +const analysisResults = document.getElementById('analysisResults'); +const comparisonList = document.getElementById('comparisonList'); +const statFound = document.getElementById('statFound'); +const statNotFound = document.getElementById('statNotFound'); +const startMigrationBtn = document.getElementById('startMigrationBtn'); + +const progressCurrent = document.getElementById('progressCurrent'); +const progressTotal = document.getElementById('progressTotal'); +const progressBar = document.getElementById('progressBar'); +const currentTrackName = document.getElementById('currentTrackName'); +const progressLog = document.getElementById('progressLog'); +const migrationComplete = document.getElementById('migrationComplete'); +const completeStats = document.getElementById('completeStats'); +const playlistLink = document.getElementById('playlistLink'); +const newMigrationBtn = document.getElementById('newMigrationBtn'); + +// Initialize +document.addEventListener('DOMContentLoaded', init); + +async function init() { + await checkAuthStatus(); + setupEventListeners(); + setupSSE(); + handleUrlParams(); +} + +function setupEventListeners() { + spotifyLoginBtn.addEventListener('click', () => window.location.href = '/auth/spotify'); + youtubeLoginBtn.addEventListener('click', () => window.location.href = '/auth/youtube'); + continueBtn.addEventListener('click', showPlaylistView); + logoutBtn.addEventListener('click', logout); + backFromAnalysis.addEventListener('click', () => showView('playlist')); + startAnalysisBtn.addEventListener('click', startAnalysis); + startMigrationBtn.addEventListener('click', startMigration); + newMigrationBtn.addEventListener('click', () => { + showView('playlist'); + loadPlaylists(); + }); +} + +function setupSSE() { + eventSource = new EventSource(`/api/progress/${sessionId}`); + + eventSource.onmessage = (event) => { + const data = JSON.parse(event.data); + handleProgressUpdate(data); + }; + + eventSource.onerror = () => { + console.log('SSE connection error, reconnecting...'); + setTimeout(setupSSE, 5000); + }; +} + +function handleUrlParams() { + const params = new URLSearchParams(window.location.search); + if (params.get('error')) { + alert('Authentication failed. Please try again.'); + } + if (params.toString()) { + window.history.replaceState({}, '', '/'); + } +} + +// Auth +async function checkAuthStatus() { + try { + const response = await fetch('/auth/status'); + authStatus = await response.json(); + updateAuthUI(); + } catch (err) { + console.error('Failed to check auth status:', err); + } +} + +function updateAuthUI() { + const spotifyIndicator = spotifyStatus.querySelector('.status-indicator'); + const spotifyText = spotifyStatus.querySelector('.status-text'); + + if (authStatus.spotify.connected) { + spotifyIndicator.classList.add('connected'); + spotifyText.textContent = `Connected as ${authStatus.spotify.user?.name || 'User'}`; + spotifyLoginBtn.textContent = 'โœ“ Connected'; + spotifyLoginBtn.disabled = true; + } else { + spotifyIndicator.classList.remove('connected'); + spotifyText.textContent = 'Not connected'; + spotifyLoginBtn.textContent = 'Login with Spotify'; + spotifyLoginBtn.disabled = false; + } + + const youtubeIndicator = youtubeStatus.querySelector('.status-indicator'); + const youtubeText = youtubeStatus.querySelector('.status-text'); + + if (authStatus.youtube.connected) { + youtubeIndicator.classList.add('connected'); + youtubeText.textContent = `Connected as ${authStatus.youtube.user?.name || 'User'}`; + youtubeLoginBtn.textContent = 'โœ“ Connected'; + youtubeLoginBtn.disabled = true; + } else { + youtubeIndicator.classList.remove('connected'); + youtubeText.textContent = 'Not connected'; + youtubeLoginBtn.textContent = 'Login with YouTube'; + youtubeLoginBtn.disabled = false; + } + + if (authStatus.spotify.connected && authStatus.youtube.connected) { + continueBtn.style.display = 'inline-flex'; + logoutBtn.style.display = 'inline-flex'; + } else { + continueBtn.style.display = 'none'; + logoutBtn.style.display = 'none'; + } +} + +async function logout() { + try { + await fetch('/auth/logout', { method: 'POST' }); + authStatus = { spotify: { connected: false }, youtube: { connected: false } }; + updateAuthUI(); + showView('login'); + } catch (err) { + console.error('Logout failed:', err); + } +} + +// Views +function showView(view) { + loginView.style.display = view === 'login' ? 'block' : 'none'; + playlistView.style.display = view === 'playlist' ? 'block' : 'none'; + analysisView.style.display = view === 'analysis' ? 'block' : 'none'; + progressView.style.display = view === 'progress' ? 'block' : 'none'; +} + +async function showPlaylistView() { + showView('playlist'); + await loadPlaylists(); +} + +// Playlists +async function loadPlaylists() { + playlistGrid.innerHTML = '
Loading playlists...
'; + + try { + const response = await fetch('/api/spotify/playlists'); + if (!response.ok) throw new Error('Failed to load playlists'); + + playlists = await response.json(); + renderPlaylists(); + } catch (err) { + playlistGrid.innerHTML = '
Failed to load playlists. Please try again.
'; + console.error(err); + } +} + +function renderPlaylists() { + if (playlists.length === 0) { + playlistGrid.innerHTML = '
No playlists found.
'; + return; + } + + playlistGrid.innerHTML = playlists.map(playlist => ` +
+ ๐ŸŽต'}" alt="${escapeHtml(playlist.name)}"> +

${escapeHtml(playlist.name)}

+

${playlist.trackCount} tracks

+
+ `).join(''); + + document.querySelectorAll('.playlist-card').forEach(card => { + card.addEventListener('click', () => selectPlaylist(card.dataset.id)); + }); +} + +async function selectPlaylist(playlistId) { + selectedPlaylist = playlists.find(p => p.id === playlistId); + if (!selectedPlaylist) return; + + showView('analysis'); + + analysisPlaylistImage.src = selectedPlaylist.image || 'data:image/svg+xml,๐ŸŽต'; + analysisPlaylistName.textContent = selectedPlaylist.name; + analysisPlaylistCount.textContent = `${selectedPlaylist.trackCount} tracks`; + + // Reset analysis UI + analysisProgress.style.display = 'none'; + analysisResults.style.display = 'none'; + startAnalysisBtn.style.display = 'inline-flex'; + startAnalysisBtn.disabled = false; + comparisonList.innerHTML = ''; + currentJob = null; + + // Load tracks + try { + const response = await fetch(`/api/spotify/playlist/${playlistId}/tracks`); + if (!response.ok) throw new Error('Failed to load tracks'); + selectedTracks = await response.json(); + } catch (err) { + console.error('Failed to load tracks:', err); + selectedTracks = []; + } +} + +// Analysis +async function startAnalysis() { + if (!selectedPlaylist || selectedTracks.length === 0) return; + + startAnalysisBtn.disabled = true; + startAnalysisBtn.textContent = 'Analyzing...'; + analysisProgress.style.display = 'block'; + analysisResults.style.display = 'none'; + analysisProgressBar.style.width = '0%'; + analysisStatusText.textContent = 'Starting analysis...'; + + try { + const response = await fetch('/api/youtube/analyze', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + playlist: selectedPlaylist, + tracks: selectedTracks, + sessionId + }) + }); + + const result = await response.json(); + if (result.error) throw new Error(result.error); + + currentJob = { id: result.jobId }; + } catch (err) { + console.error('Analysis failed:', err); + analysisStatusText.textContent = 'Analysis failed. Please try again.'; + startAnalysisBtn.disabled = false; + startAnalysisBtn.textContent = '๐Ÿ” Analyze Playlist'; + } +} + +function handleProgressUpdate(data) { + switch (data.type) { + // Analysis updates + case 'analysis_progress': + analysisStatusText.textContent = `Searching YouTube... (${data.current}/${data.total})`; + analysisProgressBar.style.width = `${(data.current / data.total) * 100}%`; + analysisCurrentTrack.textContent = `${data.track.artists.join(', ')} - ${data.track.name}`; + break; + + case 'analysis_match': + // Update progress + analysisProgressBar.style.width = `${(data.current / data.total) * 100}%`; + break; + + case 'analysis_complete': + showAnalysisResults(data.stats); + break; + + // Migration updates + case 'status': + currentTrackName.textContent = data.message; + break; + + case 'playlist_created': + addLogItem('Playlist created on YouTube', 'success'); + break; + + case 'processing': + currentTrackName.textContent = `${data.track.artists.join(', ')} - ${data.track.name}`; + progressCurrent.textContent = data.current; + progressBar.style.width = `${(data.current / data.total) * 100}%`; + break; + + case 'track_added': + addLogItem(`โœ“ ${data.track}`, 'success'); + break; + + case 'track_failed': + case 'track_skipped': + addLogItem(`โœ— ${data.track} - Skipped`, 'not-found'); + break; + + case 'complete': + showMigrationComplete(data); + break; + + case 'error': + currentTrackName.textContent = `Error: ${data.message}`; + break; + } +} + +async function showAnalysisResults(stats) { + analysisProgress.style.display = 'none'; + startAnalysisBtn.style.display = 'none'; + analysisResults.style.display = 'block'; + + // Fetch full job data + try { + const response = await fetch(`/api/youtube/analysis/${currentJob.id}`); + const job = await response.json(); + currentJob = job; + + // Update stats + statFound.textContent = stats.found; + statNotFound.textContent = stats.notFound; + + // Render comparison table + renderComparisonTable(job.tracks); + } catch (err) { + console.error('Failed to fetch analysis results:', err); + } +} + +function renderComparisonTable(tracks) { + comparisonList.innerHTML = tracks.map((track, index) => ` +
+
+
${escapeHtml(track.name)}
+
${escapeHtml(track.artists.join(', '))}
+
+
+ ${track.status === 'found' ? 'โœ“ Found' : + track.status === 'manual' ? 'โœ“ Manual' : + 'โœ— Not found'} +
+
+ ${track.status === 'found' && track.youtubeMatch ? ` +
+ +
+
${escapeHtml(track.youtubeMatch.title)}
+
${escapeHtml(track.youtubeMatch.channel)}
+
+
+ ` : track.status === 'manual' && track.manualVideoId ? ` +
+ Manual: ${track.manualVideoId} +
+ ` : ` +
+ + +
+ `} +
+
+ `).join(''); + + // Add event listeners for manual inputs + document.querySelectorAll('.save-manual-btn').forEach(btn => { + btn.addEventListener('click', () => saveManualVideo(parseInt(btn.dataset.index))); + }); + + document.querySelectorAll('.manual-video-input').forEach(input => { + input.addEventListener('keypress', (e) => { + if (e.key === 'Enter') { + saveManualVideo(parseInt(input.dataset.index)); + } + }); + }); +} + +async function saveManualVideo(trackIndex) { + const input = document.querySelector(`.manual-video-input[data-index="${trackIndex}"]`); + const videoId = input.value.trim(); + + if (!videoId) return; + + try { + const response = await fetch(`/api/youtube/analysis/${currentJob.id}/track/${trackIndex}/manual`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ videoId }) + }); + + const result = await response.json(); + if (result.success) { + // Update local job data + currentJob.tracks[trackIndex].manualVideoId = result.videoId; + currentJob.tracks[trackIndex].status = 'manual'; + + // Re-render table + renderComparisonTable(currentJob.tracks); + + // Update stats + const found = currentJob.tracks.filter(t => t.status === 'found' || t.status === 'manual').length; + const notFound = currentJob.tracks.filter(t => t.status === 'not_found').length; + statFound.textContent = found; + statNotFound.textContent = notFound; + } + } catch (err) { + console.error('Failed to save manual video:', err); + } +} + +// Migration +async function startMigration() { + if (!currentJob) return; + + showView('progress'); + + progressCurrent.textContent = '0'; + progressTotal.textContent = currentJob.tracks.length; + progressBar.style.width = '0%'; + currentTrackName.textContent = 'Starting migration...'; + progressLog.innerHTML = ''; + migrationComplete.style.display = 'none'; + + // Show progress elements + document.querySelector('.progress-stats').style.display = 'block'; + document.querySelector('.progress-bar-container').style.display = 'block'; + document.querySelector('.current-track').style.display = 'flex'; + + try { + await fetch('/api/youtube/migrate', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + jobId: currentJob.id, + sessionId + }) + }); + } catch (err) { + console.error('Migration request failed:', err); + currentTrackName.textContent = 'Migration failed. Please try again.'; + } +} + +function addLogItem(text, type) { + const item = document.createElement('div'); + item.className = `log-item ${type}`; + item.textContent = text; + progressLog.appendChild(item); + progressLog.scrollTop = progressLog.scrollHeight; +} + +function showMigrationComplete(data) { + migrationComplete.style.display = 'block'; + completeStats.textContent = `${data.successCount} of ${data.total} tracks migrated successfully`; + playlistLink.href = data.playlistUrl; + + document.querySelector('.progress-stats').style.display = 'none'; + document.querySelector('.progress-bar-container').style.display = 'none'; + document.querySelector('.current-track').style.display = 'none'; +} + +// Helpers +function escapeHtml(text) { + const div = document.createElement('div'); + div.textContent = text; + return div.innerHTML; +} diff --git a/src/public/index.html b/src/public/index.html new file mode 100644 index 0000000..e75ffe7 --- /dev/null +++ b/src/public/index.html @@ -0,0 +1,185 @@ + + + + + + + + Spotify to YouTube Music | Playlist Migration + + + + + + + +
+ +
+ + +
+ + +
+ +
+ + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/src/public/styles.css b/src/public/styles.css new file mode 100644 index 0000000..5aeddce --- /dev/null +++ b/src/public/styles.css @@ -0,0 +1,909 @@ +/* CSS Variables */ +:root { + --bg-primary: #0a0a0f; + --bg-secondary: #12121a; + --bg-card: rgba(255, 255, 255, 0.03); + --bg-card-hover: rgba(255, 255, 255, 0.06); + + --text-primary: #ffffff; + --text-secondary: #a1a1aa; + --text-muted: #52525b; + + --spotify-green: #1DB954; + --spotify-green-dark: #169c46; + --youtube-red: #FF0000; + --youtube-red-dark: #cc0000; + + --accent-gradient: linear-gradient(135deg, #1DB954 0%, #FF0000 100%); + --glass-border: rgba(255, 255, 255, 0.08); + --glass-bg: rgba(255, 255, 255, 0.02); + + --radius-sm: 8px; + --radius-md: 12px; + --radius-lg: 16px; + --radius-xl: 24px; + + --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3); + --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4); + --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5); + + --transition-fast: 150ms ease; + --transition-normal: 250ms ease; + --transition-slow: 400ms ease; +} + +/* Reset & Base */ +*, +*::before, +*::after { + box-sizing: border-box; + margin: 0; + padding: 0; +} + +html { + font-size: 16px; + scroll-behavior: smooth; +} + +body { + font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; + background: var(--bg-primary); + color: var(--text-primary); + min-height: 100vh; + line-height: 1.6; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +/* Animated background */ +body::before { + content: ''; + position: fixed; + top: 0; + left: 0; + right: 0; + bottom: 0; + background: + radial-gradient(ellipse at 20% 20%, rgba(29, 185, 84, 0.08) 0%, transparent 50%), + radial-gradient(ellipse at 80% 80%, rgba(255, 0, 0, 0.06) 0%, transparent 50%); + pointer-events: none; + z-index: 0; +} + +.app { + position: relative; + z-index: 1; + max-width: 1200px; + margin: 0 auto; + padding: 0 24px; + min-height: 100vh; +} + +/* Header */ +.header { + display: flex; + justify-content: space-between; + align-items: center; + padding: 24px 0; + border-bottom: 1px solid var(--glass-border); + margin-bottom: 40px; +} + +.logo { + display: flex; + align-items: center; + gap: 12px; +} + +.logo-spotify, +.logo-youtube { + font-size: 1.8rem; +} + +.logo-arrow { + color: var(--text-muted); + font-size: 1.2rem; +} + +.logo h1 { + font-size: 1.25rem; + font-weight: 600; + background: var(--accent-gradient); + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; + background-clip: text; +} + +/* Buttons */ +.btn { + display: inline-flex; + align-items: center; + justify-content: center; + gap: 8px; + padding: 12px 24px; + font-size: 0.95rem; + font-weight: 500; + border: none; + border-radius: var(--radius-md); + cursor: pointer; + transition: all var(--transition-normal); + text-decoration: none; +} + +.btn:disabled { + opacity: 0.5; + cursor: not-allowed; +} + +.btn-primary { + background: var(--accent-gradient); + color: white; + box-shadow: 0 4px 20px rgba(29, 185, 84, 0.3); +} + +.btn-primary:hover:not(:disabled) { + transform: translateY(-2px); + box-shadow: 0 6px 30px rgba(29, 185, 84, 0.4); +} + +.btn-spotify { + background: var(--spotify-green); + color: white; +} + +.btn-spotify:hover:not(:disabled) { + background: var(--spotify-green-dark); + transform: translateY(-2px); +} + +.btn-youtube { + background: var(--youtube-red); + color: white; +} + +.btn-youtube:hover:not(:disabled) { + background: var(--youtube-red-dark); + transform: translateY(-2px); +} + +.btn-ghost { + background: transparent; + color: var(--text-secondary); + border: 1px solid var(--glass-border); +} + +.btn-ghost:hover:not(:disabled) { + background: var(--bg-card-hover); + color: var(--text-primary); +} + +.btn-large { + padding: 16px 32px; + font-size: 1.05rem; +} + +/* Views */ +.view { + animation: fadeIn var(--transition-slow); +} + +@keyframes fadeIn { + from { + opacity: 0; + transform: translateY(10px); + } + + to { + opacity: 1; + transform: translateY(0); + } +} + +/* Login View */ +.login-container { + max-width: 800px; + margin: 0 auto; + padding: 60px 0; + text-align: center; +} + +.login-container h2 { + font-size: 2.5rem; + font-weight: 700; + margin-bottom: 12px; +} + +.subtitle { + color: var(--text-secondary); + font-size: 1.1rem; + margin-bottom: 48px; +} + +.auth-cards { + display: grid; + grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); + gap: 24px; + margin-bottom: 48px; +} + +.auth-card { + background: var(--bg-card); + border: 1px solid var(--glass-border); + border-radius: var(--radius-xl); + padding: 32px; + backdrop-filter: blur(20px); + transition: all var(--transition-normal); +} + +.auth-card:hover { + background: var(--bg-card-hover); + transform: translateY(-4px); + box-shadow: var(--shadow-lg); +} + +.auth-card-header { + display: flex; + align-items: center; + justify-content: center; + gap: 12px; + margin-bottom: 20px; +} + +.service-icon { + font-size: 2rem; +} + +.service-name { + font-size: 1.5rem; + font-weight: 600; +} + +.auth-status { + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + margin-bottom: 24px; + padding: 12px; + background: var(--bg-secondary); + border-radius: var(--radius-md); +} + +.status-indicator { + width: 10px; + height: 10px; + border-radius: 50%; + background: var(--youtube-red); +} + +.status-indicator.connected { + background: var(--spotify-green); + box-shadow: 0 0 12px var(--spotify-green); +} + +.status-text { + color: var(--text-secondary); + font-size: 0.9rem; +} + +.auth-card .btn { + width: 100%; +} + +/* Playlist Grid */ +.playlist-container, +.review-container, +.progress-container { + padding: 20px 0 60px; +} + +.view-header { + text-align: center; + margin-bottom: 40px; +} + +.view-header h2 { + font-size: 2rem; + font-weight: 700; + margin-bottom: 8px; +} + +.playlist-grid { + display: grid; + grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); + gap: 20px; +} + +.playlist-card { + background: var(--bg-card); + border: 1px solid var(--glass-border); + border-radius: var(--radius-lg); + padding: 16px; + cursor: pointer; + transition: all var(--transition-normal); +} + +.playlist-card:hover { + background: var(--bg-card-hover); + transform: translateY(-4px); + box-shadow: var(--shadow-md); + border-color: var(--spotify-green); +} + +.playlist-card img { + width: 100%; + aspect-ratio: 1; + object-fit: cover; + border-radius: var(--radius-md); + margin-bottom: 12px; + background: var(--bg-secondary); +} + +.playlist-card h3 { + font-size: 0.95rem; + font-weight: 600; + margin-bottom: 4px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.playlist-card p { + font-size: 0.85rem; + color: var(--text-secondary); +} + +/* Review View */ +.back-btn { + margin-bottom: 24px; +} + +.playlist-header { + display: flex; + gap: 24px; + margin-bottom: 40px; + padding: 24px; + background: var(--bg-card); + border: 1px solid var(--glass-border); + border-radius: var(--radius-xl); +} + +.playlist-cover { + width: 160px; + height: 160px; + object-fit: cover; + border-radius: var(--radius-lg); + background: var(--bg-secondary); +} + +.playlist-info { + display: flex; + flex-direction: column; + justify-content: center; +} + +.playlist-info h2 { + font-size: 1.75rem; + font-weight: 700; + margin-bottom: 8px; +} + +.track-count { + color: var(--text-secondary); + font-size: 1rem; +} + +.tracks-container h3 { + font-size: 1.1rem; + font-weight: 600; + margin-bottom: 16px; + color: var(--text-secondary); +} + +.track-list { + max-height: 400px; + overflow-y: auto; + background: var(--bg-card); + border: 1px solid var(--glass-border); + border-radius: var(--radius-lg); +} + +.track-item { + display: flex; + align-items: center; + gap: 16px; + padding: 12px 16px; + border-bottom: 1px solid var(--glass-border); + transition: background var(--transition-fast); +} + +.track-item:last-child { + border-bottom: none; +} + +.track-item:hover { + background: var(--bg-card-hover); +} + +.track-number { + width: 32px; + color: var(--text-muted); + font-size: 0.9rem; + text-align: center; +} + +.track-info { + flex: 1; + min-width: 0; +} + +.track-name { + font-weight: 500; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.track-artist { + font-size: 0.85rem; + color: var(--text-secondary); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.migration-actions { + margin-top: 32px; + text-align: center; +} + +/* Progress View */ +.progress-container { + max-width: 600px; + margin: 0 auto; + text-align: center; +} + +.progress-container h2 { + font-size: 2rem; + font-weight: 700; + margin-bottom: 40px; +} + +.progress-stats { + margin-bottom: 24px; +} + +.stat-value { + font-size: 3rem; + font-weight: 700; + background: var(--accent-gradient); + -webkit-background-clip: text; + -webkit-text-fill-color: transparent; + background-clip: text; +} + +.stat-label { + font-size: 1.25rem; + color: var(--text-secondary); +} + +.progress-bar-container { + height: 8px; + background: var(--bg-secondary); + border-radius: 4px; + overflow: hidden; + margin-bottom: 32px; +} + +.progress-bar { + height: 100%; + background: var(--accent-gradient); + border-radius: 4px; + transition: width var(--transition-normal); +} + +.current-track { + display: flex; + align-items: center; + justify-content: center; + gap: 12px; + padding: 16px 24px; + background: var(--bg-card); + border: 1px solid var(--glass-border); + border-radius: var(--radius-lg); + margin-bottom: 24px; +} + +.pulse { + width: 12px; + height: 12px; + background: var(--spotify-green); + border-radius: 50%; + animation: pulse 1.5s ease-in-out infinite; +} + +@keyframes pulse { + + 0%, + 100% { + opacity: 1; + transform: scale(1); + } + + 50% { + opacity: 0.5; + transform: scale(1.2); + } +} + +.progress-log { + max-height: 200px; + overflow-y: auto; + text-align: left; + background: var(--bg-card); + border: 1px solid var(--glass-border); + border-radius: var(--radius-lg); + padding: 16px; +} + +.log-item { + display: flex; + align-items: center; + gap: 8px; + padding: 8px 0; + font-size: 0.9rem; + border-bottom: 1px solid var(--glass-border); +} + +.log-item:last-child { + border-bottom: none; +} + +.log-item.success { + color: var(--spotify-green); +} + +.log-item.error { + color: var(--youtube-red); +} + +.log-item.not-found { + color: var(--text-muted); +} + +/* Migration Complete */ +.migration-complete { + padding: 48px; + background: var(--bg-card); + border: 1px solid var(--glass-border); + border-radius: var(--radius-xl); + animation: fadeIn var(--transition-slow); +} + +.complete-icon { + width: 80px; + height: 80px; + background: var(--spotify-green); + color: white; + font-size: 2.5rem; + display: flex; + align-items: center; + justify-content: center; + border-radius: 50%; + margin: 0 auto 24px; + box-shadow: 0 0 40px rgba(29, 185, 84, 0.4); +} + +.migration-complete h3 { + font-size: 1.5rem; + font-weight: 700; + margin-bottom: 8px; +} + +.migration-complete p { + color: var(--text-secondary); + margin-bottom: 24px; +} + +.migration-complete .btn { + margin: 8px; +} + +/* Loading */ +.loading-spinner { + display: flex; + align-items: center; + justify-content: center; + padding: 60px; + color: var(--text-secondary); +} + +/* Scrollbar */ +::-webkit-scrollbar { + width: 8px; +} + +::-webkit-scrollbar-track { + background: var(--bg-secondary); + border-radius: 4px; +} + +::-webkit-scrollbar-thumb { + background: var(--glass-border); + border-radius: 4px; +} + +::-webkit-scrollbar-thumb:hover { + background: var(--text-muted); +} + +/* Responsive */ +@media (max-width: 768px) { + .app { + padding: 0 16px; + } + + .header { + flex-direction: column; + gap: 16px; + text-align: center; + padding: 16px 0; + } + + .logo h1 { + font-size: 1.1rem; + } + + .login-container h2 { + font-size: 1.75rem; + } + + .playlist-header { + flex-direction: column; + align-items: center; + text-align: center; + } + + .playlist-cover { + width: 120px; + height: 120px; + } + + .comparison-table .table-header, + .comparison-table .table-row { + grid-template-columns: 1fr; + gap: 8px; + } + + .col-youtube .manual-input { + flex-direction: column; + } +} + +/* Analysis View */ +.analysis-container { + padding: 20px 0 60px; +} + +.analysis-container .playlist-header { + align-items: center; +} + +.analysis-container .playlist-info { + flex: 1; +} + +/* Analysis Progress */ +.analysis-progress { + background: var(--bg-card); + border: 1px solid var(--glass-border); + border-radius: var(--radius-lg); + padding: 24px; + margin-bottom: 24px; +} + +.progress-header { + display: flex; + align-items: center; + gap: 12px; + margin-bottom: 16px; + font-weight: 500; +} + +.progress-detail { + margin-top: 12px; + color: var(--text-secondary); + font-size: 0.9rem; +} + +/* Analysis Results */ +.analysis-results { + animation: fadeIn var(--transition-slow); +} + +.results-header { + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 20px; +} + +.results-header h3 { + font-size: 1.25rem; + font-weight: 600; +} + +.results-stats { + display: flex; + gap: 16px; +} + +.results-stats .stat { + padding: 6px 14px; + border-radius: var(--radius-md); + font-size: 0.9rem; + font-weight: 500; +} + +.results-stats .stat.found { + background: rgba(29, 185, 84, 0.15); + color: var(--spotify-green); +} + +.results-stats .stat.not-found { + background: rgba(255, 0, 0, 0.15); + color: var(--youtube-red); +} + +/* Comparison Table */ +.comparison-table { + background: var(--bg-card); + border: 1px solid var(--glass-border); + border-radius: var(--radius-lg); + overflow: hidden; +} + +.table-header { + display: grid; + grid-template-columns: 1fr 120px 1fr; + gap: 16px; + padding: 16px 20px; + background: var(--bg-secondary); + font-weight: 600; + font-size: 0.85rem; + color: var(--text-secondary); + text-transform: uppercase; + letter-spacing: 0.5px; +} + +.table-body { + max-height: 400px; + overflow-y: auto; +} + +.table-row { + display: grid; + grid-template-columns: 1fr 120px 1fr; + gap: 16px; + padding: 14px 20px; + border-bottom: 1px solid var(--glass-border); + align-items: center; + transition: background var(--transition-fast); +} + +.table-row:last-child { + border-bottom: none; +} + +.table-row:hover { + background: var(--bg-card-hover); +} + +.table-row.found { + border-left: 3px solid var(--spotify-green); +} + +.table-row.not_found { + border-left: 3px solid var(--youtube-red); +} + +.table-row.manual { + border-left: 3px solid #f59e0b; +} + +/* Status Badges */ +.status-badge { + display: inline-flex; + align-items: center; + gap: 4px; + padding: 4px 10px; + border-radius: var(--radius-sm); + font-size: 0.8rem; + font-weight: 500; +} + +.status-badge.found { + background: rgba(29, 185, 84, 0.15); + color: var(--spotify-green); +} + +.status-badge.not-found { + background: rgba(255, 0, 0, 0.15); + color: var(--youtube-red); +} + +.status-badge.manual { + background: rgba(245, 158, 11, 0.15); + color: #f59e0b; +} + +/* YouTube Match */ +.youtube-match { + display: flex; + align-items: center; + gap: 12px; +} + +.youtube-match img { + width: 48px; + height: 36px; + object-fit: cover; + border-radius: 4px; + background: var(--bg-secondary); +} + +.match-info { + min-width: 0; +} + +.match-title { + font-size: 0.9rem; + font-weight: 500; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.match-channel { + font-size: 0.8rem; + color: var(--text-secondary); +} + +.manual-badge { + font-size: 0.85rem; + color: #f59e0b; +} + +/* Manual Input */ +.manual-input { + display: flex; + gap: 8px; +} + +.manual-video-input { + flex: 1; + padding: 8px 12px; + background: var(--bg-secondary); + border: 1px solid var(--glass-border); + border-radius: var(--radius-sm); + color: var(--text-primary); + font-size: 0.85rem; + font-family: inherit; + outline: none; + transition: border-color var(--transition-fast); +} + +.manual-video-input:focus { + border-color: var(--spotify-green); +} + +.manual-video-input::placeholder { + color: var(--text-muted); +} + +.btn-small { + padding: 8px 12px; + font-size: 0.8rem; +} \ No newline at end of file diff --git a/src/routes/auth.js b/src/routes/auth.js new file mode 100644 index 0000000..b65cb08 --- /dev/null +++ b/src/routes/auth.js @@ -0,0 +1,148 @@ +import { Router } from 'express'; +import SpotifyWebApi from 'spotify-web-api-node'; +import { google } from 'googleapis'; + +const router = Router(); + +// Spotify OAuth configuration +const spotifyApi = new SpotifyWebApi({ + clientId: process.env.SPOTIFY_CLIENT_ID, + clientSecret: process.env.SPOTIFY_CLIENT_SECRET, + redirectUri: `${process.env.BASE_URL || 'http://localhost:3000'}/auth/spotify/callback` +}); + +// YouTube OAuth configuration +const oauth2Client = new google.auth.OAuth2( + process.env.YOUTUBE_CLIENT_ID, + process.env.YOUTUBE_CLIENT_SECRET, + `${process.env.BASE_URL || 'http://localhost:3000'}/auth/youtube/callback` +); + +// Spotify scopes needed +const SPOTIFY_SCOPES = [ + 'user-read-private', + 'user-read-email', + 'playlist-read-private', + 'playlist-read-collaborative' +]; + +// YouTube scopes needed +const YOUTUBE_SCOPES = [ + 'https://www.googleapis.com/auth/youtube', + 'https://www.googleapis.com/auth/youtube.force-ssl' +]; + +// Check auth status +router.get('/status', (req, res) => { + res.json({ + spotify: { + connected: !!req.session.spotifyTokens, + user: req.session.spotifyUser || null + }, + youtube: { + connected: !!req.session.youtubeTokens, + user: req.session.youtubeUser || null + } + }); +}); + +// Spotify OAuth - Initiate +router.get('/spotify', (req, res) => { + const authorizeURL = spotifyApi.createAuthorizeURL(SPOTIFY_SCOPES, 'spotify-auth'); + res.redirect(authorizeURL); +}); + +// Spotify OAuth - Callback +router.get('/spotify/callback', async (req, res) => { + const { code, error } = req.query; + + if (error) { + return res.redirect('/?error=spotify_auth_failed'); + } + + try { + const data = await spotifyApi.authorizationCodeGrant(code); + + req.session.spotifyTokens = { + accessToken: data.body.access_token, + refreshToken: data.body.refresh_token, + expiresAt: Date.now() + data.body.expires_in * 1000 + }; + + // Get user info + spotifyApi.setAccessToken(data.body.access_token); + const userInfo = await spotifyApi.getMe(); + req.session.spotifyUser = { + id: userInfo.body.id, + name: userInfo.body.display_name, + email: userInfo.body.email, + image: userInfo.body.images?.[0]?.url + }; + + res.redirect('/?spotify=connected'); + } catch (err) { + console.error('Spotify auth error:', err); + res.redirect('/?error=spotify_auth_failed'); + } +}); + +// YouTube OAuth - Initiate +router.get('/youtube', (req, res) => { + const authorizeURL = oauth2Client.generateAuthUrl({ + access_type: 'offline', + scope: YOUTUBE_SCOPES, + prompt: 'consent' + }); + res.redirect(authorizeURL); +}); + +// YouTube OAuth - Callback +router.get('/youtube/callback', async (req, res) => { + const { code, error } = req.query; + + if (error) { + return res.redirect('/?error=youtube_auth_failed'); + } + + try { + const { tokens } = await oauth2Client.getToken(code); + oauth2Client.setCredentials(tokens); + + req.session.youtubeTokens = { + accessToken: tokens.access_token, + refreshToken: tokens.refresh_token, + expiresAt: tokens.expiry_date + }; + + // Get user info + const youtube = google.youtube({ version: 'v3', auth: oauth2Client }); + const channelResponse = await youtube.channels.list({ + part: 'snippet', + mine: true + }); + + const channel = channelResponse.data.items?.[0]; + req.session.youtubeUser = { + id: channel?.id, + name: channel?.snippet?.title, + image: channel?.snippet?.thumbnails?.default?.url + }; + + res.redirect('/?youtube=connected'); + } catch (err) { + console.error('YouTube auth error:', err); + res.redirect('/?error=youtube_auth_failed'); + } +}); + +// Logout +router.post('/logout', (req, res) => { + req.session.destroy((err) => { + if (err) { + return res.status(500).json({ error: 'Logout failed' }); + } + res.json({ success: true }); + }); +}); + +export default router; diff --git a/src/routes/spotify.js b/src/routes/spotify.js new file mode 100644 index 0000000..9e5ab51 --- /dev/null +++ b/src/routes/spotify.js @@ -0,0 +1,131 @@ +import { Router } from 'express'; +import SpotifyWebApi from 'spotify-web-api-node'; + +const router = Router(); + +// Helper to get authenticated Spotify API instance +function getSpotifyApi(session) { + if (!session.spotifyTokens) { + throw new Error('Not authenticated with Spotify'); + } + + const spotifyApi = new SpotifyWebApi({ + clientId: process.env.SPOTIFY_CLIENT_ID, + clientSecret: process.env.SPOTIFY_CLIENT_SECRET + }); + + spotifyApi.setAccessToken(session.spotifyTokens.accessToken); + spotifyApi.setRefreshToken(session.spotifyTokens.refreshToken); + + return spotifyApi; +} + +// Middleware to check Spotify auth +function requireSpotifyAuth(req, res, next) { + if (!req.session.spotifyTokens) { + return res.status(401).json({ error: 'Not authenticated with Spotify' }); + } + next(); +} + +// Get user's playlists +router.get('/playlists', requireSpotifyAuth, async (req, res) => { + try { + const spotifyApi = getSpotifyApi(req.session); + + let allPlaylists = []; + let offset = 0; + const limit = 50; + let hasMore = true; + + while (hasMore) { + const response = await spotifyApi.getUserPlaylists({ limit, offset }); + allPlaylists = allPlaylists.concat(response.body.items); + + if (response.body.next) { + offset += limit; + } else { + hasMore = false; + } + } + + const playlists = allPlaylists.map(playlist => ({ + id: playlist.id, + name: playlist.name, + description: playlist.description, + trackCount: playlist.tracks.total, + image: playlist.images?.[0]?.url, + owner: playlist.owner.display_name + })); + + res.json(playlists); + } catch (err) { + console.error('Error fetching playlists:', err); + res.status(500).json({ error: 'Failed to fetch playlists' }); + } +}); + +// Get tracks from a playlist +router.get('/playlist/:id/tracks', requireSpotifyAuth, async (req, res) => { + try { + const spotifyApi = getSpotifyApi(req.session); + const playlistId = req.params.id; + + let allTracks = []; + let offset = 0; + const limit = 100; + let hasMore = true; + + while (hasMore) { + const response = await spotifyApi.getPlaylistTracks(playlistId, { + limit, + offset, + fields: 'items(track(id,name,artists,album,duration_ms)),next' + }); + + allTracks = allTracks.concat(response.body.items); + + if (response.body.next) { + offset += limit; + } else { + hasMore = false; + } + } + + const tracks = allTracks + .filter(item => item.track) // Filter out null tracks + .map(item => ({ + id: item.track.id, + name: item.track.name, + artists: item.track.artists.map(a => a.name), + album: item.track.album?.name, + duration: item.track.duration_ms + })); + + res.json(tracks); + } catch (err) { + console.error('Error fetching tracks:', err); + res.status(500).json({ error: 'Failed to fetch tracks' }); + } +}); + +// Get playlist info +router.get('/playlist/:id', requireSpotifyAuth, async (req, res) => { + try { + const spotifyApi = getSpotifyApi(req.session); + const response = await spotifyApi.getPlaylist(req.params.id); + + res.json({ + id: response.body.id, + name: response.body.name, + description: response.body.description, + trackCount: response.body.tracks.total, + image: response.body.images?.[0]?.url + }); + } catch (err) { + console.error('Error fetching playlist:', err); + res.status(500).json({ error: 'Failed to fetch playlist' }); + } +}); + +export default router; diff --git a/src/routes/youtube.js b/src/routes/youtube.js new file mode 100644 index 0000000..d7cf30b --- /dev/null +++ b/src/routes/youtube.js @@ -0,0 +1,451 @@ +import { Router } from 'express'; +import { google } from 'googleapis'; +import { sendProgress } from '../server.js'; +import * as queue from '../services/analysisQueue.js'; +import * as searchCache from '../services/searchCache.js'; + +const router = Router(); + +// Helper to get authenticated YouTube API instance +function getYouTubeApi(session) { + if (!session.youtubeTokens) { + throw new Error('Not authenticated with YouTube'); + } + + const oauth2Client = new google.auth.OAuth2( + process.env.YOUTUBE_CLIENT_ID, + process.env.YOUTUBE_CLIENT_SECRET + ); + + oauth2Client.setCredentials({ + access_token: session.youtubeTokens.accessToken, + refresh_token: session.youtubeTokens.refreshToken + }); + + return google.youtube({ version: 'v3', auth: oauth2Client }); +} + +// Middleware to check YouTube auth +function requireYouTubeAuth(req, res, next) { + if (!req.session.youtubeTokens) { + return res.status(401).json({ error: 'Not authenticated with YouTube' }); + } + next(); +} + +// Search for a video on YouTube (with caching) +async function searchVideo(youtube, artists, trackName) { + // Check cache first + const cached = searchCache.getCachedSearch(artists, trackName); + if (cached !== null) { + console.log(`๐Ÿ“ฆ Cache hit: ${artists.join(', ')} - ${trackName}`); + return cached; + } + + // Not in cache, search YouTube + const query = `${artists.join(', ')} - ${trackName}`; + try { + const response = await youtube.search.list({ + part: 'snippet', + q: query, + type: 'video', + videoCategoryId: '10', // Music category + maxResults: 1 + }); + + let result = null; + if (response.data.items && response.data.items.length > 0) { + const video = response.data.items[0]; + result = { + id: video.id.videoId, + title: video.snippet.title, + channel: video.snippet.channelTitle, + thumbnail: video.snippet.thumbnails?.default?.url + }; + } + + // Cache the result (even if null/not found) + searchCache.cacheSearch(artists, trackName, result); + console.log(`๐Ÿ” API search: ${artists.join(', ')} - ${trackName} โ†’ ${result ? 'found' : 'not found'}`); + + return result; + } catch (err) { + console.error('Search error:', err.message); + return null; + } +} + +// Create a playlist +async function createPlaylist(youtube, title, description) { + const response = await youtube.playlists.insert({ + part: 'snippet,status', + requestBody: { + snippet: { + title, + description: description || `Migrated from Spotify` + }, + status: { + privacyStatus: 'private' + } + } + }); + + return response.data; +} + +// Add video to playlist +async function addToPlaylist(youtube, playlistId, videoId) { + await youtube.playlistItems.insert({ + part: 'snippet', + requestBody: { + snippet: { + playlistId, + resourceId: { + kind: 'youtube#video', + videoId + } + } + } + }); +} + +// ============ ANALYSIS ENDPOINTS ============ + +// Start analysis job +router.post('/analyze', requireYouTubeAuth, async (req, res) => { + const { playlist, tracks, sessionId } = req.body; + + if (!tracks || !Array.isArray(tracks) || tracks.length === 0) { + return res.status(400).json({ error: 'No tracks provided' }); + } + + if (!sessionId) { + return res.status(400).json({ error: 'Session ID required' }); + } + + // Check playlist size limit + const maxSize = queue.getMaxPlaylistSize(); + if (tracks.length > maxSize) { + return res.status(400).json({ + error: `Playlist too large. Maximum ${maxSize} tracks allowed.`, + maxSize, + trackCount: tracks.length + }); + } + + // Create job + try { + const job = queue.createJob(sessionId, playlist, tracks); + + // Start analysis in background + analyzePlaylist(job.id, req.session).catch(err => { + console.error('Analysis error:', err); + queue.updateJobStatus(job.id, 'error', err.message); + }); + + res.json({ + jobId: job.id, + status: job.status, + trackCount: tracks.length + }); + } catch (err) { + res.status(400).json({ error: err.message }); + } +}); + +// Background analysis function +async function analyzePlaylist(jobId, session) { + const job = queue.getJob(jobId); + if (!job) return; + + queue.updateJobStatus(jobId, 'analyzing'); + + const youtube = getYouTubeApi(session); + const delay = queue.getRateLimitDelay(); + + for (let i = 0; i < job.tracks.length; i++) { + const track = job.tracks[i]; + + // Update status to searching + job.tracks[i].status = 'searching'; + + // Send progress update + sendProgress(job.sessionId, { + type: 'analysis_progress', + jobId, + current: i + 1, + total: job.tracks.length, + track: { + name: track.name, + artists: track.artists + }, + status: 'searching' + }); + + // Search YouTube (with caching) + const match = await searchVideo(youtube, track.artists, track.name); + + if (match) { + queue.updateTrackMatch(jobId, i, match, 'found'); + sendProgress(job.sessionId, { + type: 'analysis_match', + jobId, + current: i + 1, + total: job.tracks.length, + track: { + name: track.name, + artists: track.artists + }, + match, + status: 'found' + }); + } else { + queue.updateTrackMatch(jobId, i, null, 'not_found'); + sendProgress(job.sessionId, { + type: 'analysis_match', + jobId, + current: i + 1, + total: job.tracks.length, + track: { + name: track.name, + artists: track.artists + }, + match: null, + status: 'not_found' + }); + } + + // Rate limiting delay (except for last item) + if (i < job.tracks.length - 1) { + await new Promise(resolve => setTimeout(resolve, delay)); + } + } + + queue.updateJobStatus(jobId, 'complete'); + + // Send completion + const completedJob = queue.getJob(jobId); + const stats = { + found: completedJob.tracks.filter(t => t.status === 'found').length, + notFound: completedJob.tracks.filter(t => t.status === 'not_found').length, + total: completedJob.tracks.length + }; + + sendProgress(job.sessionId, { + type: 'analysis_complete', + jobId, + stats + }); +} + +// Get analysis job status +router.get('/analysis/:jobId', requireYouTubeAuth, (req, res) => { + const job = queue.getJob(req.params.jobId); + + if (!job) { + return res.status(404).json({ error: 'Job not found' }); + } + + res.json(job); +}); + +// Update manual video ID for a track +router.post('/analysis/:jobId/track/:trackIndex/manual', requireYouTubeAuth, (req, res) => { + const { jobId, trackIndex } = req.params; + const { videoId } = req.body; + + if (!videoId) { + return res.status(400).json({ error: 'Video ID required' }); + } + + // Extract video ID from URL if full URL provided + let extractedVideoId = videoId; + const urlMatch = videoId.match(/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([^&\s]+)/); + if (urlMatch) { + extractedVideoId = urlMatch[1]; + } + + const success = queue.setManualVideoId(jobId, parseInt(trackIndex), extractedVideoId); + + if (!success) { + return res.status(404).json({ error: 'Job or track not found' }); + } + + res.json({ success: true, videoId: extractedVideoId }); +}); + +// ============ MIGRATION ENDPOINT ============ + +// Migrate with pre-analyzed data +router.post('/migrate', requireYouTubeAuth, async (req, res) => { + const { jobId, sessionId } = req.body; + + const job = queue.getJob(jobId); + + if (!job) { + return res.status(404).json({ error: 'Analysis job not found' }); + } + + if (job.status !== 'complete') { + return res.status(400).json({ error: 'Analysis not complete' }); + } + + try { + const youtube = getYouTubeApi(req.session); + + // Create the playlist + sendProgress(sessionId, { + type: 'status', + message: 'Creating YouTube playlist...' + }); + + const playlist = await createPlaylist(youtube, job.playlist.name, `Migrated from Spotify`); + + sendProgress(sessionId, { + type: 'playlist_created', + playlistId: playlist.id, + playlistUrl: `https://music.youtube.com/playlist?list=${playlist.id}` + }); + + // Track progress + let successCount = 0; + let skipCount = 0; + const results = []; + + // Process tracks using cached matches + for (let i = 0; i < job.tracks.length; i++) { + const track = job.tracks[i]; + + // Get video ID (manual override or matched) + const videoId = track.manualVideoId || track.youtubeMatch?.id; + + sendProgress(sessionId, { + type: 'processing', + current: i + 1, + total: job.tracks.length, + track: { + name: track.name, + artists: track.artists + } + }); + + if (videoId) { + try { + await addToPlaylist(youtube, playlist.id, videoId); + successCount++; + results.push({ + track: track.name, + status: 'success', + videoId + }); + + sendProgress(sessionId, { + type: 'track_added', + current: i + 1, + total: job.tracks.length, + track: track.name, + success: true + }); + } catch (err) { + results.push({ + track: track.name, + status: 'error', + error: err.message + }); + + sendProgress(sessionId, { + type: 'track_failed', + current: i + 1, + total: job.tracks.length, + track: track.name, + error: err.message, + success: false + }); + } + } else { + skipCount++; + results.push({ + track: track.name, + status: 'skipped', + reason: 'No video ID' + }); + + sendProgress(sessionId, { + type: 'track_skipped', + current: i + 1, + total: job.tracks.length, + track: track.name + }); + } + + // Small delay to avoid rate limiting on playlist adds + await new Promise(resolve => setTimeout(resolve, 300)); + } + + // Send completion + sendProgress(sessionId, { + type: 'complete', + playlistId: playlist.id, + playlistUrl: `https://music.youtube.com/playlist?list=${playlist.id}`, + successCount, + skipCount, + total: job.tracks.length + }); + + res.json({ + success: true, + playlistId: playlist.id, + playlistUrl: `https://music.youtube.com/playlist?list=${playlist.id}`, + successCount, + skipCount, + results + }); + + } catch (err) { + console.error('Migration error:', err); + + sendProgress(sessionId, { + type: 'error', + message: err.message || 'Migration failed' + }); + + res.status(500).json({ error: 'Migration failed', details: err.message }); + } +}); + +// Get user's YouTube playlists (for reference) +router.get('/playlists', requireYouTubeAuth, async (req, res) => { + try { + const youtube = getYouTubeApi(req.session); + + const response = await youtube.playlists.list({ + part: 'snippet,contentDetails', + mine: true, + maxResults: 50 + }); + + const playlists = response.data.items.map(playlist => ({ + id: playlist.id, + name: playlist.snippet.title, + description: playlist.snippet.description, + trackCount: playlist.contentDetails.itemCount, + image: playlist.snippet.thumbnails?.default?.url + })); + + res.json(playlists); + } catch (err) { + console.error('Error fetching YouTube playlists:', err); + res.status(500).json({ error: 'Failed to fetch playlists' }); + } +}); + +// Get configuration limits and cache stats +router.get('/config', (req, res) => { + res.json({ + maxPlaylistSize: queue.getMaxPlaylistSize(), + rateLimitDelayMs: queue.getRateLimitDelay(), + searchCache: searchCache.getSearchCacheStats() + }); +}); + +export default router; diff --git a/src/server.js b/src/server.js new file mode 100644 index 0000000..6d6477b --- /dev/null +++ b/src/server.js @@ -0,0 +1,71 @@ +import 'dotenv/config'; +import express from 'express'; +import session from 'express-session'; +import { fileURLToPath } from 'url'; +import { dirname, join } from 'path'; +import authRoutes from './routes/auth.js'; +import spotifyRoutes from './routes/spotify.js'; +import youtubeRoutes from './routes/youtube.js'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const app = express(); +const PORT = process.env.PORT || 3000; + +// Middleware +app.use(express.json()); +app.use(express.static(join(__dirname, 'public'))); + +// Session configuration +app.use(session({ + secret: process.env.SESSION_SECRET || 'dev-secret-change-in-production', + resave: false, + saveUninitialized: false, + cookie: { + secure: process.env.NODE_ENV === 'production', + maxAge: 24 * 60 * 60 * 1000 // 24 hours + } +})); + +// Store SSE clients for progress updates +const clients = new Map(); + +// SSE endpoint for migration progress +app.get('/api/progress/:sessionId', (req, res) => { + const sessionId = req.params.sessionId; + + res.setHeader('Content-Type', 'text/event-stream'); + res.setHeader('Cache-Control', 'no-cache'); + res.setHeader('Connection', 'keep-alive'); + res.flushHeaders(); + + clients.set(sessionId, res); + + req.on('close', () => { + clients.delete(sessionId); + }); +}); + +// Helper to send progress updates +export function sendProgress(sessionId, data) { + const client = clients.get(sessionId); + if (client) { + client.write(`data: ${JSON.stringify(data)}\n\n`); + } +} + +// Routes +app.use('/auth', authRoutes); +app.use('/api/spotify', spotifyRoutes); +app.use('/api/youtube', youtubeRoutes); + +// Health check +app.get('/health', (req, res) => { + res.json({ status: 'ok' }); +}); + +app.listen(PORT, () => { + console.log(`๐ŸŽต Spotify to YouTube Music Migration Tool`); + console.log(`๐Ÿš€ Server running at http://localhost:${PORT}`); +}); diff --git a/src/services/analysisQueue.js b/src/services/analysisQueue.js new file mode 100644 index 0000000..03d41de --- /dev/null +++ b/src/services/analysisQueue.js @@ -0,0 +1,248 @@ +import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync, unlinkSync } from 'fs'; +import { join, resolve } from 'path'; + +// Configuration from environment +const CACHE_PATH = resolve(process.env.CACHE_PATH || './cache'); +const MAX_PLAYLIST_SIZE = parseInt(process.env.MAX_PLAYLIST_SIZE || '500', 10); +const RATE_LIMIT_DELAY_MS = parseInt(process.env.RATE_LIMIT_DELAY_MS || '2000', 10); + +// Ensure cache directory exists +if (!existsSync(CACHE_PATH)) { + mkdirSync(CACHE_PATH, { recursive: true }); +} + +// In-memory job cache (loaded from disk on demand) +const jobs = new Map(); + +/** + * Get cache file path for a job + */ +function getJobFilePath(jobId) { + return join(CACHE_PATH, `${jobId}.json`); +} + +/** + * Save job to disk + */ +function saveJobToDisk(job) { + try { + const filePath = getJobFilePath(job.id); + writeFileSync(filePath, JSON.stringify(job, null, 2), 'utf-8'); + } catch (err) { + console.error('Failed to save job to disk:', err.message); + } +} + +/** + * Load job from disk + */ +function loadJobFromDisk(jobId) { + try { + const filePath = getJobFilePath(jobId); + if (existsSync(filePath)) { + const data = readFileSync(filePath, 'utf-8'); + return JSON.parse(data); + } + } catch (err) { + console.error('Failed to load job from disk:', err.message); + } + return null; +} + +/** + * Load all jobs from disk on startup + */ +function loadAllJobsFromDisk() { + try { + if (!existsSync(CACHE_PATH)) return; + + const files = readdirSync(CACHE_PATH).filter(f => f.endsWith('.json')); + for (const file of files) { + const jobId = file.replace('.json', ''); + const job = loadJobFromDisk(jobId); + if (job) { + jobs.set(jobId, job); + } + } + console.log(`๐Ÿ“ Loaded ${files.length} cached jobs from ${CACHE_PATH}`); + } catch (err) { + console.error('Failed to load jobs from disk:', err.message); + } +} + +// Load existing jobs on module init +loadAllJobsFromDisk(); + +/** + * Get max playlist size limit + */ +export function getMaxPlaylistSize() { + return MAX_PLAYLIST_SIZE; +} + +/** + * Get rate limit delay + */ +export function getRateLimitDelay() { + return RATE_LIMIT_DELAY_MS; +} + +/** + * Create a new analysis job + */ +export function createJob(sessionId, playlist, tracks) { + // Check playlist size limit + if (tracks.length > MAX_PLAYLIST_SIZE) { + throw new Error(`Playlist exceeds maximum size of ${MAX_PLAYLIST_SIZE} tracks`); + } + + const jobId = `job_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`; + + const job = { + id: jobId, + sessionId, + playlist: { + id: playlist.id, + name: playlist.name, + image: playlist.image + }, + tracks: tracks.map(track => ({ + spotifyId: track.id, + name: track.name, + artists: track.artists, + album: track.album, + youtubeMatch: null, + manualVideoId: null, + status: 'pending' // pending, searching, found, not_found, manual + })), + status: 'pending', // pending, analyzing, complete, error + progress: { + current: 0, + total: tracks.length + }, + createdAt: Date.now(), + completedAt: null, + error: null + }; + + jobs.set(jobId, job); + saveJobToDisk(job); + return job; +} + +/** + * Get a job by ID (from memory or disk) + */ +export function getJob(jobId) { + // Try memory first + if (jobs.has(jobId)) { + return jobs.get(jobId); + } + + // Try loading from disk + const job = loadJobFromDisk(jobId); + if (job) { + jobs.set(jobId, job); + } + return job; +} + +/** + * Get all jobs for a session + */ +export function getJobsBySession(sessionId) { + const sessionJobs = []; + for (const job of jobs.values()) { + if (job.sessionId === sessionId) { + sessionJobs.push(job); + } + } + return sessionJobs.sort((a, b) => b.createdAt - a.createdAt); +} + +/** + * Update job status + */ +export function updateJobStatus(jobId, status, error = null) { + const job = jobs.get(jobId); + if (job) { + job.status = status; + if (error) job.error = error; + if (status === 'complete' || status === 'error') { + job.completedAt = Date.now(); + } + saveJobToDisk(job); + } + return job; +} + +/** + * Update track match result + */ +export function updateTrackMatch(jobId, trackIndex, youtubeMatch, status) { + const job = jobs.get(jobId); + if (job && job.tracks[trackIndex]) { + job.tracks[trackIndex].youtubeMatch = youtubeMatch; + job.tracks[trackIndex].status = status; + job.progress.current = trackIndex + 1; + + // Save to disk periodically (every 10 tracks or on completion) + if ((trackIndex + 1) % 10 === 0 || trackIndex === job.tracks.length - 1) { + saveJobToDisk(job); + } + } + return job; +} + +/** + * Set manual video ID for a track + */ +export function setManualVideoId(jobId, trackIndex, videoId) { + const job = jobs.get(jobId); + if (job && job.tracks[trackIndex]) { + job.tracks[trackIndex].manualVideoId = videoId; + job.tracks[trackIndex].status = 'manual'; + saveJobToDisk(job); + return true; + } + return false; +} + +/** + * Clean up old jobs (older than 7 days) + */ +export function cleanupOldJobs() { + const now = Date.now(); + const maxAge = 7 * 24 * 60 * 60 * 1000; // 7 days + + for (const [jobId, job] of jobs.entries()) { + if (now - job.createdAt > maxAge) { + jobs.delete(jobId); + + // Delete from disk too + try { + const filePath = getJobFilePath(jobId); + if (existsSync(filePath)) { + unlinkSync(filePath); + } + } catch (err) { + console.error('Failed to delete old job file:', err.message); + } + } + } +} + +// Run cleanup every hour +setInterval(cleanupOldJobs, 60 * 60 * 1000); + +export default { + createJob, + getJob, + getJobsBySession, + updateJobStatus, + updateTrackMatch, + setManualVideoId, + getRateLimitDelay, + getMaxPlaylistSize, + cleanupOldJobs +}; diff --git a/src/services/searchCache.js b/src/services/searchCache.js new file mode 100644 index 0000000..27bb505 --- /dev/null +++ b/src/services/searchCache.js @@ -0,0 +1,142 @@ +import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs'; +import { join, resolve } from 'path'; + +// Configuration from environment +const CACHE_PATH = resolve(process.env.CACHE_PATH || './cache'); +const SEARCH_CACHE_FILE = join(CACHE_PATH, 'search_cache.json'); + +// Ensure cache directory exists +if (!existsSync(CACHE_PATH)) { + mkdirSync(CACHE_PATH, { recursive: true }); +} + +// In-memory search cache +let searchCache = new Map(); + +/** + * Load search cache from disk + */ +function loadSearchCache() { + try { + if (existsSync(SEARCH_CACHE_FILE)) { + const data = readFileSync(SEARCH_CACHE_FILE, 'utf-8'); + const parsed = JSON.parse(data); + searchCache = new Map(Object.entries(parsed)); + console.log(`๐Ÿ” Loaded ${searchCache.size} cached search results`); + } + } catch (err) { + console.error('Failed to load search cache:', err.message); + searchCache = new Map(); + } +} + +/** + * Save search cache to disk + */ +function saveSearchCache() { + try { + const obj = Object.fromEntries(searchCache); + writeFileSync(SEARCH_CACHE_FILE, JSON.stringify(obj, null, 2), 'utf-8'); + } catch (err) { + console.error('Failed to save search cache:', err.message); + } +} + +/** + * Generate cache key from artist and track name + */ +function generateCacheKey(artists, trackName) { + // Normalize: lowercase, trim, sort artists + const normalizedArtists = artists.map(a => a.toLowerCase().trim()).sort().join('|'); + const normalizedTrack = trackName.toLowerCase().trim(); + return `${normalizedArtists}::${normalizedTrack}`; +} + +/** + * Get cached search result + */ +export function getCachedSearch(artists, trackName) { + const key = generateCacheKey(artists, trackName); + const cached = searchCache.get(key); + + if (cached) { + // Check if cache is still valid (30 days) + const maxAge = 30 * 24 * 60 * 60 * 1000; + if (Date.now() - cached.cachedAt < maxAge) { + return cached.result; + } + // Expired, remove from cache + searchCache.delete(key); + } + + return null; +} + +/** + * Cache a search result + */ +export function cacheSearch(artists, trackName, result) { + const key = generateCacheKey(artists, trackName); + searchCache.set(key, { + result, + cachedAt: Date.now() + }); + + // Save to disk periodically (every 10 new entries) + if (searchCache.size % 10 === 0) { + saveSearchCache(); + } +} + +/** + * Force save cache to disk + */ +export function flushSearchCache() { + saveSearchCache(); +} + +/** + * Get cache statistics + */ +export function getSearchCacheStats() { + return { + entries: searchCache.size, + path: SEARCH_CACHE_FILE + }; +} + +/** + * Clear expired entries from cache + */ +export function cleanupSearchCache() { + const maxAge = 30 * 24 * 60 * 60 * 1000; // 30 days + const now = Date.now(); + let removed = 0; + + for (const [key, value] of searchCache.entries()) { + if (now - value.cachedAt > maxAge) { + searchCache.delete(key); + removed++; + } + } + + if (removed > 0) { + saveSearchCache(); + console.log(`๐Ÿงน Cleaned up ${removed} expired search cache entries`); + } +} + +// Load cache on module init +loadSearchCache(); + +// Cleanup expired entries on startup and daily +cleanupSearchCache(); +setInterval(cleanupSearchCache, 24 * 60 * 60 * 1000); + +export default { + getCachedSearch, + cacheSearch, + flushSearchCache, + getSearchCacheStats, + cleanupSearchCache +};