diff --git a/web-src/src/components/ModalDialogDirectory.vue b/web-src/src/components/ModalDialogDirectory.vue index 0a6f105b..d4f575e4 100644 --- a/web-src/src/components/ModalDialogDirectory.vue +++ b/web-src/src/components/ModalDialogDirectory.vue @@ -39,23 +39,17 @@ export default { methods: { play: function () { this.$emit('close') - webapi.search({ 'type': 'tracks', 'expression': 'path starts with "' + this.directory.path + '" order by path asc' }).then(({ data }) => { - webapi.player_play_uri(data.tracks.items.map(a => a.uri).join(','), false) - }) + webapi.player_play_expression('path starts with "' + this.directory.path + '" order by path asc', false) }, queue_add: function () { this.$emit('close') - webapi.search({ 'type': 'tracks', 'expression': 'path starts with "' + this.directory.path + '" order by path asc' }).then(({ data }) => { - webapi.queue_add(data.tracks.items.map(a => a.uri).join(',')) - }) + webapi.queue_expression_add('path starts with "' + this.directory.path + '" order by path asc') }, queue_add_next: function () { this.$emit('close') - webapi.search({ 'type': 'tracks', 'expression': 'path starts with "' + this.directory.path + '" order by path asc' }).then(({ data }) => { - webapi.queue_add_next(data.tracks.items.map(a => a.uri).join(',')) - }) + webapi.queue_expression_add_next('path starts with "' + this.directory.path + '" order by path asc') } } } diff --git a/web-src/src/components/ModalDialogGenre.vue b/web-src/src/components/ModalDialogGenre.vue index 5a003ffe..45634615 100644 --- a/web-src/src/components/ModalDialogGenre.vue +++ b/web-src/src/components/ModalDialogGenre.vue @@ -39,23 +39,17 @@ export default { methods: { play: function () { this.$emit('close') - webapi.library_genre_tracks(this.genre.name).then(({ data }) => - webapi.player_play_uri(data.tracks.items.map(a => a.uri).join(','), false) - ) + webapi.player_play_expression('genre is "' + this.genre.name + '" and media_kind is music', false) }, queue_add: function () { this.$emit('close') - webapi.library_genre_tracks(this.genre.name).then(({ data }) => - webapi.queue_add(data.tracks.items.map(a => a.uri).join(',')) - ) + webapi.queue_expression_add('genre is "' + this.genre.name + '" and media_kind is music') }, queue_add_next: function () { this.$emit('close') - webapi.library_genre_tracks(this.genre.name).then(({ data }) => - webapi.queue_add_next(data.tracks.items.map(a => a.uri).join(',')) - ) + webapi.queue_expression_add_next('genre is "' + this.genre.name + '" and media_kind is music') }, open_genre: function () { diff --git a/web-src/src/pages/PageFiles.vue b/web-src/src/pages/PageFiles.vue index 2cc737e8..ae0c1fd9 100644 --- a/web-src/src/pages/PageFiles.vue +++ b/web-src/src/pages/PageFiles.vue @@ -153,9 +153,7 @@ export default { }, play: function () { - webapi.search({ 'type': 'tracks', 'expression': 'path starts with "' + this.current_directory + '" order by path asc' }).then(({ data }) => { - webapi.player_play_uri(data.tracks.items.map(a => a.uri).join(','), false) - }) + webapi.player_play_expression('path starts with "' + this.current_directory + '" order by path asc', false) }, play_track: function (position) { diff --git a/web-src/src/pages/PageGenre.vue b/web-src/src/pages/PageGenre.vue index d3749e9b..e802ed47 100644 --- a/web-src/src/pages/PageGenre.vue +++ b/web-src/src/pages/PageGenre.vue @@ -85,9 +85,7 @@ export default { }, play: function () { - webapi.library_genre_tracks(this.name).then(({ data }) => - webapi.player_play_uri(data.tracks.items.map(a => a.uri).join(','), true) - ) + webapi.player_play_expression('genre is "' + this.name + '" and media_kind is music', true) }, open_album: function (album) { diff --git a/web-src/src/pages/PageGenreTracks.vue b/web-src/src/pages/PageGenreTracks.vue index 5eddd220..d756b6b2 100644 --- a/web-src/src/pages/PageGenreTracks.vue +++ b/web-src/src/pages/PageGenreTracks.vue @@ -84,11 +84,11 @@ export default { }, play: function () { - webapi.player_play_uri(this.tracks.items.map(a => a.uri).join(','), true) + webapi.player_play_expression('genre is "' + this.genre + '" and media_kind is music', true) }, play_track: function (position) { - webapi.player_play_uri(this.tracks.items.map(a => a.uri).join(','), false, position) + webapi.player_play_expression('genre is "' + this.genre + '" and media_kind is music', false, position) }, open_dialog: function (track) { diff --git a/web-src/src/webapi/index.js b/web-src/src/webapi/index.js index 53b42eb7..82f49c9f 100644 --- a/web-src/src/webapi/index.js +++ b/web-src/src/webapi/index.js @@ -41,11 +41,9 @@ export default { return axios.put('/api/queue/items/' + itemId + '?new_position=' + newPosition) }, - queue_add (uri, showNotification = true) { + queue_add (uri) { return axios.post('/api/queue/items/add?uris=' + uri).then((response) => { - if (showNotification) { - store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 }) - } + store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 }) return Promise.resolve(response) }) }, @@ -61,18 +59,54 @@ export default { }) }, + queue_expression_add (expression) { + var options = {} + options.expression = expression + + return axios.post('/api/queue/items/add', undefined, { params: options }).then((response) => { + store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 }) + return Promise.resolve(response) + }) + }, + + queue_expression_add_next (expression) { + var options = {} + options.expression = expression + options.position = 0 + if (store.getters.now_playing && store.getters.now_playing.id) { + options.position = store.getters.now_playing.position + 1 + } + + return axios.post('/api/queue/items/add', undefined, { params: options }).then((response) => { + store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 }) + return Promise.resolve(response) + }) + }, + player_status () { return axios.get('/api/player') }, player_play_uri (uris, shuffle, position = undefined) { - return this.queue_clear().then(() => - this.player_shuffle(shuffle).then(() => - this.queue_add(uris, false).then(() => - this.player_play({ 'position': position }) - ) - ) - ) + var options = {} + options.uris = uris + options.shuffle = shuffle ? 'true' : 'false' + options.clear = 'true' + options.playback = 'start' + options.playback_from_position = position + + return axios.post('/api/queue/items/add', undefined, { params: options }) + }, + + player_play_expression (expression, shuffle, position = undefined) { + var options = {} + options.expression = expression + options.shuffle = shuffle ? 'true' : 'false' + options.clear = 'true' + options.playback = 'start' + options.playback_from_position = position + + return axios.post('/api/queue/items/add', undefined, { params: options }) }, player_play (options = {}) {