Skip to content

Commit

Permalink
Merge pull request #43 from geovannimp/main
Browse files Browse the repository at this point in the history
Add Mixxx support
  • Loading branch information
erikrichardlarson authored May 18, 2021
2 parents 5c83522 + 233550a commit 6881591
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# unbox - rekordbox / Serato / Traktor / VirtualDJ / Denon "Now Playing" overlays for Twitch / OBS
# unbox - rekordbox / Serato / Traktor / VirtualDJ / Denon / Mixxx "Now Playing" overlays for Twitch / OBS

Display your current or recent rekordbox / serato / traktor / virtualdj / denon tracks to your viewers on Twitch. Inspired by PRACT OBS and ASOT.
Display your current or recent rekordbox / serato / traktor / virtualdj / denon, mixxx tracks to your viewers on Twitch. Inspired by PRACT OBS and ASOT.
<p align="center">
<img src="https://cdn.discordapp.com/attachments/780172543771410452/783904760880562176/Screen_Shot_2020-12-02_at_7.56.55_PM.png" />
</p>
Expand Down
6 changes: 6 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ <h6 id="headerHands">🙌</h6>
Traktor
</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="mode" id="mixxx">
<label class="form-check-label" for="mixxx">
Mixxx
</label>
</div>
<div id="kuvo_url" style="display: none;">
<hr class="mt-3 mb-3" />

Expand Down
42 changes: 42 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class PlayHistory {
this.homeFolder = process.env.APPDATA || (process.platform == 'darwin' ? process.env.HOME + '/Library/Application Support' : process.env.HOME + "/.local/share");
this.optionsPath = process.platform != 'darwin' ? this.homeFolder + '\\Pioneer\\rekordboxAgent\\storage\\options.json' : this.homeFolder + '/Pioneer/rekordboxAgent/storage/options.json';
this.outputPath = process.platform != 'darwin' ? require('os').homedir() + '\\unbox_output' : require('os').homedir() + '/unbox_output';
this.mixxxDatabasePath = process.platform != 'darwin' ? process.env.HOME + '\\AppData\\Local\\Mixxx\\mixxxdb.sqlite' : this.homeFolder + '/Mixxx';

this.streamTxtPath = process.env.APPDATA ? this.outputPath + '\\rekordbox_stream.txt' : this.outputPath + '/rekordbox_stream.txt';
this.streamJSONPath = process.env.APPDATA ? this.outputPath + '\\rekordbox_stream.json' : this.outputPath + '/rekordbox_stream.json';
Expand Down Expand Up @@ -423,6 +424,47 @@ class PlayHistory {
}
})
}
else if (_this.mode == 'mixxx') {
let db = new sqlite3.Database(_this.mixxxDatabasePath)
db.serialize(function () {
db.each(`
select
li.artist, li.title, li.bpm, pt.pl_datetime_added
from PlaylistTracks pt
left join library li on li.id = pt.track_id
order by pt.pl_datetime_added desc
limit 1
`, function (err, row) {
var artist = row.artist;
var track = row.title;
_this.trackTimestamp = Math.floor(Date.parse(row.pl_datetime_added + " GMT") / 1000);

if ((_this.startTimeStamp) && (_this.startTimeStamp > _this.trackTimestamp)) {
fs.writeFileSync(_this.streamTxtPath, '');
fs.writeFileSync(_this.streamJSONPath, JSON.stringify({ artist: '', track: '' , remix: '', label: ''}));
fs.writeFileSync(_this.historyJSONPath, JSON.stringify({ tracks: [{ artist: '', track: '' , remix: '', label: ''}, { artist: '', track: '' , remix: '', label: ''}, { artist: '', track: '' , remix: '', label: ''}] }));
_this.playlistHistory = [{ artist: '', track: '' , remix: '', label: ''}, { artist: '', track: '' , remix: '', label: ''}, { artist: '', track: '' , remix: '', label: ''}];
}
if ((track.toUpperCase() != _this.mostrecentTrack) && (!_this.startTimeStamp || (_this.startTimeStamp < _this.trackTimestamp))) {
_this.mostRecentArtist = artist.toUpperCase();
_this.mostrecentTrack = track.toUpperCase();
fs.access(_this.historyJSONPath, function (error) {
if (error) {
fs.writeFileSync(_this.historyJSONPath, JSON.stringify({ tracks: [{ artist: _this.mostRecentArtist, track: _this.mostrecentTrack }] }));
}
else {
let history = JSON.parse(fs.readFileSync(_this.historyJSONPath))['tracks'];
if ((history) && (history.length == 3)) {
history.pop()
}
_this.playlistHistory = [{ artist: artist.toUpperCase(), track: track.toUpperCase() }].concat(history);
}
})
}
})
})
db.close();
}
else if (_this.mode == 'rekordbox') {
let db_path = JSON.parse(fs.readFileSync(_this.optionsPath))['options'][0][1];
let db = new sqlite3.Database(db_path)
Expand Down
6 changes: 6 additions & 0 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ checkboxes.forEach(function (checkbox) {
document.getElementById('kuvo_url').style['display'] = 'None';
}

if (mode[0] == 'mixxx') {
document.getElementById('header').innerHTML = `<h6>You're now logging your Mixxx history</h6>
<h6 id="headerHands"></h6>`;
document.getElementById('kuvo_url').style['display'] = 'None';
}

document.getElementById('headerHands').innerText = '🙌';

})
Expand Down

0 comments on commit 6881591

Please sign in to comment.