Skip to content

Commit

Permalink
feat: update lyrics fetching to use new genius-lyrics client
Browse files Browse the repository at this point in the history
  • Loading branch information
Drack112 committed Jan 11, 2025
1 parent 0404e3b commit 0fe77e3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 576 deletions.
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"drizzle-orm": "^0.38.3",
"framer-motion": "^11.2.12",
"fuse.js": "^7.0.0",
"genius-lyrics-api": "^3.2.1",
"genius-lyrics": "^4.4.7",
"get-artist-title": "^1.3.1",
"get-youtube-id": "^1.0.1",
"graphql": "^16.9.0",
Expand Down
16 changes: 5 additions & 11 deletions apps/web/src/server/modules/lyrics/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore-next-line

import { getLyrics as getLyricsRequest } from 'genius-lyrics-api'

import { Client } from 'genius-lyrics'
import { logger } from '@/server/logger'

import type { GetLyricsOptions } from './types'

const api = new Client(process.env.GENIUS_ACCESS_TOKEN!)

const getLyrics = async (args: Pick<GetLyricsOptions, 'artist' | 'title'>) => {
const [title, artist] = `${args.title}${args.artist}`
.toLowerCase()
Expand All @@ -20,15 +21,8 @@ const getLyrics = async (args: Pick<GetLyricsOptions, 'artist' | 'title'>) => {

logger.info(`Fetching lyrics for ${title} by ${artist}`)

return getLyricsRequest({
...args,
title,
artist,
apiKey: process.env.GENIUS_ACCESS_TOKEN!,
optimizeQuery: false,
authHeader: true,
reverseProxy: process.env.PROXY,
} satisfies GetLyricsOptions) as Promise<string>
const response = await api.songs.search(`${title} ${artist}`)
return await response[0].lyrics()
}

export { getLyrics }
Loading

0 comments on commit 0fe77e3

Please sign in to comment.