Skip to content

Commit

Permalink
change TPE2 handling once more
Browse files Browse the repository at this point in the history
  • Loading branch information
oweitman committed Oct 27, 2024
1 parent 526adc5 commit c77a0b2
Show file tree
Hide file tree
Showing 11 changed files with 688 additions and 946 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ admin/i18n/*/flat.txt
# ioBroker dev-server
.dev-server/
.vscode/secrets.txt
.vscode/info.md
.vscode/info.xlsx
.vscode/~$info.xlsx
14 changes: 5 additions & 9 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"list-marker-space": {
"ul_multi": 3,
"ul_single": 3
},
"ul-indent": {
"indent": 4
},
"first-line-heading": false
}
"first-line-heading": false,
"MD013": {
"tables": false
}
}
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Program",
"program": "../iobroker.repochecker/index.js",
"args": ["https://github.com/oweitman/ioBroker.squeezeboxrpc","main","--local"],
"request": "launch",
"stopOnEntry": true,
"runtimeExecutable": "c:/Users/oweit/AppData/Roaming/fnm/aliases/default/node.exe",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"type": "node",
"request": "launch",
Expand Down
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
"fileMatch": ["admin/jsonConfig.json", "admin/jsonCustom.json", "admin/jsonTab.json"],
"url": "https://raw.githubusercontent.com/ioBroker/adapter-react-v5/main/schemas/jsonConfig.json"
}
]
],
"[markdown]": {
"editor.wordWrap": "off"
}
}
661 changes: 469 additions & 192 deletions README.md

Large diffs are not rendered by default.

15 changes: 0 additions & 15 deletions admin/jsonConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,6 @@
"lg": 4,
"xl": 4,
"newLine": true
},
"TPE2Handling": {
"type": "select",
"label": "TPE2 Handling",
"options": [
{ "label": "TPE2 as Band", "value": "TPE2Band" },
{ "label": "TPE2 as Artist of Album (default)", "value": "TPE2Artist" }
],
"default": "TPE2Artist",
"xs": 12,
"sm": 12,
"md": 6,
"lg": 4,
"xl": 4,
"newLine": true
}
}
},
Expand Down
72 changes: 22 additions & 50 deletions lib/iosbplayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function ioSBPlayer(server, playerdata) {

this.islogsilly = this.adapter.config.outputplayersilly;
this.islogdebug = this.adapter.config.outputplayerdebug;
this.TPE2Handling = this.adapter.config.TPE2Handling || "TPE2Artist";
this.TPE2Handling = 1;

this.FORBIDDEN_CHARS = /[^\d\w_]+/gm;
//test the regex: https://regex101.com/r/Ed0WhH/1
Expand Down Expand Up @@ -265,31 +265,30 @@ function ioSBPlayer(server, playerdata) {
role: "media.artist",
exist: false
},
"artistOriginal": {
name: "ArtistOriginal",
"albumartist": {
name: "Albumartist",
read: true,
write: false,
type: "string",
role: "media.artist",
exist: false
},
"albumartist": {
name: "Albumartist",
"trackartist": {
name: "Trackartist",
read: true,
write: false,
type: "string",
role: "media.artist",
exist: false
},
"trackartist": {
name: "Trackartist",
"band": {
name: "Band",
read: true,
write: false,
type: "string",
role: "media.artist",
exist: false
},
"url": {
}, "url": {
name: "Url",
read: true,
write: false,
Expand Down Expand Up @@ -603,45 +602,11 @@ function ioSBPlayer(server, playerdata) {
value = decodeURIComponent(m[1]);
}
}
if (key == "artist") {
const artist = value;
if (this.TPE2Handling == "TPE2Band") {
if (Object.prototype.hasOwnProperty.call(playerdata, "trackartist")) {
value = playerdata["trackartist"];
}
if (Object.prototype.hasOwnProperty.call(playerdata, "albumartist")) {
value = playerdata["albumartist"];
}
} else {
if (Object.prototype.hasOwnProperty.call(playerdata, "albumartist")) {
value = playerdata["albumartist"];
}
}
this.setState(this.sbPlayerStatusLoop["artistOriginal"].name, this.convertState(this.sbPlayerStatusLoop["artistOriginal"], artist), this.statePath, this.playername);
}
if (key == "albumartist") {
if (this.TPE2Handling == "TPE2Band") {
if (Object.prototype.hasOwnProperty.call(playerdata, "trackartist")) {
value = playerdata["trackartist"];
}
if (Object.prototype.hasOwnProperty.call(playerdata, "albumartist")) {
value = playerdata["albumartist"];
}
} else {
if (Object.prototype.hasOwnProperty.call(playerdata, "albumartist")) {
value = playerdata["albumartist"];
}
}
this.setState(this.sbPlayerStatusLoop["artist"].name, this.convertState(this.sbPlayerStatusLoop["artist"], value), this.statePath, this.playername);
}
if (key == "trackartist") {
if (this.TPE2Handling == "TPE2Band") {
if (Object.prototype.hasOwnProperty.call(playerdata, "trackartist") && !Object.prototype.hasOwnProperty.call(playerdata, "albumartist")) {
value = playerdata["trackartist"];
}
}
this.setState(this.sbPlayerStatusLoop["artist"].name, this.convertState(this.sbPlayerStatusLoop["artist"], value), this.statePath, this.playername);
}
/* if (key == "artist" || key == "albumartist" || key == "trackartist") {
console.log("artist", playerdata["artist"]);
console.log("albumartist", playerdata["albumartist"]);
console.log("trackartist", playerdata["trackartist"]);
} */
this.setState(this.sbPlayerStatusLoop[key].name, this.convertState(this.sbPlayerStatusLoop[key], value), this.statePath, this.playername);
} else {
if (key == "remote_title" && this.remote == 0) {
Expand Down Expand Up @@ -802,8 +767,12 @@ function ioSBPlayer(server, playerdata) {
}
if (idParts[0] == "cmdGeneral") {
if (state.val !== " ") {
const cmd = JSON.parse("[" + state.val + "]");
this.request(this.playerid, cmd);
try {
const cmd = JSON.parse("[" + state.val + "]");
this.request(this.playerid, cmd);
} catch (error) {
this.logerror("cmdGeneral, Parameter error: " + state.val);
}
this.setState(idParts[0], " ", this.statePath, this.playername, false);
}
}
Expand Down Expand Up @@ -870,6 +839,9 @@ function ioSBPlayer(server, playerdata) {
this.request = function (playerid, params, callback) {
if (this.connected) this.server.request(playerid, params, callback);
};
this.setTPE2Handling = function (value) {
this.TPE2Handling = value;
};
this.setState = function (name, value, level1path, level2path, check = true) {
name = (level1path ? level1path + "." : "") + (level2path ? level2path + "." : "") + name;
if (this.currentStates[name] !== value && check) {
Expand Down
62 changes: 42 additions & 20 deletions lib/iosbserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,28 +378,33 @@ function IoSbServer(adapter) {
});
this.telnet.on("data", (data) => {
this.logdebug("doTelnet received Data: " + data.toString());
//console.log(decodeURIComponent(data.toString()));
const regex = /^((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))\s*(.*)/gm;
let m;
if ((m = regex.exec(decodeURIComponent(data.toString()))) !== null) {
if (m[2] == "client reconnect") {
this.logdebug("doTelnet received reconnect for : " + m[1]);
this.getServerstatus();
}
if (m[2] == "client disconnect") {
this.logdebug("doTelnet received disconnect for : " + m[1]);
this.getServerstatus();
}
if (m[2] == "client new") {
this.logdebug("doTelnet received disconnect for : " + m[1]);
this.getServerstatus();
}
if (m[2] == "power 0") {
this.logdebug("doTelnet received power off : " + m[1]);
this.getServerstatus();
}
if (m[2] == "power 1") {
this.logdebug("doTelnet received power on : " + m[1]);
this.getServerstatus();
const cmdQueue = decodeURIComponent(data.toString()).split("\r\n");
for (const cmd of cmdQueue) {

if ((m = regex.exec(cmd)) !== null) {
if (m[2] == "client reconnect") {
this.logdebug("doTelnet received reconnect for : " + m[1]);
this.getServerstatus();
}
if (m[2] == "client disconnect") {
this.logdebug("doTelnet received disconnect for : " + m[1]);
this.getServerstatus();
}
if (m[2] == "client new") {
this.logdebug("doTelnet received disconnect for : " + m[1]);
this.getServerstatus();
}
if (m[2] == "power 0") {
this.logdebug("doTelnet received power off : " + m[1]);
this.getServerstatus();
}
if (m[2] == "power 1") {
this.logdebug("doTelnet received power on : " + m[1]);
this.getServerstatus();
}
}
}
});
Expand Down Expand Up @@ -556,6 +561,7 @@ function IoSbServer(adapter) {
};
this.checkPlayer = function (playersdata) {
this.logdebug("checkPlayer");
this.checkTPE2();
for (const key in playersdata) {
if (this.players[playersdata[key].playerid].connected != playersdata[key].connected) {
if (playersdata[key].connected == 0) {
Expand All @@ -567,6 +573,22 @@ function IoSbServer(adapter) {
}
}
};
this.checkTPE2 = function () {
const that = this;
this.request("", ["pref", "useTPE2AsAlbumArtist", "?"], function (result) {
if (result.ok) {
if (Object.keys(result.result).length > 0) {
const value = result.result[Object.keys(result.result)[0]];
for (const key in that.players) {
if (Object.prototype.hasOwnProperty.call(that.players, key)) {
// console.log("setTPE2Handling", key, value);
that.players[key].setTPE2Handling(parseInt(value));
}
}
}
}
}.bind(this));
};
this.stateChange = function (id, state) {
this.logsilly("stateChange");
// Warning, state can be null if it was deleted
Expand Down
Loading

0 comments on commit c77a0b2

Please sign in to comment.