Skip to content

Instantly share code, notes, and snippets.

@konecnyna
Created October 1, 2019 19:41
Show Gist options
  • Save konecnyna/5db0de079367141922a94d59b51899f3 to your computer and use it in GitHub Desktop.
Save konecnyna/5db0de079367141922a94d59b51899f3 to your computer and use it in GitHub Desktop.
#!/bin/bash
seek=$(( ( RANDOM % 60 ) + 1 ))
omxplayer --loop fireplace_10_hours.mp3 -o alsa:hw:1,0 --vol -602 --pos 00:$seek:00
@konecnyna
Copy link
Author

const http = require('http');
const { execSync } = require('child_process');

const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'application/json');
  routes(req,res);
});

server.listen(port, () => {
  console.log(`Server running at http://localhost:${port}/`);
});


const getVol = () => {
  return execSync("amixer get -c 1 PCM | awk '$0~/%/{print $4}' | tr -d '[]'").toString().trim();
}
const routes = (req,res) => {
  const url = req.url;
  switch(url) {
    case "/vol-up":
      execSync('amixer -c 1 set PCM 5%+');
      res.end(JSON.stringify({ volume: getVol() }));
      break;
    case "/vol-down":
      execSync('amixer -c 1 set PCM 5%-');
      res.end(JSON.stringify({ volume: getVol() }));
      break;
    default:
      res.statusCode = 400
      res.end(JSON.stringify({ error: "Invalid route. please choose /vol-up /vol-down"}));
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment