<commit_before>'use strict';

var icecast = require('icecast'),
    lame = require('lame'),
    _ = require('underscore')._;

function Shuffler(app, library) {
    var self = this;

    self.app = app;
    self.encoder = lame.Encoder({channels: 2, bitDepth: 16, sampleRate: 44100});
    self.decoder = lame.Decoder();
    self.clients = [];
    self.sseClients = [];
    self.library = library;
    self.changeSourceCounter = 0;
    self.track = '';
    self.init();
}

Shuffler.prototype.init = function () {
    var self = this;

    self.encoder.on('data', function (data) {
        self.sendData(data);
    });

    self.decoder.on('format', function (/*format*/) {
        self.decoder.pipe(self.encoder);
    });

    self.shuffle();
};

Shuffler.prototype.shuffle = function () {
    var self = this;

    self.changeSourceCounter = 0;
    self.library.next();
    //console.log('current: ' + self.library.current());
    icecast.get(self.library.current(), function (res) {
        res.on('data', function (data) {
            self.decoder.write(data);
        });

        res.on('metadata', function (metadata) {
            if (self.changeSourceCounter === 5) {
                res.end();
                self.shuffle();
            } else {
                ++self.changeSourceCounter;
            }
            self.track = icecast.parse(metadata).StreamTitle;
            self.publishTrackInfo();
        });
    });
};

Shuffler.prototype.sendData = function (data) {<commit_msg>rebuilt app after zero-client bandwidth limiting change<commit_after>'use strict';

var icecast = require('icecast'),
    lame = require('lame'),
    _ = require('underscore')._;

function Shuffler(app, library) {
    var self = this;

    self.app = app;
    self.encoder = lame.Encoder({channels: 2, bitDepth: 16, sampleRate: 44100});
    self.decoder = lame.Decoder();
    self.clients = [];
    self.sseClients = [];
    self.library = library;
    self.changeSourceCounter = 0;
    self.track = '';
    self.init();
}

Shuffler.prototype.init = function () {
    var self = this;

    self.encoder.on('data', function (data) {
        self.sendData(data);
    });

    self.decoder.on('format', function (/*format*/) {
        self.decoder.pipe(self.encoder);
    });

    self.shuffle();
};

Shuffler.prototype.shuffle = function () {
    var self = this;

    self.changeSourceCounter = 0;
    self.library.next();
    //console.log('current: ' + self.library.current());
    icecast.get(self.library.current(), function (res) {
        if (self.clients.length === 0) {
            res.end();
            self.shuffle();
        }

        res.on('data', function (data) {
            self.decoder.write(data);
        });

        res.on('metadata', function (metadata) {
            if (self.changeSourceCounter === 5) {
                res.end();
                self.shuffle();
            } else {
                ++self.changeSourceCounter;
            }
            self.track = icecast.parse(metadata).StreamTitle;
            self.publishTrackInfo();
        });
    });
};

Shuffler.prototype.sendData = function (data) {
{'fraction_non_alphanumeric': 0.1603321622484829, 'fraction_numerical': 0.007345895879910571, 'mean_word_length': 2.2255406797116373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7461799', 'n_tokens_mistral': 989, 'n_tokens_neox': 933, 'n_words': 171}