mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 02:13:33 +00:00
[enhancement]: allow downloading individual tracks for external use
This commit is contained in:
parent
10fca2dc12
commit
c4677a63f6
10 changed files with 91 additions and 6 deletions
|
|
@ -8,7 +8,8 @@ export const QUEUE_CONTEXT_MENU_ITEMS: SetContextMenuItems = [
|
|||
{ id: 'addToFavorites' },
|
||||
{ divider: true, id: 'removeFromFavorites' },
|
||||
{ children: true, disabled: false, id: 'setRating' },
|
||||
{ disabled: false, id: 'deselectAll' },
|
||||
{ disabled: false, divider: true, id: 'deselectAll' },
|
||||
{ id: 'download' },
|
||||
{ divider: true, id: 'shareItem' },
|
||||
{ divider: true, id: 'showDetails' },
|
||||
];
|
||||
|
|
@ -22,6 +23,7 @@ export const SONG_CONTEXT_MENU_ITEMS: SetContextMenuItems = [
|
|||
{ id: 'addToFavorites' },
|
||||
{ divider: true, id: 'removeFromFavorites' },
|
||||
{ children: true, disabled: false, divider: true, id: 'setRating' },
|
||||
{ id: 'download' },
|
||||
{ divider: true, id: 'shareItem' },
|
||||
{ divider: true, id: 'showDetails' },
|
||||
];
|
||||
|
|
@ -43,6 +45,7 @@ export const PLAYLIST_SONG_CONTEXT_MENU_ITEMS: SetContextMenuItems = [
|
|||
{ id: 'addToFavorites' },
|
||||
{ divider: true, id: 'removeFromFavorites' },
|
||||
{ children: true, disabled: false, id: 'setRating' },
|
||||
{ id: 'download' },
|
||||
{ divider: true, id: 'shareItem' },
|
||||
{ divider: true, id: 'showDetails' },
|
||||
];
|
||||
|
|
@ -56,6 +59,7 @@ export const SMART_PLAYLIST_SONG_CONTEXT_MENU_ITEMS: SetContextMenuItems = [
|
|||
{ id: 'addToFavorites' },
|
||||
{ divider: true, id: 'removeFromFavorites' },
|
||||
{ children: true, disabled: false, id: 'setRating' },
|
||||
{ id: 'download' },
|
||||
{ divider: true, id: 'shareItem' },
|
||||
{ divider: true, id: 'showDetails' },
|
||||
];
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import {
|
|||
RiShareForwardFill,
|
||||
RiInformationFill,
|
||||
RiRadio2Fill,
|
||||
RiDownload2Line,
|
||||
} from 'react-icons/ri';
|
||||
import { AnyLibraryItems, LibraryItem, ServerType, AnyLibraryItem } from '/@/renderer/api/types';
|
||||
import {
|
||||
|
|
@ -62,6 +63,7 @@ import { Play, PlaybackType } from '/@/renderer/types';
|
|||
import { ItemDetailsModal } from '/@/renderer/features/item-details/components/item-details-modal';
|
||||
import { updateSong } from '/@/renderer/features/player/update-remote-song';
|
||||
import { controller } from '/@/renderer/api/controller';
|
||||
import { api } from '/@/renderer/api';
|
||||
|
||||
type ContextMenuContextProps = {
|
||||
closeContextMenu: () => void;
|
||||
|
|
@ -90,6 +92,7 @@ const JELLYFIN_IGNORED_MENU_ITEMS: ContextMenuItemType[] = ['setRating', 'shareI
|
|||
// const SUBSONIC_IGNORED_MENU_ITEMS: ContextMenuItemType[] = [];
|
||||
|
||||
const mpvPlayer = isElectron() ? window.electron.mpvPlayer : null;
|
||||
const utils = isElectron() ? window.electron.utils : null;
|
||||
|
||||
export interface ContextMenuProviderProps {
|
||||
children: ReactNode;
|
||||
|
|
@ -685,6 +688,20 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
|||
handlePlayQueueAdd?.({ byData: [ctx.data[0], ...songs], playType: Play.NOW });
|
||||
}, [ctx, handlePlayQueueAdd]);
|
||||
|
||||
const handleDownload = useCallback(() => {
|
||||
const item = ctx.data[0];
|
||||
const url = api.controller.getDownloadUrl({
|
||||
apiClientProps: { server },
|
||||
query: { id: item.id },
|
||||
});
|
||||
|
||||
if (utils) {
|
||||
utils.download(url!);
|
||||
} else {
|
||||
window.open(url, '_blank');
|
||||
}
|
||||
}, [ctx.data, server]);
|
||||
|
||||
const contextMenuItems: Record<ContextMenuItemType, ContextMenuItem> = useMemo(() => {
|
||||
return {
|
||||
addToFavorites: {
|
||||
|
|
@ -716,6 +733,13 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
|||
leftIcon: <RiCloseCircleLine size="1.1rem" />,
|
||||
onClick: handleDeselectAll,
|
||||
},
|
||||
download: {
|
||||
disabled: ctx.data?.length !== 1,
|
||||
id: 'download',
|
||||
label: t('page.contextMenu.download', { postProcess: 'sentenceCase' }),
|
||||
leftIcon: <RiDownload2Line size="1.1rem" />,
|
||||
onClick: handleDownload,
|
||||
},
|
||||
moveToBottomOfQueue: {
|
||||
id: 'moveToBottomOfQueue',
|
||||
label: t('page.contextMenu.moveToBottom', { postProcess: 'sentenceCase' }),
|
||||
|
|
@ -860,18 +884,19 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
|||
handleAddToPlaylist,
|
||||
openDeletePlaylistModal,
|
||||
handleDeselectAll,
|
||||
ctx.data,
|
||||
handleDownload,
|
||||
handleMoveToBottom,
|
||||
handleMoveToTop,
|
||||
handleSimilar,
|
||||
handleRemoveFromFavorites,
|
||||
handleRemoveFromPlaylist,
|
||||
handleRemoveSelected,
|
||||
ctx.data,
|
||||
server,
|
||||
handleShareItem,
|
||||
handleOpenItemDetails,
|
||||
handlePlay,
|
||||
handleUpdateRating,
|
||||
handleShareItem,
|
||||
server,
|
||||
handleSimilar,
|
||||
]);
|
||||
|
||||
const mergedRef = useMergedRef(ref, clickOutsideRef);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ export type ContextMenuItemType =
|
|||
| 'removeFromQueue'
|
||||
| 'deselectAll'
|
||||
| 'showDetails'
|
||||
| 'playSimilarSongs';
|
||||
| 'playSimilarSongs'
|
||||
| 'download';
|
||||
|
||||
export type SetContextMenuItems = {
|
||||
children?: boolean;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue