Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-organize the code #352

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions .github/workflows/ci.yaml → .github/workflows/go-ci.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Go CI

on:
push:
Expand All @@ -10,19 +10,25 @@ jobs:

runs-on: ubuntu-latest

defaults:
run:
shell: bash
working-directory: ./go


steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install Go
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x
# We don't have it setup in the Makefile to avoid double-building, but 'make lint'
# requires the react build to have completed.
- run: make react
- run: make frontend

- run: make lint

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: push
defaults:
run:
shell: bash
working-directory: pickup-rust
working-directory: rs

jobs:
test:
Expand All @@ -22,7 +22,7 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
pickup-rust/target/
rs/target/
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
- name: Update rust toolchain
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
defaults:
run:
shell: bash
working-directory: pickup-rust
working-directory: rs

jobs:
build:
Expand All @@ -23,7 +23,7 @@ jobs:
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
pickup-rust/target/
rs/target/
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
- name: Update rust toolchain
run: |
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/pickup
/*.json

/pickup-rust/target/
Expand Down
28 changes: 12 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@

GO_FILES = $(shell find . -iname '*.go')
.PHONY: frontend go rs clean lint

pickup: react
make pickup-only
go:
cd go && make pickup

pickup-only: main.go $(GO_FILES)
go build
frontend:
cd go/frontend && yarn build

react: deps
cd react && yarn build
rs:
cd rs && cargo build

deps: react/yarn.lock react/package.json
cd react && yarn install
lint:
cd go && make lint
cd rs && cargo clippy

# go vet requires the files in react/dist
lint: deps $(GO_FILES)
go vet && cd react && yarn lint

.PHONY: react clean deps pickup
clean:
rm -rf react/dist
go clean
cd go && make clean
cd rs && cargo clean
69 changes: 13 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![CI](https://github.com/werkshy/pickup/actions/workflows/ci.yaml/badge.svg)](https://github.com/werkshy/pickup/actions/workflows/ci.yaml)

This is pickup (in go), a web frontend for [Music Player Daemon](http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki).
This is pickup, a web-based music player.

Pickup is my white whale... I've been playing with the idea since 2007. I have a
large music collection, and my navigation of choice is by album, with easy
Expand All @@ -11,61 +11,17 @@ close, but the uploaded never worked for me and now the product is dead.

## Status

There's a functioning, but abandoned, Go and React version in [go/](./go/README.md) that works as a frontend to [Music Player Daemon](http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki).
It works, more or less. You can add albums and tracks to the playlist, control
volume, skip tracks, start/stop playback. You can view the playlist. It runs on
the Raspberry Pi with room to run mpd as well. Because of the client-side
architecture it is very fast.

In mid-2021, I have started rewriting the backend in Rust. The two motiviations for this are:
In mid-2021, I started rewriting the backend in Rust. The two motiviations for this are:

- This is the project I usually use to learn a new language or framework
- I want to get away from mpd and have a single executable that can do the web part, plus control the playlist and actually play music, and set us up for playback in the browser. This is basically a complete rewrite anyway.

## Getting Started In Ubuntu

# The React frontend requires the 'yarn' package manager -
# install it like this:
sudo apt install nodejs

# This next command might require 'sudo' as well.
npm install -g yarn

# Requires go > v1.16, which is best installed via `snap` on Ubuntu.
sudo snap install --classic go
# Install yarn dependencies, build the frontend, and build the binary:
make build

# Run the binary
./pickup --help
./pickup

## Getting Started on macOS / brew

# Requires go > 1.16 for the embed feature
brew install yarn golang
make

## Getting Started Cross-Compiling for Raspberry Pi

Assuming you installed go as a snap, you should be able to cross-compile for
the Pi like this:

GOOS=linux GOARCH=arm GOARM=5 go build

Now copy the pickup binary to your pi and run

./pickup

## Install As A Service

Copy init.d/pickup to /etc/init.d

Edit the script and set these vars to suit your setup. I'm lazy and just run as
my main user, definitely don't do this on the internet!

SCRIPT=/home/oneill/pickup/pickup
RUNAS=oneill

## Background

I've written functional prototypes of this in C++, Python, C++ again (I was
Expand All @@ -92,18 +48,19 @@ contributions would be much appreciated.

## Design Approach

- The Go implementation is a simple backend serving JSON to a React frontend.
- The frontend loads the entire music collection up front. This takes less than
#### Go Version:

- The Go implementation is a simple backend serving JSON to a React frontend, and requires MPD
for actually indexing and playing music.
- The simple React frontend loads the entire music collection up front. This takes less than
a second and makes navigating around the collection extremely fast.

## Roadmap
#### Rust Version:

- Backend: I'm working on a re-write of the backend in Rust, and dropping the
mpd dependency.
- Frontend: Upgrade to Typescript, maybe start using create-react-app to make
the build more vanilla.
- Frontend: Allow playback in the browser.
- Built-in music player in the server and file indexing, so no need for MPD.
- I intend to add in-browser music playback as well.
- There's no frontend yet but I will either port the Go version to Typescript and React or write a new one in Svelte.

## Screenshot

![Screenshot](./screenshot.png)
![Screenshot (Go/React version)](./screenshot.png)
13 changes: 0 additions & 13 deletions deploy-pi

This file was deleted.

6 changes: 6 additions & 0 deletions go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/pickup
/*.json

/pickup-rust/target/
.idea/
.cache/
5 changes: 5 additions & 0 deletions go/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.exclude": {
"**/frontend/**": true
}
}
23 changes: 23 additions & 0 deletions go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

GO_FILES = $(shell find . -iname '*.go')

pickup: frontend
make pickup-only

pickup-only: main.go $(GO_FILES)
go build

frontend: deps
cd frontend && yarn build

deps: frontend/yarn.lock frontend/package.json
cd frontend && yarn install

# go vet requires the files in frontend/dist
lint: deps $(GO_FILES)
go vet && cd frontend && yarn lint

.PHONY: frontend clean deps pickup
clean:
rm -rf frontend/dist
go clean
57 changes: 57 additions & 0 deletions go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Pickup

[![CI](https://github.com/werkshy/pickup/actions/workflows/go-ci.yaml/badge.svg)](https://github.com/werkshy/pickup/actions/workflows/go-ci.yaml)

This is pickup (in go), a web frontend for [Music Player Daemon](http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki).

## Status

It works, more or less. You can add albums and tracks to the playlist, control
volume, skip tracks, start/stop playback. You can view the playlist. It runs on
the Raspberry Pi with room to run mpd as well. Because of the client-side
architecture it is very fast.

## Getting Started In Ubuntu

# The React frontend requires the 'yarn' package manager -
# install it like this:
sudo apt install nodejs

# This next command might require 'sudo' as well.
npm install -g yarn

# Requires go > v1.16, which is best installed via `snap` on Ubuntu.
sudo snap install --classic go
# Install yarn dependencies, build the frontend, and build the binary:
make build

# Run the binary
./pickup --help
./pickup

## Getting Started on macOS / brew

# Requires go > 1.16 for the embed feature
brew install yarn golang
make

## Getting Started Cross-Compiling for Raspberry Pi

Assuming you installed go as a snap, you should be able to cross-compile for
the Pi like this:

GOOS=linux GOARCH=arm GOARM=5 go build

Now copy the pickup binary to your pi and run

./pickup

## Install As A Service

Copy init.d/pickup to /etc/init.d

Edit the script and set these vars to suit your setup. I'm lazy and just run as
my main user, definitely don't do this on the internet!

SCRIPT=/home/oneill/pickup/pickup
RUNAS=oneill
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion main.go → go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
}

// Embed the compiled frontend files
//go:embed react/dist
//go:embed frontend/dist
var embedded embed.FS

func serve(conf *config.Config, plyr player.Player) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions pickup.code-workspace
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"folders": [
{
"path": "."
"path": "go"
},
{
"path": "react"
"path": "go/frontend",
"name": "frontend"
},
{
"path": "pickup-rust"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading