Przeglądaj źródła

refactor: Renamed ratings module to media module and included ENSURE_SONG_EXISTS_BY_YOUTUBE_ID as GET_MEDIA

Owen Diffey 2 lat temu
rodzic
commit
530b9902d9

+ 1 - 1
backend/index.js

@@ -259,7 +259,7 @@ if (!config.get("migration")) {
 	moduleManager.addModule("punishments");
 	moduleManager.addModule("songs");
 	moduleManager.addModule("stations");
-	moduleManager.addModule("ratings");
+	moduleManager.addModule("media");
 	moduleManager.addModule("tasks");
 	moduleManager.addModule("utils");
 	moduleManager.addModule("youtube");

+ 2 - 2
backend/logic/actions/index.js

@@ -10,7 +10,7 @@ import news from "./news";
 import punishments from "./punishments";
 import utils from "./utils";
 import youtube from "./youtube";
-import ratings from "./ratings";
+import media from "./media";
 
 export default {
 	apis,
@@ -25,5 +25,5 @@ export default {
 	punishments,
 	utils,
 	youtube,
-	ratings
+	media
 };

+ 26 - 26
backend/logic/actions/ratings.js → backend/logic/actions/media.js

@@ -11,7 +11,7 @@ const WSModule = moduleManager.modules.ws;
 const CacheModule = moduleManager.modules.cache;
 const SongsModule = moduleManager.modules.songs;
 const ActivitiesModule = moduleManager.modules.activities;
-const RatingsModule = moduleManager.modules.ratings;
+const MediaModule = moduleManager.modules.media;
 
 CacheModule.runJob("SUB", {
 	channel: "ratings.like",
@@ -128,11 +128,11 @@ export default {
 	 * @param {object} session - the session object automatically added by the websocket
 	 * @param cb
 	 */
-	recalculateAll: isAdminRequired(async function recalculateAll(session, cb) {
+	recalculateAllRatings: isAdminRequired(async function recalculateAllRatings(session, cb) {
 		async.waterfall(
 			[
 				next => {
-					RatingsModule.runJob("RECALCULATE_ALL_RATINGS", {}, this)
+					MediaModule.runJob("RECALCULATE_ALL_RATINGS", {}, this)
 						.then(() => {
 							next();
 						})
@@ -144,10 +144,10 @@ export default {
 			async err => {
 				if (err) {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
-					this.log("ERROR", "RATINGS_RECALCULATE_ALL", `Failed to recalculate all ratings. "${err}"`);
+					this.log("ERROR", "MEDIA_RECALCULATE_ALL_RATINGS", `Failed to recalculate all ratings. "${err}"`);
 					return cb({ status: "error", message: err });
 				}
-				this.log("SUCCESS", "RATINGS_RECALCULATE_ALL", `Recalculated all ratings successfully.`);
+				this.log("SUCCESS", "MEDIA_RECALCULATE_ALL_RATINGS", `Recalculated all ratings successfully.`);
 				return cb({ status: "success", message: "Successfully recalculated all ratings." });
 			}
 		);
@@ -166,8 +166,8 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					SongsModule.runJob(
-						"ENSURE_SONG_EXISTS_BY_YOUTUBE_ID",
+					MediaModule.runJob(
+						"GET_MEDIA",
 						{
 							youtubeId
 						},
@@ -233,7 +233,7 @@ export default {
 						}),
 
 				(song, next) => {
-					RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId })
+					MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId })
 						.then(ratings => next(null, song, ratings))
 						.catch(err => next(err));
 				}
@@ -243,7 +243,7 @@ export default {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 					this.log(
 						"ERROR",
-						"RATINGS_LIKE",
+						"MEDIA_RATINGS_LIKE",
 						`User "${session.userId}" failed to like song ${youtubeId}. "${err}"`
 					);
 					return cb({ status: "error", message: err });
@@ -294,8 +294,8 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					SongsModule.runJob(
-						"ENSURE_SONG_EXISTS_BY_YOUTUBE_ID",
+					MediaModule.runJob(
+						"GET_MEDIA",
 						{
 							youtubeId
 						},
@@ -361,7 +361,7 @@ export default {
 						}),
 
 				(song, next) => {
-					RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId })
+					MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId })
 						.then(ratings => next(null, song, ratings))
 						.catch(err => next(err));
 				}
@@ -371,7 +371,7 @@ export default {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 					this.log(
 						"ERROR",
-						"RATINGS_DISLIKE",
+						"MEDIA_RATINGS_DISLIKE",
 						`User "${session.userId}" failed to dislike song ${youtubeId}. "${err}"`
 					);
 					return cb({ status: "error", message: err });
@@ -422,8 +422,8 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					SongsModule.runJob(
-						"ENSURE_SONG_EXISTS_BY_YOUTUBE_ID",
+					MediaModule.runJob(
+						"GET_MEDIA",
 						{
 							youtubeId
 						},
@@ -490,7 +490,7 @@ export default {
 				},
 
 				(song, next) => {
-					RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId })
+					MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId })
 						.then(ratings => next(null, song, ratings))
 						.catch(err => next(err));
 				}
@@ -500,7 +500,7 @@ export default {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 					this.log(
 						"ERROR",
-						"RATINGS_UNDISLIKE",
+						"MEDIA_RATINGS_UNDISLIKE",
 						`User "${session.userId}" failed to undislike song ${youtubeId}. "${err}"`
 					);
 					return cb({ status: "error", message: err });
@@ -553,8 +553,8 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					SongsModule.runJob(
-						"ENSURE_SONG_EXISTS_BY_YOUTUBE_ID",
+					MediaModule.runJob(
+						"GET_MEDIA",
 						{
 							youtubeId
 						},
@@ -621,7 +621,7 @@ export default {
 				},
 
 				(song, next) => {
-					RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId })
+					MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId })
 						.then(ratings => next(null, song, ratings))
 						.catch(err => next(err));
 				}
@@ -631,7 +631,7 @@ export default {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 					this.log(
 						"ERROR",
-						"RATINGS_UNLIKE",
+						"MEDIA_RATINGS_UNLIKE",
 						`User "${session.userId}" failed to unlike song ${youtubeId}. "${err}"`
 					);
 					return cb({ status: "error", message: err });
@@ -683,7 +683,7 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					RatingsModule.runJob("GET_RATINGS", { youtubeId, createMissing: true }, this)
+					MediaModule.runJob("GET_RATINGS", { youtubeId, createMissing: true }, this)
 						.then(res => next(null, res.ratings))
 						.catch(next);
 				},
@@ -700,7 +700,7 @@ export default {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 					this.log(
 						"ERROR",
-						"RATINGS_GET_RATINGS",
+						"MEDIA_GET_RATINGS",
 						`User "${session.userId}" failed to get ratings for ${youtubeId}. "${err}"`
 					);
 					return cb({ status: "error", message: err });
@@ -732,8 +732,8 @@ export default {
 		async.waterfall(
 			[
 				next => {
-					SongsModule.runJob(
-						"ENSURE_SONG_EXISTS_BY_YOUTUBE_ID",
+					MediaModule.runJob(
+						"GET_MEDIA",
 						{
 							youtubeId
 						},
@@ -784,7 +784,7 @@ export default {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 					this.log(
 						"ERROR",
-						"RATINGS_GET_OWN_RATINGS",
+						"MEDIA_GET_OWN_RATINGS",
 						`User "${session.userId}" failed to get ratings for ${youtubeId}. "${err}"`
 					);
 					return cb({ status: "error", message: err });

+ 3 - 2
backend/logic/actions/playlists.js

@@ -14,6 +14,7 @@ const CacheModule = moduleManager.modules.cache;
 const PlaylistsModule = moduleManager.modules.playlists;
 const YouTubeModule = moduleManager.modules.youtube;
 const ActivitiesModule = moduleManager.modules.activities;
+const MediaModule = moduleManager.modules.media;
 
 CacheModule.runJob("SUB", {
 	channel: "playlist.create",
@@ -1435,7 +1436,7 @@ export default {
 				},
 
 				(playlist, next) => {
-					SongsModule.runJob("ENSURE_SONG_EXISTS_BY_YOUTUBE_ID", { youtubeId }, this)
+					MediaModule.runJob("GET_MEDIA", { youtubeId }, this)
 						.then(res =>
 							next(null, playlist, {
 								_id: res.song._id,
@@ -1481,7 +1482,7 @@ export default {
 
 						if (playlist.type === "user-liked") {
 							CacheModule.runJob("PUB", {
-								channel: "song.unlike",
+								channel: "ratings.unlike",
 								value: JSON.stringify({
 									youtubeId: newSong.youtubeId,
 									userId: session.userId,

+ 3 - 3
backend/logic/actions/users.js

@@ -19,7 +19,7 @@ const MailModule = moduleManager.modules.mail;
 const PunishmentsModule = moduleManager.modules.punishments;
 const ActivitiesModule = moduleManager.modules.activities;
 const PlaylistsModule = moduleManager.modules.playlists;
-const RatingsModule = moduleManager.modules.ratings;
+const MediaModule = moduleManager.modules.media;
 
 CacheModule.runJob("SUB", {
 	channel: "user.updatePreferences",
@@ -374,7 +374,7 @@ export default {
 						(song, next) => {
 							const { youtubeId } = song;
 
-							RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId })
+							MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId })
 								.then(() => next())
 								.catch(next);
 						},
@@ -600,7 +600,7 @@ export default {
 						(song, next) => {
 							const { youtubeId } = song;
 
-							RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId })
+							MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId })
 								.then(() => next())
 								.catch(next);
 						},

+ 73 - 15
backend/logic/ratings.js → backend/logic/media.js

@@ -1,23 +1,23 @@
 import async from "async";
 import CoreClass from "../core";
 
-let RatingsModule;
+let MediaModule;
 let CacheModule;
 let DBModule;
 let UtilsModule;
 let YouTubeModule;
 let SongsModule;
 
-class _RatingsModule extends CoreClass {
+class _MediaModule extends CoreClass {
 	// eslint-disable-next-line require-jsdoc
 	constructor() {
-		super("ratings");
+		super("media");
 
-		RatingsModule = this;
+		MediaModule = this;
 	}
 
 	/**
-	 * Initialises the ratings module
+	 * Initialises the media module
 	 *
 	 * @returns {Promise} - returns promise (reject, resolve)
 	 */
@@ -57,7 +57,7 @@ class _RatingsModule extends CoreClass {
 						return async.each(
 							youtubeIds,
 							(youtubeId, next) => {
-								RatingsModule.RatingsModel.findOne({ youtubeId }, (err, rating) => {
+								MediaModule.RatingsModel.findOne({ youtubeId }, (err, rating) => {
 									if (err) next(err);
 									else if (!rating)
 										CacheModule.runJob("HDEL", {
@@ -75,7 +75,7 @@ class _RatingsModule extends CoreClass {
 
 					next => {
 						this.setStage(4);
-						RatingsModule.RatingsModel.find({}, next);
+						MediaModule.RatingsModel.find({}, next);
 					},
 
 					(ratings, next) => {
@@ -86,7 +86,7 @@ class _RatingsModule extends CoreClass {
 								CacheModule.runJob("HSET", {
 									table: "ratings",
 									key: rating.youtubeId,
-									value: RatingsModule.RatingsSchemaCache(rating)
+									value: MediaModule.RatingsSchemaCache(rating)
 								})
 									.then(() => next())
 									.catch(next);
@@ -139,7 +139,7 @@ class _RatingsModule extends CoreClass {
 					},
 
 					({ likes, dislikes }, next) => {
-						RatingsModule.RatingsModel.findOneAndUpdate(
+						MediaModule.RatingsModel.findOneAndUpdate(
 							{ youtubeId: payload.youtubeId },
 							{
 								$set: {
@@ -203,7 +203,7 @@ class _RatingsModule extends CoreClass {
 							youtubeIds,
 							2,
 							(youtubeId, next) => {
-								RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId }, this)
+								MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId }, this)
 									.then(() => {
 										next();
 									})
@@ -244,7 +244,7 @@ class _RatingsModule extends CoreClass {
 
 					(ratings, next) => {
 						if (ratings) return next(true, ratings);
-						return RatingsModule.RatingsModel.findOne({ youtubeId: payload.youtubeId }, next);
+						return MediaModule.RatingsModel.findOne({ youtubeId: payload.youtubeId }, next);
 					},
 
 					(ratings, next) => {
@@ -261,13 +261,13 @@ class _RatingsModule extends CoreClass {
 
 						if (!payload.createMissing) return next("Ratings not found.");
 
-						return RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId: payload.youtubeId }, this)
+						return MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId: payload.youtubeId }, this)
 							.then(() => next())
 							.catch(next);
 					},
 
 					next =>
-						RatingsModule.runJob("GET_RATINGS", { youtubeId: payload.youtubeId }, this)
+						MediaModule.runJob("GET_RATINGS", { youtubeId: payload.youtubeId }, this)
 							.then(res => next(null, res.ratings))
 							.catch(next)
 				],
@@ -298,7 +298,7 @@ class _RatingsModule extends CoreClass {
 					async.waterfall(
 						[
 							next => {
-								RatingsModule.RatingsModel.deleteOne({ youtubeId }, err => {
+								MediaModule.RatingsModel.deleteOne({ youtubeId }, err => {
 									if (err) next(err);
 									else next();
 								});
@@ -322,6 +322,64 @@ class _RatingsModule extends CoreClass {
 			);
 		});
 	}
+
+	/**
+	 * Get song or youtube video by youtubeId
+	 *
+	 * @param {object} payload - an object containing the payload
+	 * @param {string} payload.youtubeId - the youtube id of the song/video
+	 * @param {string} payload.userId - the user id
+	 * @returns {Promise} - returns a promise (resolve, reject)
+	 */
+	GET_MEDIA(payload) {
+		return new Promise((resolve, reject) => {
+			async.waterfall(
+				[
+					next => {
+						SongsModule.SongModel.findOne({ youtubeId: payload.youtubeId }, next);
+					},
+
+					(song, next) => {
+						if (song && song.duration > 0) next(true, song);
+						else {
+							YouTubeModule.runJob(
+								"GET_VIDEO",
+								{ identifier: payload.youtubeId, createMissing: true },
+								this
+							)
+								.then(response => {
+									const { youtubeId, title, author, duration } = response.video;
+									next(null, song, { youtubeId, title, artists: [author], duration });
+								})
+								.catch(next);
+						}
+					},
+
+					(song, youtubeVideo, next) => {
+						if (song && song.duration <= 0) {
+							song.duration = youtubeVideo.duration;
+							song.save({ validateBeforeSave: true }, err => {
+								if (err) next(err, song);
+								next(null, song);
+							});
+						} else {
+							next(null, {
+								...youtubeVideo,
+								skipDuration: 0,
+								requestedBy: payload.userId,
+								requestedAt: Date.now(),
+								verified: false
+							});
+						}
+					}
+				],
+				(err, song) => {
+					if (err && err !== true) return reject(new Error(err));
+					return resolve({ song });
+				}
+			);
+		});
+	}
 }
 
-export default new _RatingsModule();
+export default new _MediaModule();

+ 5 - 5
backend/logic/playlists.js

@@ -8,7 +8,7 @@ let SongsModule;
 let CacheModule;
 let DBModule;
 let UtilsModule;
-let RatingsModule;
+let MediaModule;
 let WSModule;
 
 class _PlaylistsModule extends CoreClass {
@@ -32,7 +32,7 @@ class _PlaylistsModule extends CoreClass {
 		DBModule = this.moduleManager.modules.db;
 		UtilsModule = this.moduleManager.modules.utils;
 		SongsModule = this.moduleManager.modules.songs;
-		RatingsModule = this.moduleManager.modules.ratings;
+		MediaModule = this.moduleManager.modules.media;
 		WSModule = this.moduleManager.modules.ws;
 
 		this.playlistModel = await DBModule.runJob("GET_MODEL", { modelName: "playlist" });
@@ -407,7 +407,7 @@ class _PlaylistsModule extends CoreClass {
 					},
 
 					next => {
-						SongsModule.runJob("ENSURE_SONG_EXISTS_BY_YOUTUBE_ID", { youtubeId }, this)
+						MediaModule.runJob("GET_MEDIA", { youtubeId }, this)
 							.then(response => {
 								const { song } = response;
 								const { _id, title, artists, thumbnail, duration, verified } = song;
@@ -460,7 +460,7 @@ class _PlaylistsModule extends CoreClass {
 
 					(playlist, newSong, next) => {
 						if (playlist.type === "user-liked" || playlist.type === "user-disliked") {
-							RatingsModule.runJob("RECALCULATE_RATINGS", {
+							MediaModule.runJob("RECALCULATE_RATINGS", {
 								youtubeId: newSong.youtubeId
 							})
 								.then(ratings => next(null, playlist, newSong, ratings))
@@ -539,7 +539,7 @@ class _PlaylistsModule extends CoreClass {
 
 					(playlist, next) => {
 						if (playlist.type === "user-liked" || playlist.type === "user-disliked") {
-							RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId })
+							MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId })
 								.then(ratings => next(null, playlist, ratings))
 								.catch(next);
 						} else next(null, playlist, null);

+ 5 - 74
backend/logic/songs.js

@@ -9,7 +9,7 @@ let UtilsModule;
 let YouTubeModule;
 let StationsModule;
 let PlaylistsModule;
-let RatingsModule;
+let MediaModule;
 let WSModule;
 
 class _SongsModule extends CoreClass {
@@ -34,7 +34,7 @@ class _SongsModule extends CoreClass {
 		YouTubeModule = this.moduleManager.modules.youtube;
 		StationsModule = this.moduleManager.modules.stations;
 		PlaylistsModule = this.moduleManager.modules.playlists;
-		RatingsModule = this.moduleManager.modules.ratings;
+		MediaModule = this.moduleManager.modules.media;
 		WSModule = this.moduleManager.modules.ws;
 
 		this.SongModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
@@ -220,65 +220,6 @@ class _SongsModule extends CoreClass {
 		});
 	}
 
-	/**
-	 * Makes sure that if a song is not currently in the songs db, to add it
-	 *
-	 * @param {object} payload - an object containing the payload
-	 * @param {string} payload.youtubeId - the youtube song id of the song we are trying to ensure is in the songs db
-	 * @param {string} payload.userId - the youtube song id of the song we are trying to ensure is in the songs db
-	 * @param {string} payload.automaticallyRequested - whether the song was automatically requested or not
-	 * @returns {Promise} - returns a promise (resolve, reject)
-	 */
-	ENSURE_SONG_EXISTS_BY_YOUTUBE_ID(payload) {
-		return new Promise((resolve, reject) => {
-			async.waterfall(
-				[
-					next => {
-						SongsModule.SongModel.findOne({ youtubeId: payload.youtubeId }, next);
-					},
-
-					(song, next) => {
-						if (song && song.duration > 0) next(true, song);
-						else {
-							YouTubeModule.runJob(
-								"GET_VIDEO",
-								{ identifier: payload.youtubeId, createMissing: true },
-								this
-							)
-								.then(response => {
-									const { youtubeId, title, author, duration } = response.video;
-									next(null, song, { youtubeId, title, artists: [author], duration });
-								})
-								.catch(next);
-						}
-					},
-
-					(song, youtubeVideo, next) => {
-						if (song && song.duration <= 0) {
-							song.duration = youtubeVideo.duration;
-							song.save({ validateBeforeSave: true }, err => {
-								if (err) next(err, song);
-								next(null, song);
-							});
-						} else {
-							next(null, {
-								...youtubeVideo,
-								skipDuration: 0,
-								requestedBy: payload.userId,
-								requestedAt: Date.now(),
-								verified: false
-							});
-						}
-					}
-				],
-				(err, song) => {
-					if (err && err !== true) return reject(new Error(err));
-					return resolve({ song });
-				}
-			);
-		});
-	}
-
 	/**
 	 * Create song
 	 *
@@ -325,7 +266,7 @@ class _SongsModule extends CoreClass {
 					},
 
 					(song, next) => {
-						RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId: song.youtubeId }, this)
+						MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId: song.youtubeId }, this)
 							.then(() => next(null, song))
 							.catch(next);
 					},
@@ -1184,21 +1125,11 @@ class _SongsModule extends CoreClass {
 										},
 
 										next => {
-											SongsModule.runJob(
-												"ENSURE_SONG_EXISTS_BY_SONG_ID",
-												{ youtubeId, automaticallyRequested: true },
-												this
-											)
-												.then(() => next())
+											MediaModule.runJob("GET_MEDIA", { youtubeId }, this)
+												.then(res => next(null, res.song))
 												.catch(next);
 										},
 
-										next => {
-											console.log(444, youtubeId);
-
-											SongsModule.SongModel.findOne({ youtubeId }, next);
-										},
-
 										(song, next) => {
 											const { _id, title, artists, thumbnail, duration, verified } = song;
 											const trimmedSong = {

+ 7 - 9
backend/logic/stations.js

@@ -7,9 +7,9 @@ let CacheModule;
 let DBModule;
 let UtilsModule;
 let WSModule;
-let SongsModule;
 let PlaylistsModule;
 let NotificationsModule;
+let MediaModule;
 
 class _StationsModule extends CoreClass {
 	// eslint-disable-next-line require-jsdoc
@@ -29,9 +29,9 @@ class _StationsModule extends CoreClass {
 		DBModule = this.moduleManager.modules.db;
 		UtilsModule = this.moduleManager.modules.utils;
 		WSModule = this.moduleManager.modules.ws;
-		SongsModule = this.moduleManager.modules.songs;
 		PlaylistsModule = this.moduleManager.modules.playlists;
 		NotificationsModule = this.moduleManager.modules.notifications;
+		MediaModule = this.moduleManager.modules.media;
 
 		this.userList = {};
 		this.usersPerStation = {};
@@ -539,7 +539,7 @@ class _StationsModule extends CoreClass {
 							songsToAdd.map(song => song.youtubeId),
 							2,
 							(youtubeId, next) => {
-								SongsModule.runJob("ENSURE_SONG_EXISTS_BY_YOUTUBE_ID", { youtubeId }, this)
+								MediaModule.runJob("GET_MEDIA", { youtubeId }, this)
 									.then(response => {
 										const { song } = response;
 										const { _id, title, artists, thumbnail, duration, skipDuration, verified } =
@@ -639,12 +639,10 @@ class _StationsModule extends CoreClass {
 					},
 
 					(queueSong, next) => {
-						SongsModule.runJob(
-							"ENSURE_SONG_EXISTS_BY_YOUTUBE_ID",
+						MediaModule.runJob(
+							"GET_MEDIA",
 							{
-								youtubeId: queueSong.youtubeId,
-								userId: null,
-								automaticallyRequested: true
+								youtubeId: queueSong.youtubeId
 							},
 							this
 						)
@@ -1767,7 +1765,7 @@ class _StationsModule extends CoreClass {
 					},
 
 					(station, next) => {
-						SongsModule.runJob("ENSURE_SONG_EXISTS_BY_YOUTUBE_ID", { youtubeId }, this)
+						MediaModule.runJob("GET_MEDIA", { youtubeId }, this)
 							.then(response => {
 								const { song } = response;
 								const { _id, title, skipDuration, artists, thumbnail, duration, verified } = song;

+ 4 - 4
backend/logic/youtube.js

@@ -41,7 +41,7 @@ class RateLimitter {
 let YouTubeModule;
 let CacheModule;
 let DBModule;
-let RatingsModule;
+let MediaModule;
 let SongsModule;
 let StationsModule;
 let PlaylistsModule;
@@ -103,7 +103,7 @@ class _YouTubeModule extends CoreClass {
 	async initialize() {
 		CacheModule = this.moduleManager.modules.cache;
 		DBModule = this.moduleManager.modules.db;
-		RatingsModule = this.moduleManager.modules.ratings;
+		MediaModule = this.moduleManager.modules.media;
 		SongsModule = this.moduleManager.modules.songs;
 		StationsModule = this.moduleManager.modules.stations;
 		PlaylistsModule = this.moduleManager.modules.playlists;
@@ -1332,7 +1332,7 @@ class _YouTubeModule extends CoreClass {
 							youtubeIds,
 							2,
 							(youtubeId, next) => {
-								RatingsModule.runJob("RECALCULATE_RATINGS", { youtubeId }, this)
+								MediaModule.runJob("RECALCULATE_RATINGS", { youtubeId }, this)
 									.then(() => next())
 									.catch(next);
 							},
@@ -1487,7 +1487,7 @@ class _YouTubeModule extends CoreClass {
 					},
 
 					(youtubeIds, next) => {
-						RatingsModule.runJob("REMOVE_RATINGS", { youtubeIds }, this)
+						MediaModule.runJob("REMOVE_RATINGS", { youtubeIds }, this)
 							.then(() => next(null, youtubeIds))
 							.catch(next);
 					},

+ 1 - 1
frontend/src/pages/Admin/Songs/index.vue

@@ -522,7 +522,7 @@ export default {
 				},
 				{
 					name: "Recalculate all ratings",
-					socket: "ratings.recalculateAll"
+					socket: "media.recalculateAllRatings"
 				}
 			]
 		};

+ 1 - 1
frontend/src/pages/Admin/YouTube/Videos.vue

@@ -291,7 +291,7 @@ export default {
 			jobs: [
 				{
 					name: "Recalculate all ratings",
-					socket: "ratings.recalculateAll"
+					socket: "media.recalculateAllRatings"
 				}
 			]
 		};

+ 6 - 6
frontend/src/pages/Station/index.vue

@@ -1369,7 +1369,7 @@ export default {
 				);
 
 				this.socket.dispatch(
-					"ratings.getRatings",
+					"media.getRatings",
 					currentSong.youtubeId,
 					res => {
 						if (
@@ -1383,7 +1383,7 @@ export default {
 
 				if (this.loggedIn) {
 					this.socket.dispatch(
-						"ratings.getOwnRatings",
+						"media.getOwnRatings",
 						currentSong.youtubeId,
 						res => {
 							console.log("getOwnSongRatings", res);
@@ -1801,7 +1801,7 @@ export default {
 		toggleLike() {
 			if (this.currentSong.liked)
 				this.socket.dispatch(
-					"ratings.unlike",
+					"media.unlike",
 					this.currentSong.youtubeId,
 					res => {
 						if (res.status !== "success")
@@ -1810,7 +1810,7 @@ export default {
 				);
 			else
 				this.socket.dispatch(
-					"ratings.like",
+					"media.like",
 					this.currentSong.youtubeId,
 					res => {
 						if (res.status !== "success")
@@ -1821,7 +1821,7 @@ export default {
 		toggleDislike() {
 			if (this.currentSong.disliked)
 				return this.socket.dispatch(
-					"ratings.undislike",
+					"media.undislike",
 					this.currentSong.youtubeId,
 					res => {
 						if (res.status !== "success")
@@ -1830,7 +1830,7 @@ export default {
 				);
 
 			return this.socket.dispatch(
-				"ratings.dislike",
+				"media.dislike",
 				this.currentSong.youtubeId,
 				res => {
 					if (res.status !== "success")