Browse Source

refactor: changed weight_stations experimental feature to support multiple tag names

Kristian Vos 1 year ago
parent
commit
13e4f3da59
2 changed files with 18 additions and 13 deletions
  1. 9 10
      backend/config/template.json
  2. 9 3
      backend/logic/stations.js

+ 9 - 10
backend/config/template.json

@@ -116,17 +116,16 @@
 	},
 	"configVersion": 11,
 	"experimental": {
-		"weight_stations": [
-			"STATION_ID"
-		],
-		"queue_autofill_skip_last_x_played": {
-			"STATION_ID": 5
+		"weight_stations": {
+			"STATION_ID": true,
+			"STATION_ID_2": "alternative_weight",
 		},
-		"queue_autofill_skip_played_in_last_x_minutes": {
-			"STATION_ID": 5
+		"queue_autofill_skip_last_x_played": {
+			"STATION_ID": 5,
+			"STATION_ID_2": 10
 		},
-		"queue_add_before_autofilled": {
-			"STATION_ID": true
-		}
+		"queue_add_before_autofilled": [
+			"STATION_ID"
+		]
 	}
 }

+ 9 - 3
backend/logic/stations.js

@@ -564,9 +564,13 @@ class _StationsModule extends CoreClass {
 
 						// Block for experiment: weight_stations
 						if (
-							config.has("experimental.weight_stations") &&
-							config.get("experimental.weight_stations").indexOf(stationId) !== -1
+							config.has(`experimental.weight_stations.${stationId}`) &&
+							!!config.get(`experimental.weight_stations.${stationId}`)
 						) {
+							const weightTagName =
+								config.get(`experimental.weight_stations.${stationId}`) === true
+									? "weight"
+									: config.get(`experimental.weight_stations.${stationId}`);
 							const weightMap = {};
 							const getYoutubeIds = playlistSongs
 								.map(playlistSong => playlistSong.youtubeId)
@@ -574,11 +578,13 @@ class _StationsModule extends CoreClass {
 
 							const { songs } = await SongsModule.runJob("GET_SONGS", { youtubeIds: getYoutubeIds });
 
+							const weightRegex = new RegExp(`${weightTagName}\\[(\\d+)\\]`);
+
 							songs.forEach(song => {
 								let weight = 1;
 
 								song.tags.forEach(tag => {
-									const regexResponse = /weight\[(\d+)\]/.exec(tag);
+									const regexResponse = weightRegex.exec(tag);
 									if (regexResponse) weight = Number(regexResponse[1]);
 								});