{"id":35163938,"url":"https://github.com/ducks/scrob","last_synced_at":"2026-01-16T14:06:00.712Z","repository":{"id":327673491,"uuid":"1109530043","full_name":"ducks/scrob","owner":"ducks","description":"A self-hostable scrobbling server written in Rust","archived":false,"fork":false,"pushed_at":"2025-12-20T06:45:41.000Z","size":111,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-22T13:51:40.481Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ducks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-12-03T23:46:40.000Z","updated_at":"2025-12-20T06:45:45.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/ducks/scrob","commit_stats":null,"previous_names":["ducks/scrob"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ducks/scrob","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducks%2Fscrob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducks%2Fscrob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducks%2Fscrob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducks%2Fscrob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ducks","download_url":"https://codeload.github.com/ducks/scrob/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ducks%2Fscrob/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28102733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-28T02:00:05.685Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-28T19:03:41.602Z","updated_at":"2025-12-28T19:05:46.402Z","avatar_url":"https://github.com/ducks.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scrob\n\nSelf-hosted music scrobble server with REST API.\n\n**New to scrob?** Check out [QUICKSTART.md](QUICKSTART.md) for a step-by-step guide.\n\n**Developing?** See [CLAUDE.md](CLAUDE.md) for architecture notes and best practices.\n\n## Features\n\n- REST API for scrobble submission and statistics\n- Token-based authentication\n- PostgreSQL database\n- Docker support\n- Compatible with last-fm-rs client library\n\n## Quick Start with Docker\n\n### Using Docker Compose\n\n```bash\n# Build and start\ndocker-compose up -d\n\n# View logs\ndocker-compose logs -f\n\n# Stop\ndocker-compose down\n```\n\nThe server will be available at `http://localhost:3000`.\n\n### Manual Docker Build\n\n```bash\n# Build image\ndocker build -t scrob .\n\n# Run container\ndocker run -d \\\n  -p 3000:3000 \\\n  -v $(pwd)/data:/app/data \\\n  --name scrob \\\n  scrob\n```\n\n## Development\n\n### Prerequisites\n\n- Rust 1.82+\n- PostgreSQL 12+\n- sqlx-cli: `cargo install sqlx-cli --no-default-features --features postgres`\n\n### Setup\n\n```bash\n# Create PostgreSQL database\ncreatedb scrob\n\n# Or with custom user:\n# createuser -P scrob\n# createdb -O scrob scrob\n\n# Install dependencies\ncargo build\n\n# Run migrations\nexport DATABASE_URL=\"postgres://localhost/scrob\"\ncargo sqlx migrate run\n\n# Start server\ncargo run\n```\n\nSee [POSTGRES_SETUP.md](POSTGRES_SETUP.md) for detailed PostgreSQL setup instructions.\n\n### Environment Variables\n\n- `DATABASE_URL` - Database connection string (default: `postgres://localhost/scrob`)\n- `HOST` - Bind address (default: `127.0.0.1`)\n- `PORT` - Port number (default: `3000`)\n- `RUST_LOG` - Logging level (default: `scrob=info`)\n\nExample DATABASE_URL formats:\n```bash\n# Local development\npostgres://localhost/scrob\n\n# With authentication\npostgres://scrob:password@localhost/scrob\n\n# Remote with SSL\npostgres://user:pass@host:5432/scrob?sslmode=require\n```\n\n## Creating Users\n\n### Quick Bootstrap (Recommended)\n\nUse the interactive bootstrap script to create a user, login, and get tokens:\n\n```bash\n./scripts/bootstrap.sh\n```\n\nThis handles everything for you and outputs the tokens you need.\n\n### Using Python (requires bcrypt)\n\n```bash\npython3 -c \"\nimport psycopg2\nimport bcrypt\nimport time\n\nusername = 'alice'\npassword = 'mypassword'\nis_admin = True\n\nhash = bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()\ntimestamp = int(time.time())\n\nconn = psycopg2.connect('dbname=scrob user=scrob')\ncur = conn.cursor()\ncur.execute(\n    'INSERT INTO users (username, password_hash, is_admin, created_at) VALUES (%s, %s, %s, %s)',\n    (username, hash, is_admin, timestamp)\n)\nconn.commit()\nprint(f'User {username} created')\n\"\n```\n\n### Using the helper script\n\n```bash\n# Requires Python 3 with bcrypt installed\n./scripts/create_user.sh alice mypassword true\n```\n\n## REST API\n\n### Authentication\n\n```bash\n# Login and get token\ncurl -X POST http://localhost:3000/login \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"username\": \"alice\", \"password\": \"mypassword\"}'\n\n# Response: {\"token\": \"...\", \"username\": \"alice\", \"is_admin\": false}\n```\n\nUse the returned token in the `Authorization` header for all protected endpoints:\n```\nAuthorization: Bearer \u003ctoken\u003e\n```\n\n### Submit Scrobbles\n\n```bash\ncurl -X POST http://localhost:3000/scrob \\\n  -H \"Authorization: Bearer \u003ctoken\u003e\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '[{\n    \"artist\": \"Kendrick Lamar\",\n    \"track\": \"Wesley'\\''s Theory\",\n    \"album\": \"To Pimp a Butterfly\",\n    \"duration\": 287,\n    \"timestamp\": 1701619200\n  }]'\n```\n\n### Get Recent Scrobbles\n\n```bash\ncurl http://localhost:3000/recent?limit=20 \\\n  -H \"Authorization: Bearer \u003ctoken\u003e\"\n```\n\n### Get Top Artists\n\n```bash\ncurl http://localhost:3000/top/artists?limit=10 \\\n  -H \"Authorization: Bearer \u003ctoken\u003e\"\n```\n\n### Get Top Tracks\n\n```bash\ncurl http://localhost:3000/top/tracks?limit=10 \\\n  -H \"Authorization: Bearer \u003ctoken\u003e\"\n```\n\n### Now Playing\n\n```bash\ncurl -X POST http://localhost:3000/now \\\n  -H \"Authorization: Bearer \u003ctoken\u003e\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n    \"artist\": \"Pink Floyd\",\n    \"track\": \"Time\",\n    \"album\": \"The Dark Side of the Moon\"\n  }'\n```\n\n## Integration with last-fm-rs\n\nThis server is designed to work with the [last-fm-rs](https://github.com/ducks/last-fm-rs) client library in token mode:\n\n```rust\nuse last_fm_rs::Client;\n\nlet client = Client::with_token(\n  \"http://localhost:3000\",\n  \"your-api-token\"\n)?;\n\n// Use as normal\nclient.update_now_playing(\u0026now_playing).await?;\nclient.scrobble(\u0026scrobbles).await?;\n```\n\n## Database Schema\n\n### users\n- `id` - Primary key\n- `username` - Unique username\n- `password_hash` - Bcrypt password hash\n- `is_admin` - Admin flag\n- `created_at` - Unix timestamp\n\n### api_tokens\n- `id` - Primary key\n- `user_id` - Foreign key to users\n- `token` - Unique token string\n- `label` - Optional label (e.g., \"desktop\", \"phone\")\n- `created_at` - Unix timestamp\n- `last_used_at` - Unix timestamp (updated on use)\n- `revoked` - Revocation flag\n\n### scrobs\n- `id` - Primary key\n- `user_id` - Foreign key to users\n- `artist` - Artist name\n- `track` - Track name\n- `album` - Album name (optional)\n- `duration` - Duration in seconds (optional)\n- `timestamp` - When the track was played (Unix timestamp)\n- `created_at` - When the scrobble was recorded (Unix timestamp)\n\n## License\n\nMIT OR Apache-2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fducks%2Fscrob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fducks%2Fscrob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fducks%2Fscrob/lists"}