Skip to content

Commit

Permalink
Added support for non-timed lyrics in VK plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Azarattum committed Apr 21, 2024
1 parent 0677ce8 commit 7873e29
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions plugins/vk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ search(function* (type, query, page) {
const { response } = yield* safeFetch(
`audio.search${method}`,
{ params: { q: query, count: page, offset: i } },
responseOf(items(struct))
responseOf(items(struct)),
);
if (!response.items.length) break;
const results = convert(response.items, type);
Expand Down Expand Up @@ -101,13 +101,16 @@ transcribe(function* (track) {
params: { audio_id: id },
}).as(responseOf(optional(lyrics)));

if (!response?.lyrics) return;
yield response.lyrics.timestamps.map((x) => x.line || "").join("\n");
const lines =
response?.lyrics.timestamps?.map((x) => x.line || "") ||
response?.lyrics.text;

if (lines?.length) yield lines.join("\n");
});

function* identify(
data: { sources?: string[]; title?: string },
type: "track" | "artist" | "album"
type: "track" | "artist" | "album",
) {
return (
data.sources?.find((x) => x.startsWith("vk/"))?.slice(3) ||
Expand Down
15 changes: 9 additions & 6 deletions plugins/vk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,15 @@ const track = type({

const lyrics = type({
lyrics: type({
timestamps: array(
type({
begin: number(),
end: number(),
line: optional(string()),
}),
text: optional(array(string())),
timestamps: optional(
array(
type({
begin: number(),
end: number(),
line: optional(string()),
}),
),
),
}),
});
Expand Down

0 comments on commit 7873e29

Please sign in to comment.