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 Server Rescan #268

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .github/workflows/publish-docker-auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: |
linux/amd64
linux/arm/v7
linux/arm64/v8
linux/amd64
linux/arm/v7
linux/arm64/v8
6 changes: 3 additions & 3 deletions .github/workflows/publish-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: |
linux/amd64
linux/arm/v7
linux/arm64/v8
linux/amd64
linux/arm/v7
linux/arm64/v8
1 change: 1 addition & 0 deletions src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@
"home": "$t(common.home)",
"nowPlaying": "now playing",
"playlists": "$t(entity.playlist_other)",
"rescan": "rescan",
"search": "$t(common.search)",
"settings": "$t(common.setting_other)",
"tracks": "$t(entity.track_other)"
Expand Down
28 changes: 28 additions & 0 deletions src/renderer/api/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ import type {
SearchResponse,
LyricsArgs,
LyricsResponse,
RescanArgs,
ScanStatus,
ScanStatusArgs,
ServerInfo,
ServerInfoArgs,
StructuredLyricsArgs,
Expand Down Expand Up @@ -89,13 +92,15 @@ export type ControllerEndpoint = Partial<{
getPlaylistList: (args: PlaylistListArgs) => Promise<PlaylistListResponse>;
getPlaylistSongList: (args: PlaylistSongListArgs) => Promise<SongListResponse>;
getRandomSongList: (args: RandomSongListArgs) => Promise<SongListResponse>;
getScanStatus: (args: ScanStatusArgs) => Promise<ScanStatus>;
getServerInfo: (args: ServerInfoArgs) => Promise<ServerInfo>;
getSongDetail: (args: SongDetailArgs) => Promise<SongDetailResponse>;
getSongList: (args: SongListArgs) => Promise<SongListResponse>;
getStructuredLyrics: (args: StructuredLyricsArgs) => Promise<StructuredLyric[]>;
getTopSongs: (args: TopSongListArgs) => Promise<TopSongListResponse>;
getUserList: (args: UserListArgs) => Promise<UserListResponse>;
removeFromPlaylist: (args: RemoveFromPlaylistArgs) => Promise<RemoveFromPlaylistResponse>;
rescan: (args: RescanArgs) => Promise<ScanStatus>;
scrobble: (args: ScrobbleArgs) => Promise<ScrobbleResponse>;
search: (args: SearchArgs) => Promise<SearchResponse>;
setRating: (args: SetRatingArgs) => Promise<RatingResponse>;
Expand Down Expand Up @@ -135,13 +140,15 @@ const endpoints: ApiController = {
getPlaylistList: jfController.getPlaylistList,
getPlaylistSongList: jfController.getPlaylistSongList,
getRandomSongList: jfController.getRandomSongList,
getScanStatus: undefined,
getServerInfo: jfController.getServerInfo,
getSongDetail: jfController.getSongDetail,
getSongList: jfController.getSongList,
getStructuredLyrics: undefined,
getTopSongs: jfController.getTopSongList,
getUserList: undefined,
removeFromPlaylist: jfController.removeFromPlaylist,
rescan: jfController.rescan,
scrobble: jfController.scrobble,
search: jfController.search,
setRating: undefined,
Expand Down Expand Up @@ -173,13 +180,15 @@ const endpoints: ApiController = {
getPlaylistList: ndController.getPlaylistList,
getPlaylistSongList: ndController.getPlaylistSongList,
getRandomSongList: ssController.getRandomSongList,
getScanStatus: ssController.getScanStatus,
getServerInfo: ssController.getServerInfo,
getSongDetail: ndController.getSongDetail,
getSongList: ndController.getSongList,
getStructuredLyrics: ssController.getStructuredLyrics,
getTopSongs: ssController.getTopSongList,
getUserList: ndController.getUserList,
removeFromPlaylist: ndController.removeFromPlaylist,
rescan: ssController.rescan,
scrobble: ssController.scrobble,
search: ssController.search3,
setRating: ssController.setRating,
Expand Down Expand Up @@ -208,12 +217,14 @@ const endpoints: ApiController = {
getMusicFolderList: ssController.getMusicFolderList,
getPlaylistDetail: undefined,
getPlaylistList: undefined,
getScanStatus: ssController.getScanStatus,
getServerInfo: ssController.getServerInfo,
getSongDetail: undefined,
getSongList: undefined,
getStructuredLyrics: ssController.getStructuredLyrics,
getTopSongs: ssController.getTopSongList,
getUserList: undefined,
rescan: ssController.rescan,
scrobble: ssController.scrobble,
search: ssController.search3,
setRating: undefined,
Expand Down Expand Up @@ -493,6 +504,21 @@ const getLyrics = async (args: LyricsArgs) => {
)?.(args);
};

const rescan = async (args: RescanArgs) => {
return (
apiController('rescan', args.apiClientProps.server?.type) as ControllerEndpoint['rescan']
)?.(args);
};

const getScanStatus = async (args: RescanArgs) => {
return (
apiController(
'getScanStatus',
args.apiClientProps.server?.type,
) as ControllerEndpoint['getScanStatus']
)?.(args);
};

const getServerInfo = async (args: ServerInfoArgs) => {
return (
apiController(
Expand Down Expand Up @@ -530,13 +556,15 @@ export const controller = {
getPlaylistList,
getPlaylistSongList,
getRandomSongList,
getScanStatus,
getServerInfo,
getSongDetail,
getSongList,
getStructuredLyrics,
getTopSongList,
getUserList,
removeFromPlaylist,
rescan,
scrobble,
search,
updatePlaylist,
Expand Down
9 changes: 9 additions & 0 deletions src/renderer/api/jellyfin/jellyfin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,15 @@ export const contract = c.router({
400: jfType._response.error,
},
},
refresh: {
body: null,
method: 'POST',
path: 'library/refresh',
responses: {
204: z.null(),
400: jfType._response.error,
},
},
removeFavorite: {
body: jfType._parameters.favorite,
method: 'DELETE',
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/api/jellyfin/jellyfin-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import {
LyricsArgs,
LyricsResponse,
genreListSortMap,
RescanArgs,
ScanStatus,
SongDetailArgs,
SongDetailResponse,
ServerInfo,
Expand Down Expand Up @@ -931,6 +933,24 @@ const getLyrics = async (args: LyricsArgs): Promise<LyricsResponse> => {
return res.body.Lyrics.map((lyric) => [lyric.Start! / 1e4, lyric.Text]);
};

const rescan = async (args: RescanArgs): Promise<ScanStatus> => {
const { apiClientProps } = args;

if (!apiClientProps.server?.userId) {
throw new Error('No userId found');
}

const res = await jfApiClient(apiClientProps).refresh({
body: null,
});

if (res.status !== 204) {
throw new Error('Failed to start scan');
}

return { scanning: true };
};

const getSongDetail = async (args: SongDetailArgs): Promise<SongDetailResponse> => {
const { query, apiClientProps } = args;

Expand Down Expand Up @@ -984,6 +1004,7 @@ export const jfController = {
getSongList,
getTopSongList,
removeFromPlaylist,
rescan,
scrobble,
search,
updatePlaylist,
Expand Down
15 changes: 15 additions & 0 deletions src/renderer/api/subsonic/subsonic-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export const contract = c.router({
200: ssType._response.randomSongList,
},
},
getScanStatus: {
method: 'GET',
path: 'getScanStatus.view',
responses: {
200: ssType._response.scanStatus,
},
},
getServerInfo: {
method: 'GET',
path: 'getOpenSubsonicExtensions.view',
Expand Down Expand Up @@ -112,6 +119,14 @@ export const contract = c.router({
200: ssType._response.setRating,
},
},
startScan: {
method: 'GET',
path: 'startScan.view',
query: ssType._parameters.scan,
responses: {
200: ssType._response.scanStatus,
},
},
});

const axiosClient = axios.create({});
Expand Down
55 changes: 55 additions & 0 deletions src/renderer/api/subsonic/subsonic-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
SearchResponse,
RandomSongListResponse,
RandomSongListArgs,
RescanArgs,
ScanStatus,
ScanStatusArgs,
ServerInfo,
ServerInfoArgs,
StructuredLyricsArgs,
Expand Down Expand Up @@ -372,6 +375,56 @@ const getRandomSongList = async (args: RandomSongListArgs): Promise<RandomSongLi
};
};

const rescan = async (args: RescanArgs): Promise<ScanStatus> => {
const { full, apiClientProps } = args;

if (!apiClientProps.server?.userId) {
throw new Error('No userId found');
}

const res = await ssApiClient(apiClientProps).startScan({
query:
full !== undefined
? {
fullScan: full,
}
: undefined,
});

if (res.status !== 200) {
throw new Error('Could not start scan');
}

const { scanning, count, folderCount } = res.body.scanStatus;

return {
folders: folderCount,
scanning,
tracks: count,
};
};

const getScanStatus = async (args: ScanStatusArgs): Promise<ScanStatus> => {
const { apiClientProps } = args;

if (!apiClientProps.server?.userId) {
throw new Error('No userId found');
}

const res = await ssApiClient(apiClientProps).getScanStatus();
if (res.status !== 200) {
throw new Error('Could not start scan');
}

const { scanning, count, folderCount } = res.body.scanStatus;

return {
folders: folderCount,
scanning,
tracks: count,
};
};

const getServerInfo = async (args: ServerInfoArgs): Promise<ServerInfo> => {
const { apiClientProps } = args;

Expand Down Expand Up @@ -450,10 +503,12 @@ export const ssController = {
getArtistInfo,
getMusicFolderList,
getRandomSongList,
getScanStatus,
getServerInfo,
getStructuredLyrics,
getTopSongList,
removeFavorite,
rescan,
scrobble,
search3,
setRating,
Expand Down
23 changes: 18 additions & 5 deletions src/renderer/api/subsonic/subsonic-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ const randomSongList = z.object({
}),
});

const scanParameters = z.object({
fullScan: z.boolean().optional(),
});

const scanStatus = z.object({
scanStatus: z.object({
count: z.number().optional(),
folderCount: z.number().optional(),
lastScan: z.string().optional(),
scanning: z.boolean(),
}),
});

const ping = z.object({
openSubsonic: z.boolean().optional(),
serverVersion: z.string().optional(),
Expand Down Expand Up @@ -240,11 +253,9 @@ const structuredLyric = z.object({
});

const structuredLyrics = z.object({
lyricsList: z
.object({
structuredLyrics: z.array(structuredLyric).optional(),
})
.optional(),
lyricsList: z.object({
structuredLyrics: z.array(structuredLyric).optional(),
}),
});

export const ssType = {
Expand All @@ -255,6 +266,7 @@ export const ssType = {
createFavorite: createFavoriteParameters,
randomSongList: randomSongListParameters,
removeFavorite: removeFavoriteParameters,
scan: scanParameters,
scrobble: scrobbleParameters,
search3: search3Parameters,
setRating: setRatingParameters,
Expand All @@ -274,6 +286,7 @@ export const ssType = {
ping,
randomSongList,
removeFavorite,
scanStatus,
scrobble,
search3,
serverInfo,
Expand Down
11 changes: 11 additions & 0 deletions src/renderer/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,17 @@ export enum LyricSource {

export type LyricsOverride = Omit<FullLyricsMetadata, 'lyrics'> & { id: string };

export type RescanArgs = {
full?: boolean;
} & BaseEndpointArgs;

export type ScanStatus = {
folders?: number;
scanning: boolean;
tracks?: number;
};

export type ScanStatusArgs = BaseEndpointArgs;
// This type from https://wicg.github.io/local-font-access/#fontdata
// NOTE: it is still experimental, so this should be updates as appropriate
export type FontData = {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/features/discord-rpc/use-discord-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const useDiscordRpc = () => {
largeImageText: currentSong?.album || 'Unknown album',
smallImageKey: undefined,
smallImageText: currentStatus,
state: artists && `By ${artists}` || "Unknown artist",
state: (artists && `By ${artists}`) || 'Unknown artist',
};

if (currentStatus === PlayerStatus.PLAYING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const SidebarSettings = () => {
Home: t('page.sidebar.home', { postProcess: 'titleCase' }),
'Now Playing': t('page.sidebar.nowPlaying', { postProcess: 'titleCase' }),
Playlists: t('page.sidebar.playlists', { postProcess: 'titleCase' }),
Rescan: t('page.sidebar.rescan', { postProcess: 'titleCase' }),
Search: t('page.sidebar.search', { postProcess: 'titleCase' }),
Settings: t('page.sidebar.settings', { postProcess: 'titleCase' }),
Tracks: t('page.sidebar.tracks', { postProcess: 'titleCase' }),
Expand Down
Loading
Loading