Refined Jellyfin Search
This commit is contained in:
@@ -81,15 +81,12 @@ export class Jellyfin implements Connection {
|
||||
if (!searchResponse.ok) throw new JellyfinFetchError('Failed to search Jellyfin', searchResponse.status, searchURL)
|
||||
const searchResults = (await searchResponse.json()).Items as (JellyfinAPI.Song | JellyfinAPI.Album)[] // JellyfinAPI.Artist
|
||||
|
||||
const parsedResults: MediaItem[] = []
|
||||
searchResults.forEach((result) => {
|
||||
const parsedResults: MediaItem[] = Array.from(searchResults, (result) => {
|
||||
switch (result.Type) {
|
||||
case 'Audio':
|
||||
parsedResults.push(this.parseSong(result))
|
||||
break
|
||||
return this.parseSong(result)
|
||||
case 'MusicAlbum':
|
||||
parsedResults.push(this.parseAlbum(result))
|
||||
break
|
||||
return this.parseAlbum(result)
|
||||
}
|
||||
})
|
||||
return parsedResults
|
||||
|
||||
@@ -74,6 +74,28 @@ export class YouTubeMusic implements Connection {
|
||||
return listenAgain.concat(quickPicks)
|
||||
}
|
||||
|
||||
public search = async (searchTerm: string): Promise<MediaItem[]> => {
|
||||
const headers = Object.assign(this.BASEHEADERS, { authorization: `Bearer ${(await this.getTokens()).accessToken}`, 'X-Goog-Request-Time': `${Date.now()}` })
|
||||
|
||||
const response = await fetch(`https://music.youtube.com/youtubei/v1/search`, {
|
||||
headers,
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
query: searchTerm,
|
||||
context: {
|
||||
client: {
|
||||
clientName: 'WEB_REMIX',
|
||||
clientVersion: `1.${formatDate()}.01.00`,
|
||||
hl: 'en',
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
const data = await response.json()
|
||||
console.log(JSON.stringify(data))
|
||||
}
|
||||
|
||||
private getHome = async (): Promise<YouTubeMusic.HomeItems> => {
|
||||
const headers = Object.assign(this.BASEHEADERS, { authorization: `Bearer ${(await this.getTokens()).accessToken}`, 'X-Goog-Request-Time': `${Date.now()}` })
|
||||
|
||||
|
||||
Reference in New Issue
Block a user