<commit_before>#!/usr/bin/env node

'use strict';

const MUSIC_ROOT = '/Users/snichol/music';

const express = require('express');
const morgan = require('morgan');
const mp3store = require('./mp3store');

const app = express();

app.use(morgan('combined'));
app.use('/music', express.static(MUSIC_ROOT));
app.use('/', express.static(__dirname + '/www'));

app.get('/api/artists', (req, res) => {
  mp3store.getArtists((err, artists) => {
    if (err) {
      res.status(500);
      res.send(err);
    } else {
      res.send(artists);
    }
  });
});

app.get('/api/artists/:artist/albums', (req, res) => {
  mp3store.getArtistAlbums(req.params.artist, (err, albums) => {
    if (err) {
      res.status(500);
      res.send(err);
    } else {
      res.send(albums);
    }
  });
});

app.get('/api/artists/:artist/albums/:album/tracks', (req, res) => {
  mp3store.getAlbumTracks(req.params.artist, req.params.album, (err, tracks) => {
    if (err) {
      res.status(500);
      res.send(err);
    } else {
      tracks.sort((t1, t2) => {
        return t1.trackNumber - t2.trackNumber;
      });
      let trackNames = tracks.map((track) => {
        return track.track;
      });
      res.send(trackNames);
    }
  });
});

app.get('/api/artists/:artist/albums/:album/tracks/:track/details', (req, res) => {
  mp3store.getTrackDetails(req.params.artist, req.params.album, req.params.track, (err, details) => {
    if (err) {
      res.status(500);
      res.send(err);
    } else {
      details.path = details.path.startsWith(MUSIC_ROOT) ? details.path.substr(MUSIC_ROOT.length, details.path.length) : details.path;
      res.send(details);
    }
  });
});

const port = process.env.PORT || 3000;
app.listen(port, (err) => {
  if (err) {
    console.error('Error ' + err + ' trying to listen on port ' + port);
  } else {
    console.info('Listening on port ' + port);
  }
});
<commit_msg>Allow music root to be set via the environment<commit_after>#!/usr/bin/env node

'use strict';

const MUSIC_ROOT = process.env.MUSIC_ROOT || '/Users/snichol/music';

const express = require('express');
const morgan = require('morgan');
const mp3store = require('./mp3store');

const app = express();

app.use(morgan('combined'));
app.use('/music', express.static(MUSIC_ROOT));
app.use('/', express.static(__dirname + '/www'));

app.get('/api/artists', (req, res) => {
  mp3store.getArtists((err, artists) => {
    if (err) {
      res.status(500);
      res.send(err);
    } else {
      res.send(artists);
    }
  });
});

app.get('/api/artists/:artist/albums', (req, res) => {
  mp3store.getArtistAlbums(req.params.artist, (err, albums) => {
    if (err) {
      res.status(500);
      res.send(err);
    } else {
      res.send(albums);
    }
  });
});

app.get('/api/artists/:artist/albums/:album/tracks', (req, res) => {
  mp3store.getAlbumTracks(req.params.artist, req.params.album, (err, tracks) => {
    if (err) {
      res.status(500);
      res.send(err);
    } else {
      tracks.sort((t1, t2) => {
        return t1.trackNumber - t2.trackNumber;
      });
      let trackNames = tracks.map((track) => {
        return track.track;
      });
      res.send(trackNames);
    }
  });
});

app.get('/api/artists/:artist/albums/:album/tracks/:track/details', (req, res) => {
  mp3store.getTrackDetails(req.params.artist, req.params.album, req.params.track, (err, details) => {
    if (err) {
      res.status(500);
      res.send(err);
    } else {
      details.path = details.path.startsWith(MUSIC_ROOT) ? details.path.substr(MUSIC_ROOT.length, details.path.length) : details.path;
      res.send(details);
    }
  });
});

const port = process.env.PORT || 3000;
app.listen(port, (err) => {
  if (err) {
    console.error('Error ' + err + ' trying to listen on port ' + port);
  } else {
    console.info('Listening on port ' + port);
  }
});

{'fraction_non_alphanumeric': 0.1979734996102884, 'fraction_numerical': 0.013510002598077423, 'mean_word_length': 2.964984552008239, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3786344', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1412, 'n_words': 231}