File size: 4,900 Bytes
3c56493
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// Type definitions based on HIFI API

export interface Track {
	id: number;
	title: string;
	duration: number;
	replayGain?: number;
	peak?: number;
	allowStreaming: boolean;
	streamReady: boolean;
	streamStartDate?: string;
	premiumStreamingOnly: boolean;
	trackNumber: number;
	volumeNumber: number;
	version: string | null;
	popularity: number;
	copyright?: string;
	url: string;
	isrc?: string;
	editable: boolean;
	explicit: boolean;
	audioQuality: string;
	audioModes: string[];
	artist: Artist;
	artists: Artist[];
	album: Album;
	mixes?: Record<string, string>;
	mediaMetadata?: {
		tags: string[];
	};
}

export interface Artist {
	id: number;
	name: string;
	type: string;
	picture?: string;
	url?: string;
	popularity?: number;
	artistTypes?: string[];
	artistRoles?: Array<{
		category: string;
		categoryId: number;
	}>;
	mixes?: Record<string, string>;
}

export interface ArtistDetails extends Artist {
	albums: Album[];
	tracks: Track[];
}

export interface Album {
	id: number;
	title: string;
	cover: string;
	videoCover: string | null;
	releaseDate?: string;
	duration?: number;
	numberOfTracks?: number;
	numberOfVideos?: number;
	numberOfVolumes?: number;
	explicit?: boolean;
	popularity?: number;
	type?: string;
	upc?: string;
	copyright?: string;
	artist?: Artist;
	artists?: Artist[];
	audioQuality?: string;
	audioModes?: string[];
	url?: string;
	vibrantColor?: string;
	streamReady?: boolean;
	allowStreaming?: boolean;
	mediaMetadata?: {
		tags: string[];
	};
}

export interface Playlist {
	uuid: string;
	title: string;
	description: string;
	image: string;
	squareImage?: string;
	duration: number;
	numberOfTracks: number;
	numberOfVideos: number;
	creator: {
		id: number;
		name: string;
		picture: string | null;
	};
	created: string;
	lastUpdated: string;
	type: string;
	publicPlaylist: boolean;
	url: string;
	popularity: number;
	promotedArtists?: Artist[];
}

export interface TrackInfo {
	trackId: number;
	audioQuality: string;
	audioMode: string;
	manifest: string;
	manifestMimeType: string;
	manifestHash?: string;
	assetPresentation: string;
	albumReplayGain?: number;
	albumPeakAmplitude?: number;
	trackReplayGain?: number;
	trackPeakAmplitude?: number;
	bitDepth?: number;
	sampleRate?: number;
}

export interface SearchResponse<T> {
	limit: number;
	offset: number;
	totalNumberOfItems: number;
	items: T[];
}

export interface CoverImage {
	id: number;
	name: string;
	'1280': string;
	'640': string;
	'80': string;
}

export interface Lyrics {
	trackId: number;
	lyricsProvider: string;
	providerCommontrackId: string;
	providerLyricsId: string;
	lyrics: string;
	subtitles: string;
	isRightToLeft: boolean;
}

export type AudioQuality = 'HI_RES_LOSSLESS' | 'LOSSLESS' | 'HIGH' | 'LOW';

export interface StreamData {
	originalTrack: string;
	trackInfo: TrackInfo;
	songInfo: Track;
}

export interface TrackLookup {
	track: Track;
	info: TrackInfo;
	originalTrackUrl?: string;
}

export interface TrackRecommendationsResponse {
	version: string,
	data: {
		limit: number;
		offset: number;
		totalNumberOfItems: number,
		items: {
			track: Track;
			sources: string[]
		}[]
	}
}

/**
 * Songlink API response types (copied to avoid circular dependency)
 */
export interface SonglinkEntity {
	id: string;
	type: 'song' | 'album';
	title?: string;
	artistName?: string;
	thumbnailUrl?: string;
	thumbnailWidth?: number;
	thumbnailHeight?: number;
	apiProvider: string;
	platforms: string[];
}

export interface SonglinkPlatformLink {
	country: string;
	url: string;
	nativeAppUriMobile?: string;
	nativeAppUriDesktop?: string;
	entityUniqueId: string;
}

export interface SonglinkResponse {
	entityUniqueId: string;
	userCountry: string;
	pageUrl: string;
	entitiesByUniqueId: Record<string, SonglinkEntity>;
	linksByPlatform: Record<string, SonglinkPlatformLink>;
}

/**
 * Represents a track from Songlink API that hasn't been converted to a full TIDAL track yet
 * Used to defer expensive TIDAL API calls until the track is actually played
 */
export interface SonglinkTrack {
	// Unique identifier (e.g., "spotify:track:3RiPr603aXAoi4GHyXx0uy")
	id: string;
	title: string;
	artistName: string;
	// Duration is unknown from Songlink, use placeholder
	duration: number;
	thumbnailUrl: string;
	// Store the original URL for later conversion
	sourceUrl: string;
	// Store Songlink response data
	songlinkData: SonglinkResponse;
	// Flag to identify this as a Songlink track
	isSonglinkTrack: true;
	// Optional Tidal ID if available
	tidalId?: number;
	// Assume CD quality for display purposes
	audioQuality: 'LOSSLESS';
}

/**
 * Union type for tracks that can be played
 */
export type PlayableTrack = Track | SonglinkTrack;

/**
 * Type guard to check if a track is a SonglinkTrack
 */
export function isSonglinkTrack(track: PlayableTrack): track is SonglinkTrack {
	return 'isSonglinkTrack' in track && track.isSonglinkTrack === true;
}