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 6 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
30 changes: 29 additions & 1 deletion src/components/itemContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ 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';
import libraryMenu from '../scripts/libraryMenu';
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
dmitrylyzo marked this conversation as resolved.
Show resolved Hide resolved

export function getCommands(options) {
const item = options.item;
Expand Down Expand Up @@ -567,6 +569,29 @@ function deleteSeriesTimer(apiClient, item, resolve, command) {
});
}

function getSettingsKey(item) {
if (item.IsFolder) {
return 'Folder';
}
const itemType = item.MediaType;
switch (itemType) {
case 'Movie':
case 'BoxSet':
case 'Video':
return 'movies';
case 'Audio':
return 'songs';
case 'MusicAlbum':
return 'musicalbums';
case 'MusicArtist':
return 'musicartists';
case 'MusicGenre':
return 'genres';
case 'MusicPlaylist':
return 'musicplaylists';
}
}

dmitrylyzo marked this conversation as resolved.
Show resolved Hide resolved
function play(item, resume, queue, queueNext) {
let method = 'play';
if (queue) {
Expand All @@ -589,9 +614,12 @@ function play(item, resume, queue, queueNext) {
serverId: item.ServerId
});
} else {
const sortParentId = item.IsFolder ? ('items-' + item.Id) : libraryMenu.getTopParentId() + '-' + getSettingsKey(item);
const sortValues = userSettings.getSortValues(sortParentId);
dmitrylyzo marked this conversation as resolved.
Show resolved Hide resolved
playbackManager[method]({
items: [item],
startPositionTicks: startPosition
startPositionTicks: startPosition,
queryOptions: sortValues
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
});
}
}
Expand Down
23 changes: 13 additions & 10 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',
sortBy: options.shuffle ? 'Random' : 'SortName',
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
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'
});
}));
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
} else if (firstItem.IsFolder && firstItem.CollectionType === 'homevideos') {
promise = getItemsForPlayback(serverId, mergePlaybackQueries({
ParentId: firstItem.Id,
Expand Down
8 changes: 7 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 Down Expand Up @@ -205,7 +210,8 @@ function executeAction(card, target, action) {
playbackManager.play({
ids: [playableItemId],
startPositionTicks: startPositionTicks,
serverId: serverId
serverId: serverId,
queryOptions: userSettings.getSortValuesLegacy(sortParentId, 'SortName')
grafixeyehero marked this conversation as resolved.
Show resolved Hide resolved
});
} else {
console.warn('Unable to play item', item);
Expand Down
9 changes: 4 additions & 5 deletions src/controllers/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -722,11 +722,13 @@ class ItemsView {

function play() {
const currentItem = self.currentItem;
const values = self.getSortValues();

if (currentItem && !self.hasFilters) {
playbackManager.play({
items: [currentItem],
autoplay: true
autoplay: true,
queryOptions: values
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved
});
} else {
getItems(self, self.params, currentItem, null, 0, 300).then(function (result) {
Expand Down Expand Up @@ -960,10 +962,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
27 changes: 27 additions & 0 deletions src/scripts/settings/userSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,31 @@ 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
* @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 +697,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);