// Copyright 2014-2025 Jesper Larsson
//
// This file is part of Klipspringer, <https://klipspringer.avadeaux.net/>
//
// Klipspringer is free software: you can redistribute it and/or modify it under the terms of the
// GNU General Public License as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// Klipspringer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with Klipspringer. If
// not, see <https://www.gnu.org/licenses/>.

import * as net from 'net';
import { unlink, open } from 'fs/promises';

if (process.argv.length !== 4) {
    log.error("Utility to fetch audiostream from running track player and save it as a file.\n"
              +"Example:\n"
              +"    trackplayer -output none -controlsock foo.sock 01.music.flac\n"
              +"    node lib/node/savestream.js foo.sock saved.mp3");
    process.exit(1);
}

const controlPath = process.argv[2];
const fnam = process.argv[3];
const fh = await open(fnam, "w");

const sock = net.connect(controlPath, () => {
    sock.write(Object.entries({
        cmd: 'fetchstream',
        type: fnam.slice(fnam.lastIndexOf('.')+1),
        writeahead: '9223372036854775807'
    }).map(([p, v]) => p+'='+encodeURIComponent(v.toString())).join('&')+'\n');
});
sock.on('data', chunk => { fh.write(chunk) })
    .on('end', () => { fh.close(); process.exit(0) })
    .on('close', () => { fh.close(); process.exit(0) })
    .on('error', err => { log.error(err) });

Version: v4.3.2.2 (2026-05-16T17:03:34+02:00)
Raw file
Source code overview
Klipspringer home