<commit_before>const spotify = new require('./node-spotify-webhelper').SpotifyWebHelper()
const EventEmitter = require('events')

let loopId, lastSongId = []

module.exports = exports = new EventEmitter()

let getTrackId = track => ['track', 'artist', 'album'].map(x => track[x + '_resource'].uri)
let equals = (a, b) => a.length === b.length && a.every((x, i) => x === b[i])

exports.listen = function() {
    let loop = () => spotify.getStatus((err, result) => {
        if (err || result.error || !result.running) return

        clearTimeout(loopId)
        loopId = setTimeout(loop, Math.min(result.track.length - result.playing_position, 1) * 1000)

        if (equals(lastSongId, getTrackId(result.track)))
            return exports.emit('song-progress', result)

        lastSongId = getTrackId(result.track)
        exports.emit('song-update', result)<commit_msg>Lazily instantiate SpotifyWebHelper to boost startup speed<commit_after>const {SpotifyWebHelper} = new require('./node-spotify-webhelper')
const EventEmitter = require('events')

let spotify, loopId, lastSongId = []

module.exports = exports = new EventEmitter()

let getTrackId = track => ['track', 'artist', 'album'].map(x => track[x + '_resource'].uri)
let equals = (a, b) => a.length === b.length && a.every((x, i) => x === b[i])

exports.listen = function() {
    if (spotify == null) spotify = new SpotifyWebHelper()

    let loop = () => spotify.getStatus((err, result) => {
        if (err || result.error || !result.running) return

        clearTimeout(loopId)
        loopId = setTimeout(loop, Math.min(result.track.length - result.playing_position, 1) * 1000)

        if (equals(lastSongId, getTrackId(result.track)))
            return exports.emit('song-progress', result)

        lastSongId = getTrackId(result.track)
        exports.emit('song-update', result)
{'fraction_non_alphanumeric': 0.16261480280929227, 'fraction_numerical': 0.005402485143165856, 'mean_word_length': 3.7487179487179487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '67150', 'n_tokens_mistral': 593, 'n_tokens_neox': 565, 'n_words': 132}