ソースを参照

Added ability to import playlists to the queue

Kristian Vos 5 年 前
コミット
42ca70eeae

+ 43 - 2
backend/logic/actions/queueSongs.js

@@ -26,7 +26,7 @@ cache.sub('queue.update', songId => {
 	});
 });
 
-module.exports = {
+let lib = {
 
 	/**
 	 * Gets all queuesongs
@@ -203,5 +203,46 @@ module.exports = {
 			logger.success("QUEUE_ADD", `User "${userId}" successfully added queuesong "${songId}".`);
 			return cb({ status: 'success', message: 'Successfully added that song to the queue' });
 		});
+	}),
+
+	/**
+	 * Adds a set of songs to the queue
+	 *
+	 * @param {Object} session - the session object automatically added by socket.io
+	 * @param {String} url - the url of the the YouTube playlist
+	 * @param {Function} cb - gets called with the result
+	 * @param {String} userId - the userId automatically added by hooks
+	 */
+	addSetToQueue: hooks.loginRequired((session, url, cb, userId) => {
+		async.waterfall([
+			(next) => {
+				utils.getPlaylistFromYouTube(url, songs => {
+					next(null, songs);
+				});
+			},
+			(songs, next) => {
+				let processed = 0;
+				function checkDone() {
+					if (processed === songs.length) next();
+				}
+				for (let s = 0; s < songs.length; s++) {
+					lib.add(session, songs[s].contentDetails.videoId, () => {
+						processed++;
+						checkDone();
+					});
+				}
+			}
+		], (err) => {
+			if (err) {
+				err = utils.getError(err);
+				logger.error("QUEUE_IMPORT", `Importing a YouTube playlist to the queue failed for user "${userId}". "${err}"`);
+				return cb({ status: 'failure', message: err});
+			} else {
+				logger.success("QUEUE_IMPORT", `Successfully imported a YouTube playlist to the queue for user "${userId}".`);
+				cb({ status: 'success', message: 'Playlist has been successfully imported.' });
+			}
+		});
 	})
-};
+};
+
+module.exports = lib;

+ 30 - 1
frontend/components/Modals/AddSongToQueue.vue

@@ -40,6 +40,20 @@
           <a class="button is-info" v-on:click="submitQuery()" href="#">Search</a>
         </p>
       </div>
+      <div class="control is-grouped">
+        <p class="control is-expanded">
+          <input
+            class="input"
+            type="text"
+            placeholder="YouTube Playlist URL"
+            v-model="importQuery"
+            @keyup.enter="importPlaylist()"
+          />
+        </p>
+        <p class="control">
+          <a class="button is-info" v-on:click="importPlaylist()" href="#">Import</a>
+        </p>
+      </div>
       <table class="table">
         <tbody>
           <tr v-for="(result, index) in queryResults" :key="index">
@@ -69,7 +83,8 @@ export default {
       querySearch: "",
       queryResults: [],
       playlists: [],
-      privatePlaylistQueueSelected: null
+      privatePlaylistQueueSelected: null,
+      importQuery: "",
     };
   },
   methods: {
@@ -112,6 +127,20 @@ export default {
         });
       }
     },
+    importPlaylist: function() {
+      let _this = this;
+      Toast.methods.addToast(
+        "Starting to import your playlist. This can take some time to do.",
+        4000
+      );
+      this.socket.emit(
+        "queueSongs.addSetToQueue",
+        _this.importQuery,
+        res => {
+          Toast.methods.addToast(res.message, 4000);
+        }
+      );
+    },
     submitQuery: function() {
       console.log("submit query");
       let _this = this;

+ 0 - 1
frontend/components/Modals/EditSong.vue

@@ -455,7 +455,6 @@ export default {
               _this.video.player.getCurrentTime() <
               _this.editing.song.skipDuration
             ) {
-              console.log("Seekto2: " + _this.editing.song.skipDuration);
               _this.video.player.seekTo(_this.editing.song.skipDuration);
             }
           } else if (event.data === 2) {