mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 18:21:47 +00:00
feat(api-server): add absolute seek endpoint (#2748)
Co-authored-by: JellyBrick <shlee1503@naver.com>
This commit is contained in:
@ -8,6 +8,7 @@ import {
|
|||||||
AuthHeadersSchema,
|
AuthHeadersSchema,
|
||||||
type ResponseSongInfo,
|
type ResponseSongInfo,
|
||||||
SongInfoSchema,
|
SongInfoSchema,
|
||||||
|
SeekSchema,
|
||||||
GoForwardScheme,
|
GoForwardScheme,
|
||||||
GoBackSchema,
|
GoBackSchema,
|
||||||
SwitchRepeatSchema,
|
SwitchRepeatSchema,
|
||||||
@ -103,7 +104,28 @@ const routes = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
seekTo: createRoute({
|
||||||
|
method: 'post',
|
||||||
|
path: `/api/${API_VERSION}/seek-to`,
|
||||||
|
summary: 'seek',
|
||||||
|
description: 'Seek to a specific time in the current song',
|
||||||
|
request: {
|
||||||
|
headers: AuthHeadersSchema,
|
||||||
|
body: {
|
||||||
|
description: 'seconds to seek to',
|
||||||
|
content: {
|
||||||
|
'application/json': {
|
||||||
|
schema: SeekSchema,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
responses: {
|
||||||
|
204: {
|
||||||
|
description: 'Success',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
goBack: createRoute({
|
goBack: createRoute({
|
||||||
method: 'post',
|
method: 'post',
|
||||||
path: `/api/${API_VERSION}/go-back`,
|
path: `/api/${API_VERSION}/go-back`,
|
||||||
@ -294,25 +316,6 @@ const routes = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
seekTime: createRoute({
|
|
||||||
method: 'get',
|
|
||||||
path: `/api/${API_VERSION}/seek-time`,
|
|
||||||
summary: 'get current play time and video duration',
|
|
||||||
description: 'Get current play time and video duration in seconds',
|
|
||||||
responses: {
|
|
||||||
200: {
|
|
||||||
description: 'Success',
|
|
||||||
content: {
|
|
||||||
'application/json': {
|
|
||||||
schema: z.object({
|
|
||||||
current: z.number().nullable().openapi({ example: 3 }),
|
|
||||||
duration: z.number().nullable().openapi({ example: 233 }),
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
songInfo: createRoute({
|
songInfo: createRoute({
|
||||||
method: 'get',
|
method: 'get',
|
||||||
path: `/api/${API_VERSION}/song-info`,
|
path: `/api/${API_VERSION}/song-info`,
|
||||||
@ -384,6 +387,13 @@ export const register = (
|
|||||||
ctx.status(204);
|
ctx.status(204);
|
||||||
return ctx.body(null);
|
return ctx.body(null);
|
||||||
});
|
});
|
||||||
|
app.openapi(routes.seekTo, (ctx) => {
|
||||||
|
const { seconds } = ctx.req.valid('json');
|
||||||
|
controller.seekTo(seconds);
|
||||||
|
|
||||||
|
ctx.status(204);
|
||||||
|
return ctx.body(null);
|
||||||
|
});
|
||||||
app.openapi(routes.goBack, (ctx) => {
|
app.openapi(routes.goBack, (ctx) => {
|
||||||
const { seconds } = ctx.req.valid('json');
|
const { seconds } = ctx.req.valid('json');
|
||||||
controller.goBack(seconds);
|
controller.goBack(seconds);
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
export * from './auth';
|
export * from './auth';
|
||||||
export * from './song-info';
|
export * from './song-info';
|
||||||
|
export * from './seek';
|
||||||
export * from './go-back';
|
export * from './go-back';
|
||||||
export * from './go-forward';
|
export * from './go-forward';
|
||||||
export * from './switch-repeat';
|
export * from './switch-repeat';
|
||||||
|
|||||||
5
src/plugins/api-server/backend/scheme/seek.ts
Normal file
5
src/plugins/api-server/backend/scheme/seek.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { z } from '@hono/zod-openapi';
|
||||||
|
|
||||||
|
export const SeekSchema = z.object({
|
||||||
|
seconds: z.number(),
|
||||||
|
});
|
||||||
@ -34,6 +34,12 @@ export default (win: BrowserWindow) => {
|
|||||||
playPause: () => win.webContents.send('ytmd:toggle-play'),
|
playPause: () => win.webContents.send('ytmd:toggle-play'),
|
||||||
like: () => win.webContents.send('ytmd:update-like', 'LIKE'),
|
like: () => win.webContents.send('ytmd:update-like', 'LIKE'),
|
||||||
dislike: () => win.webContents.send('ytmd:update-like', 'DISLIKE'),
|
dislike: () => win.webContents.send('ytmd:update-like', 'DISLIKE'),
|
||||||
|
seekTo: (seconds: ArgsType<number>) => {
|
||||||
|
const secondsNumber = parseNumberFromArgsType(seconds);
|
||||||
|
if (secondsNumber !== null) {
|
||||||
|
win.webContents.send('ytmd:seek-to', seconds);
|
||||||
|
}
|
||||||
|
},
|
||||||
goBack: (seconds: ArgsType<number>) => {
|
goBack: (seconds: ArgsType<number>) => {
|
||||||
const secondsNumber = parseNumberFromArgsType(seconds);
|
const secondsNumber = parseNumberFromArgsType(seconds);
|
||||||
if (secondsNumber !== null) {
|
if (secondsNumber !== null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user