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 4 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
34 changes: 28 additions & 6 deletions src/components/playback/playbackmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -1773,6 +1773,18 @@ class PlaybackManager {
});
}

function getSortOptions(options) {
const sortOptions = options.sortOptions || {};
let sortByValue = options.shuffle ? 'Random' : sortOptions.sortBy;
if (sortByValue == null) {
sortByValue = 'SortName';
}
return {
sortBy: sortByValue,
sortOrder: sortOptions.sortOrder
};
}

function translateItemsForPlayback(items, options) {
if (items.length > 1 && options && options.ids) {
// Use the original request id array for sorting the result in the proper order
Expand All @@ -1788,6 +1800,8 @@ class PlaybackManager {

const queryOptions = options.queryOptions || {};

const sortOptions = getSortOptions(options);

if (firstItem.Type === 'Program') {
promise = getItemsForPlayback(serverId, {
Ids: firstItem.ChannelId
Expand All @@ -1802,7 +1816,8 @@ class PlaybackManager {
ArtistIds: firstItem.Id,
Filters: 'IsNotFolder',
Recursive: true,
SortBy: options.shuffle ? 'Random' : 'SortName',
SortBy: sortOptions.sortBy,
SortOrder: sortOptions.sortOrder,
MediaTypes: 'Audio'
});
} else if (firstItem.MediaType === 'Photo') {
Expand All @@ -1811,7 +1826,8 @@ class PlaybackManager {
Filters: 'IsNotFolder',
// Setting this to true may cause some incorrect sorting
Recursive: false,
SortBy: options.shuffle ? 'Random' : 'SortName',
SortBy: sortOptions.sortBy,
SortOrder: sortOptions.sortOrder,
MediaTypes: 'Photo,Video',
Limit: UNLIMITED_ITEMS
}).then(function (result) {
Expand All @@ -1835,7 +1851,8 @@ class PlaybackManager {
Filters: 'IsNotFolder',
// Setting this to true may cause some incorrect sorting
Recursive: false,
SortBy: options.shuffle ? 'Random' : 'SortName',
SortBy: sortOptions.sortBy,
SortOrder: sortOptions.sortOrder,
// Only include Photos because we do not handle mixed queues currently
MediaTypes: 'Photo',
Limit: UNLIMITED_ITEMS
Expand All @@ -1845,32 +1862,37 @@ class PlaybackManager {
GenreIds: firstItem.Id,
Filters: 'IsNotFolder',
Recursive: true,
SortBy: options.shuffle ? 'Random' : 'SortName',
SortBy: sortOptions.sortBy,
SortOrder: sortOptions.sortOrder,
MediaTypes: 'Audio'
});
} else if (firstItem.IsFolder && firstItem.CollectionType === 'homevideos') {
promise = getItemsForPlayback(serverId, mergePlaybackQueries({
ParentId: firstItem.Id,
Filters: 'IsNotFolder',
Recursive: true,
SortBy: options.shuffle ? 'Random' : 'SortName',
SortBy: sortOptions.sortBy,
SortOrder: sortOptions.sortOrder,
// Only include Photos because we do not handle mixed queues currently
MediaTypes: 'Photo',
Limit: UNLIMITED_ITEMS
}, queryOptions));
} else if (firstItem.IsFolder) {
let sortBy = null;
let sortOrder = null;
if (options.shuffle) {
sortBy = 'Random';
} else if (firstItem.Type !== 'BoxSet') {
sortBy = 'SortName';
sortBy = sortOptions.sortBy;
sortOrder = sortOptions.sortOrder;
}
promise = getItemsForPlayback(serverId, mergePlaybackQueries({
ParentId: firstItem.Id,
Filters: 'IsNotFolder',
Recursive: true,
// These are pre-sorted
SortBy: sortBy,
SortOrder: sortOrder,
MediaTypes: 'Audio,Video'
}, queryOptions));
} else if (firstItem.Type === 'Episode' && items.length === 1 && getPlayer(firstItem, options).supportsProgress !== false) {
Expand Down
16 changes: 15 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 @@ -165,6 +166,14 @@ function showPlayMenu(card, target) {
});
}

function getSortValues(parentId) {
const basekey = 'items-' + parentId + '-Folder';
return {
sortBy: userSettings.getFilter(basekey + '-sortby'),
sortOrder: userSettings.getFilter(basekey + '-sortorder') === 'Descending' ? 'Descending' : 'Ascending'
};
}
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved

function executeAction(card, target, action) {
target = target || card;

Expand All @@ -175,6 +184,10 @@ function executeAction(card, target, action) {
id = card.getAttribute('data-id');
}

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

const parentId = itemsContainer.getAttribute('data-parentid');

const item = getItemInfoFromCard(card);
v0idMrK marked this conversation as resolved.
Show resolved Hide resolved

const serverId = item.ServerId;
Expand Down Expand Up @@ -205,7 +218,8 @@ function executeAction(card, target, action) {
playbackManager.play({
ids: [playableItemId],
startPositionTicks: startPositionTicks,
serverId: serverId
serverId: serverId,
sortOptions: getSortValues(parentId)
});
} else {
console.warn('Unable to play item', item);
Expand Down
4 changes: 3 additions & 1 deletion 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,
sortOptions: values
});
} else {
getItems(self, self.params, currentItem, null, 0, 300).then(function (result) {
Expand Down
Loading