Skip to content

Commit 237dde9

Browse files
franz-dcJellyBrick
andauthored
feat(api-server): add absolute seek endpoint (#2748)
Co-authored-by: JellyBrick <[email protected]>
1 parent 65f4339 commit 237dde9

File tree

4 files changed

+42
-20
lines changed

4 files changed

+42
-20
lines changed

src/plugins/api-server/backend/routes/control.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
AuthHeadersSchema,
99
type ResponseSongInfo,
1010
SongInfoSchema,
11+
SeekSchema,
1112
GoForwardScheme,
1213
GoBackSchema,
1314
SwitchRepeatSchema,
@@ -103,7 +104,28 @@ const routes = {
103104
},
104105
},
105106
}),
106-
107+
seekTo: createRoute({
108+
method: 'post',
109+
path: `/api/${API_VERSION}/seek-to`,
110+
summary: 'seek',
111+
description: 'Seek to a specific time in the current song',
112+
request: {
113+
headers: AuthHeadersSchema,
114+
body: {
115+
description: 'seconds to seek to',
116+
content: {
117+
'application/json': {
118+
schema: SeekSchema,
119+
},
120+
},
121+
},
122+
},
123+
responses: {
124+
204: {
125+
description: 'Success',
126+
},
127+
},
128+
}),
107129
goBack: createRoute({
108130
method: 'post',
109131
path: `/api/${API_VERSION}/go-back`,
@@ -294,25 +316,6 @@ const routes = {
294316
},
295317
},
296318
}),
297-
seekTime: createRoute({
298-
method: 'get',
299-
path: `/api/${API_VERSION}/seek-time`,
300-
summary: 'get current play time and video duration',
301-
description: 'Get current play time and video duration in seconds',
302-
responses: {
303-
200: {
304-
description: 'Success',
305-
content: {
306-
'application/json': {
307-
schema: z.object({
308-
current: z.number().nullable().openapi({ example: 3 }),
309-
duration: z.number().nullable().openapi({ example: 233 }),
310-
}),
311-
},
312-
},
313-
},
314-
},
315-
}),
316319
songInfo: createRoute({
317320
method: 'get',
318321
path: `/api/${API_VERSION}/song-info`,
@@ -384,6 +387,13 @@ export const register = (
384387
ctx.status(204);
385388
return ctx.body(null);
386389
});
390+
app.openapi(routes.seekTo, (ctx) => {
391+
const { seconds } = ctx.req.valid('json');
392+
controller.seekTo(seconds);
393+
394+
ctx.status(204);
395+
return ctx.body(null);
396+
});
387397
app.openapi(routes.goBack, (ctx) => {
388398
const { seconds } = ctx.req.valid('json');
389399
controller.goBack(seconds);

src/plugins/api-server/backend/scheme/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './auth';
22
export * from './song-info';
3+
export * from './seek';
34
export * from './go-back';
45
export * from './go-forward';
56
export * from './switch-repeat';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { z } from '@hono/zod-openapi';
2+
3+
export const SeekSchema = z.object({
4+
seconds: z.number(),
5+
});

src/providers/song-controls.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ export default (win: BrowserWindow) => {
3434
playPause: () => win.webContents.send('ytmd:toggle-play'),
3535
like: () => win.webContents.send('ytmd:update-like', 'LIKE'),
3636
dislike: () => win.webContents.send('ytmd:update-like', 'DISLIKE'),
37+
seekTo: (seconds: ArgsType<number>) => {
38+
const secondsNumber = parseNumberFromArgsType(seconds);
39+
if (secondsNumber !== null) {
40+
win.webContents.send('ytmd:seek-to', seconds);
41+
}
42+
},
3743
goBack: (seconds: ArgsType<number>) => {
3844
const secondsNumber = parseNumberFromArgsType(seconds);
3945
if (secondsNumber !== null) {

0 commit comments

Comments
 (0)