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

Migrate getInstantMixItems to jellyfin-sdk-typescript #694

Merged
merged 2 commits into from
Nov 10, 2024
Merged
Changes from 1 commit
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
57 changes: 33 additions & 24 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ import type {
BaseItemDto,
BaseItemPerson,
TvShowsApiGetEpisodesRequest,
UserDto
UserDto,
InstantMixApiGetInstantMixFromAlbumRequest,
InstantMixApiGetInstantMixFromPlaylistRequest,
InstantMixApiGetInstantMixFromArtistsRequest,
InstantMixApiGetInstantMixFromSongRequest
} from '@jellyfin/sdk/lib/generated-client';
import { getTvShowsApi } from '@jellyfin/sdk/lib/utils/api';
import { getInstantMixApi, getTvShowsApi } from '@jellyfin/sdk/lib/utils/api';
import { JellyfinApi } from './components/jellyfinApi';
import { PlaybackManager, PlaybackState } from './components/playbackManager';
import { BusMessage, ItemQuery } from './types/global';

type InstantMixApiRequest =
| InstantMixApiGetInstantMixFromAlbumRequest
| InstantMixApiGetInstantMixFromArtistsRequest
| InstantMixApiGetInstantMixFromSongRequest
| InstantMixApiGetInstantMixFromPlaylistRequest;

export const TicksPerSecond = 10000000;

/**
Expand Down Expand Up @@ -508,38 +518,37 @@ export async function getInstantMixItems(
userId: string,
item: BaseItemDto
): Promise<BaseItemDtoQueryResult> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const query: any = {
Fields: requiredItemFields,
Limit: 50,
UserId: userId
if (item.Id === undefined) {
throw new Error('Item ID not provided');
}

const query: InstantMixApiRequest = {
fields: ['MediaSources', 'Chapters'],
itemId: item.Id,
limit: 50,
userId
3flex marked this conversation as resolved.
Show resolved Hide resolved
};

let url: string | null = null;
const instantMixApi = getInstantMixApi(JellyfinApi.jellyfinApi);

if (item.Type == 'MusicArtist') {
url = 'Artists/InstantMix';
query.Id = item.Id;
return (await instantMixApi.getInstantMixFromArtists(query)).data;
} else if (item.Type == 'MusicGenre') {
url = 'MusicGenres/InstantMix';
query.Id = item.Id;
return (
await instantMixApi.getInstantMixFromMusicGenreById({
...query,
id: item.Id
})
).data;
} else if (item.Type == 'MusicAlbum') {
url = `Albums/${item.Id}/InstantMix`;
return (await instantMixApi.getInstantMixFromAlbum(query)).data;
} else if (item.Type == 'Audio') {
url = `Songs/${item.Id}/InstantMix`;
return (await instantMixApi.getInstantMixFromSong(query)).data;
} else if (item.Type == 'Playlist') {
url = `Playlists/${item.Id}/InstantMix`;
return (await instantMixApi.getInstantMixFromPlaylist(query)).data;
}

if (url) {
return JellyfinApi.authAjax(url, {
dataType: 'json',
query: query,
type: 'GET'
});
} else {
throw new Error(`InstantMix: Unknown item type: ${item.Type}`);
}
throw new Error(`InstantMix: Unknown item type: ${item.Type}`);
}

/**
Expand Down
Loading