Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sort options to playback requests #4786

Merged
merged 16 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
- [Fishbigger](https://github.com/fishbigger)
- [sleepycatcoding](https://github.com/sleepycatcoding)
- [TheMelmacian](https://github.com/TheMelmacian)
- [v0idMrK](https://github.com/v0idMrK)

# Emby Contributors

Expand Down
10 changes: 9 additions & 1 deletion src/components/itemContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import itemHelper from './itemHelper';
import { playbackManager } from './playback/playbackmanager';
import ServerConnections from './ServerConnections';
import toast from './toast/toast';
import * as userSettings from '../scripts/settings/userSettings';

export function getCommands(options) {
const item = options.item;
Expand Down Expand Up @@ -589,9 +590,16 @@ function play(item, resume, queue, queueNext) {
serverId: item.ServerId
});
} else {
const sortParentId = 'items-' + (item.IsFolder ? item.Id : item.ParentId) + '-Folder';
const sortValues = userSettings.getSortValuesLegacy(sortParentId);

playbackManager[method]({
items: [item],
startPositionTicks: startPosition
startPositionTicks: startPosition,
queryOptions: {
SortBy: sortValues.sortBy,
SortOrder: sortValues.sortOrder
}
});
}
}
Expand Down
21 changes: 12 additions & 9 deletions src/components/playback/playbackmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ function createStreamInfoFromUrlItem(item) {
}

function mergePlaybackQueries(obj1, obj2) {
const query = Object.assign(obj1, obj2);
const query = obj1;
for (const key in obj2) {
if (obj2[key] !== undefined) query[key] = obj2[key];
thornbill marked this conversation as resolved.
Show resolved Hide resolved
}

const filters = query.Filters ? query.Filters.split(',') : [];
if (filters.indexOf('IsNotFolder') === -1) {
Expand Down Expand Up @@ -1798,23 +1801,23 @@ class PlaybackManager {
SortBy: options.shuffle ? 'Random' : null
});
} else if (firstItem.Type === 'MusicArtist') {
promise = getItemsForPlayback(serverId, {
promise = getItemsForPlayback(serverId, mergePlaybackQueries({
ArtistIds: firstItem.Id,
Filters: 'IsNotFolder',
Recursive: true,
SortBy: options.shuffle ? 'Random' : 'SortName',
MediaTypes: 'Audio'
});
}, queryOptions));
} else if (firstItem.MediaType === 'Photo') {
promise = getItemsForPlayback(serverId, {
promise = getItemsForPlayback(serverId, mergePlaybackQueries({
ParentId: firstItem.ParentId,
Filters: 'IsNotFolder',
// Setting this to true may cause some incorrect sorting
Recursive: false,
SortBy: options.shuffle ? 'Random' : 'SortName',
MediaTypes: 'Photo,Video',
Limit: UNLIMITED_ITEMS
}).then(function (result) {
}, queryOptions)).then(function (result) {
const playbackItems = result.Items;

let index = playbackItems.map(function (i) {
Expand All @@ -1830,7 +1833,7 @@ class PlaybackManager {
return Promise.resolve(result);
});
} else if (firstItem.Type === 'PhotoAlbum') {
promise = getItemsForPlayback(serverId, {
promise = getItemsForPlayback(serverId, mergePlaybackQueries({
ParentId: firstItem.Id,
Filters: 'IsNotFolder',
// Setting this to true may cause some incorrect sorting
Expand All @@ -1839,15 +1842,15 @@ class PlaybackManager {
// Only include Photos because we do not handle mixed queues currently
MediaTypes: 'Photo',
Limit: UNLIMITED_ITEMS
});
}, queryOptions));
} else if (firstItem.Type === 'MusicGenre') {
promise = getItemsForPlayback(serverId, {
promise = getItemsForPlayback(serverId, mergePlaybackQueries({
GenreIds: firstItem.Id,
Filters: 'IsNotFolder',
Recursive: true,
SortBy: options.shuffle ? 'Random' : 'SortName',
MediaTypes: 'Audio'
});
}, queryOptions));
} else if (firstItem.IsFolder && firstItem.CollectionType === 'homevideos') {
promise = getItemsForPlayback(serverId, mergePlaybackQueries({
ParentId: firstItem.Id,
Expand Down
12 changes: 11 additions & 1 deletion src/components/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dom from '../scripts/dom';
import recordingHelper from './recordingcreator/recordinghelper';
import ServerConnections from './ServerConnections';
import toast from './toast/toast';
import * as userSettings from '../scripts/settings/userSettings';

function playAllFromHere(card, serverId, queue) {
const parent = card.parentNode;
Expand Down Expand Up @@ -177,6 +178,10 @@ function executeAction(card, target, action) {

const item = getItemInfoFromCard(card);

const itemsContainer = dom.parentWithClass(card, 'itemsContainer');

const sortParentId = 'items-' + (item.IsFolder ? item.Id : itemsContainer?.getAttribute('data-parentid')) + '-Folder';

const serverId = item.ServerId;
const type = item.Type;

Expand All @@ -200,12 +205,17 @@ function executeAction(card, target, action) {
});
} else if (action === 'play' || action === 'resume') {
const startPositionTicks = parseInt(card.getAttribute('data-positionticks') || '0', 10);
const sortValues = userSettings.getSortValuesLegacy(sortParentId, 'SortName');
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved

v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
if (playbackManager.canPlay(item)) {
playbackManager.play({
ids: [playableItemId],
startPositionTicks: startPositionTicks,
serverId: serverId
serverId: serverId,
queryOptions: {
SortBy: sortValues.sortBy,
SortOrder: sortValues.sortOrder
}
});
} else {
console.warn('Unable to play item', item);
Expand Down
10 changes: 6 additions & 4 deletions src/controllers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,13 @@ class ItemsView {
const currentItem = self.currentItem;

if (currentItem && !self.hasFilters) {
const values = self.getSortValues();
playbackManager.play({
items: [currentItem],
queryOptions: {
SortBy: values.sortBy,
SortOrder: values.sortOrder
},
autoplay: true
});
} else {
Expand Down Expand Up @@ -960,10 +965,7 @@ class ItemsView {

getSortValues() {
const basekey = this.getSettingsKey();
return {
sortBy: userSettings.getFilter(basekey + '-sortby') || this.getDefaultSortBy(),
dmitrylyzo marked this conversation as resolved.
Show resolved Hide resolved
sortOrder: userSettings.getFilter(basekey + '-sortorder') === 'Descending' ? 'Descending' : 'Ascending'
};
return userSettings.getSortValuesLegacy(basekey, this.getDefaultSortBy());
}

getDefaultSortBy() {
Expand Down
28 changes: 28 additions & 0 deletions src/scripts/settings/userSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,32 @@ export class UserSettings {
getFilter(key) {
return this.get(key, true);
}

/**
* Gets the current sort values (Legacy - Non-JSON)
* (old views such as list.js [Photos] will
* use this one)
* @param {string} key - Filter key.
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
* @param {string} defaultSortBy - Default SortBy value.
* @return {Object} sortOptions object
*/
getSortValuesLegacy(key, defaultSortBy) {
return {
sortBy: this.getFilter(key + '-sortby') || defaultSortBy,
sortOrder: this.getFilter(key + '-sortorder') === 'Descending' ? 'Descending' : 'Ascending'
};
}

/**
* Gets the current sort values (JSON)
* (new views such as MoviesView will use
* this one)
* @param {string} key - Filter key.
* @return {Object} sortOptions object
*/
getSortValues(key) {
return this.loadQuerySettings(key, {});
}
dmitrylyzo marked this conversation as resolved.
Show resolved Hide resolved
}

export const currentSettings = new UserSettings;
Expand Down Expand Up @@ -672,3 +698,5 @@ export const customCss = currentSettings.customCss.bind(currentSettings);
export const disableCustomCss = currentSettings.disableCustomCss.bind(currentSettings);
export const getSavedView = currentSettings.getSavedView.bind(currentSettings);
export const saveViewSetting = currentSettings.saveViewSetting.bind(currentSettings);
export const getSortValuesLegacy = currentSettings.getSortValuesLegacy.bind(currentSettings);
export const getSortValues = currentSettings.getSortValues.bind(currentSettings);
Loading