Browse Source

feat: added experimental option to disable YouTube search on the backend

Kristian Vos 1 year ago
parent
commit
469a75b85e
3 changed files with 17 additions and 7 deletions
  1. 1 0
      .wiki/Configuration.md
  2. 2 1
      backend/config/template.json
  3. 14 6
      backend/logic/youtube.js

+ 1 - 0
.wiki/Configuration.md

@@ -61,6 +61,7 @@ Location: `backend/config/default.json`
 | `experimental.weight_stations` | Experimental option to use weights when autofilling stations, looking at the weight[X] tag for songs. Must be an object, key must be station id's, value can be true or a string. If true, it uses tag name `weight`. If a string, it uses that string as the tag name. |
 | `experimental.queue_autofill_skip_last_x_played` | Experimental option to not autofill songs that were played recently. Must be an object, key must be station id's, value must be a number. The number equals how many songs it will consider recent and use when checking if it can autofill. |
 | `experimental.queue_add_before_autofilled` | Experimental option to have requested songs in queue appear before autofilled songs, based on the autofill number. Must be true or an object. If true, it's enabled for all stations. If an object, key must be station id's, value must be true to enable for that station. |
+| `experimental.disable_youtube_search` | Experimental option to disable YouTube search on the backend. If true, this option is enabled. |
 
 ## Frontend
 

+ 2 - 1
backend/config/template.json

@@ -126,6 +126,7 @@
 		},
 		"queue_add_before_autofilled": [
 			"STATION_ID"
-		]
+		],
+		"disable_youtube_search": true
 	}
 }

+ 14 - 6
backend/logic/youtube.js

@@ -216,6 +216,7 @@ class _YouTubeModule extends CoreClass {
 				})
 				.catch(err => {
 					YouTubeModule.log("ERROR", "SEARCH", `${err.message}`);
+					if (err.message === "Searching with YouTube is disabled.") return reject(err);
 					return reject(new Error("An error has occured. Please try again later."));
 				});
 		});
@@ -498,9 +499,9 @@ class _YouTubeModule extends CoreClass {
 				})
 				.catch(err => {
 					YouTubeModule.log("ERROR", "GET_CHANNEL_UPLOADS_PLAYLIST_ID", `${err.message}`);
-					if (err.message === "Request failed with status code 404") {
+					if (err.message === "Request failed with status code 404")
 						return reject(new Error("Channel not found. Is the channel public/unlisted?"));
-					}
+					if (err.message === "Searching with YouTube is disabled.") return reject(err);
 					return reject(new Error("An error has occured. Please try again later."));
 				});
 		});
@@ -588,9 +589,9 @@ class _YouTubeModule extends CoreClass {
 				(err, channelId) => {
 					if (err) {
 						YouTubeModule.log("ERROR", "GET_CHANNEL_ID_FROM_CUSTOM_URL", `${err.message || err}`);
-						if (err.message === "Request failed with status code 404") {
+						if (err.message === "Request failed with status code 404")
 							return reject(new Error("Channel not found. Is the channel public/unlisted?"));
-						}
+						if (err.message === "Searching with YouTube is disabled.") return reject(err);
 						return reject(new Error("An error has occured. Please try again later."));
 					}
 
@@ -714,9 +715,8 @@ class _YouTubeModule extends CoreClass {
 				})
 				.catch(err => {
 					YouTubeModule.log("ERROR", "GET_PLAYLIST_PAGE", `${err.message}`);
-					if (err.message === "Request failed with status code 404") {
+					if (err.message === "Request failed with status code 404")
 						return reject(new Error("Playlist not found. Is the playlist public/unlisted?"));
-					}
 					return reject(new Error("An error has occured. Please try again later."));
 				});
 		});
@@ -1014,6 +1014,14 @@ class _YouTubeModule extends CoreClass {
 		return new Promise((resolve, reject) => {
 			const { params } = payload;
 
+			if (
+				config.has("experimental.disable_youtube_search") &&
+				config.get("experimental.disable_youtube_search")
+			) {
+				reject(new Error("Searching with YouTube is disabled."));
+				return;
+			}
+
 			YouTubeModule.runJob(
 				"API_CALL",
 				{