@@ -8,13 +8,13 @@ import { SpotifyPreAuthState } from './SpotifyPreAuthState';
88import { SpotifyAuthState } from './SpotifyAuthState' ;
99import { clearTimeout } from 'node:timers' ;
1010import { SpotifyCurrentPlayingState } from './SpotifyCurrentPlayingState' ;
11- import { LRCLibSearchResponse } from './api/response/LRCLibGetResponse' ;
12- import { LRCLibApi } from './api/LRCLibApi' ;
1311import TreeMap from 'ts-treemap' ;
1412import { LyricsEntry } from './LyricsEntry' ;
1513import { generateTextColor , getAccentColorFromUrl } from './ColorUtil' ;
1614import path from 'node:path' ;
1715import LRUCache from 'lru-cache' ;
16+ import { LRCLibLyricsProvider } from './provider/LRCLibLyricsProvider' ;
17+ import { LyricsProvider } from './provider/LyricsProvider' ;
1818
1919let panel : WebviewPanel | undefined ;
2020
@@ -26,6 +26,8 @@ let tracksCache: LRUCache<string, SpotifyCurrentPlayingState>;
2626let server : http . Server | null ;
2727let pollingTimeout : NodeJS . Timeout | null ;
2828
29+ const provider : LyricsProvider = new LRCLibLyricsProvider ( ) ;
30+
2931export async function activate ( context : vscode . ExtensionContext ) {
3032 context . subscriptions . push (
3133 vscode . commands . registerCommand ( 'spotilyrics.lyrics' , async ( ) => {
@@ -352,16 +354,16 @@ async function updateLyrics() {
352354 currentPlayingState . authors !== artists ||
353355 currentPlayingState . name !== trackName
354356 ) {
355- const getLyricsResponse : LRCLibSearchResponse = await LRCLibApi . get (
357+ const lyricsResult = await provider . getLyrics (
356358 trackName ,
357359 artists ,
358360 albumName ,
359361 durationInS
360362 ) ;
361- if ( ! getLyricsResponse . statusCode && ! getLyricsResponse . instrumental ) {
363+ if ( lyricsResult && ! lyricsResult . instrumental ) {
362364 const currentlyPlayingPoll = new SpotifyCurrentPlayingState ( trackName , artists ) ;
363- if ( getLyricsResponse . plainLyrics ) {
364- const plainLyricsStrs : string [ ] = getLyricsResponse . plainLyrics
365+ if ( lyricsResult . plainLyrics ) {
366+ const plainLyricsStrs : string [ ] = lyricsResult . plainLyrics
365367 . split ( / \n / )
366368 . map ( ( s ) => s . trim ( ) )
367369 . filter ( ( s ) => s !== '' )
@@ -370,9 +372,9 @@ async function updateLyrics() {
370372 currentlyPlayingPoll . plainLyricsStrs = plainLyricsStrs ;
371373 }
372374 // load synchronized lyrics in treemap
373- if ( getLyricsResponse . syncedLyrics ) {
375+ if ( lyricsResult . syncedLyrics ) {
374376 const synchronizedLyricsMap = new TreeMap < number , LyricsEntry > ( ) ;
375- const synchronizedLyricsStrs : string [ ] = getLyricsResponse . syncedLyrics
377+ const synchronizedLyricsStrs : string [ ] = lyricsResult . syncedLyrics
376378 . split ( / (? = \[ \d { 2 } : \d { 2 } \. \d { 2 } \] ) / )
377379 . filter ( ( s ) => s . trim ( ) !== '' ) ;
378380 let id : number = 0 ;
0 commit comments