Skip to content

Commit

Permalink
feat: v1 and v2 types
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvdkolk committed Feb 1, 2024
1 parent 4632c43 commit cd0e869
Show file tree
Hide file tree
Showing 19 changed files with 182 additions and 85 deletions.
7 changes: 3 additions & 4 deletions src/interfaces/statsfm/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
export * from './album';
export * from './artist';
export * from './audio-analysis';
export * from './audio-features';
export * from './database_size';
export * from './friend_status';
export * from './genre';
export * from './giftCode';
export * from './query';
export * from './record';
Expand All @@ -13,7 +10,6 @@ export * from './soulmate';
export * from './stats';
export * from './stream';
export * from './top';
export * from './track';
export * from './user';

export interface Object {
Expand All @@ -22,3 +18,6 @@ export interface Object {
}

export type AvailableService = 'spotify' | 'appleMusic';

export * as v1 from './v1';
export * as v2 from './v2';
5 changes: 2 additions & 3 deletions src/interfaces/statsfm/search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Track, UserPublic } from '.';
import { Album } from './album';
import { Artist } from './artist';
import { UserPublic } from './user';
import { Album, Artist, Track } from './v1';

export enum SearchTypes {
TRACK = 'track',
Expand Down
23 changes: 23 additions & 0 deletions src/interfaces/statsfm/v1/album.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ArtistSimple } from './artist';
import { Object } from '..';
import { TopObject } from '../top';

export interface AlbumSimple extends Object {
name: string;
image: string;
}

export interface Album extends AlbumSimple {
label: string;
spotifyPopularity: number;
totalTracks: number;
releaseDate: Date;
genres: string[];
artists: ArtistSimple[];
externalIds: Record<string, unknown> & { spotify?: string[]; appleMusic?: string[] };
type: 'single' | 'complication' | 'album';
}

export interface TopAlbum extends TopObject {
album: Album;
}
18 changes: 18 additions & 0 deletions src/interfaces/statsfm/v1/artist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Object } from '..';
import { TopObject } from '../top';

export interface ArtistSimple extends Object {
name: string;
}

export interface Artist extends ArtistSimple {
followers: number;
image?: string;
spotifyPopularity: number;
externalIds: Record<string, unknown> & { spotify?: string[]; appleMusic?: string[] };
genres: string[];
}

export interface TopArtist extends TopObject {
artist: Artist;
}
18 changes: 18 additions & 0 deletions src/interfaces/statsfm/v1/genre.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Object } from '..';
import { ArtistSimple } from './artist';
import { TopObject } from '../top';

export interface GenreSimple extends Object {
tag: string;
}

export interface Genre extends GenreSimple {
artists: ArtistSimple[];
related: GenreSimple[];
sub: GenreSimple[];
}

export interface TopGenre extends TopObject {
genre: GenreSimple;
artistCount?: number;
}
4 changes: 4 additions & 0 deletions src/interfaces/statsfm/v1/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './album';
export * from './artist';
export * from './genre';
export * from './track';
33 changes: 33 additions & 0 deletions src/interfaces/statsfm/v1/track.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AlbumSimple } from './album';
import { ArtistSimple } from './artist';
import { Object } from '..';
import { TopObject } from '../top';

export interface Track extends Object {
name: string;
explicit: boolean;
durationMs: number;
spotifyPopularity: number;
spotifyPreview?: string;
externalIds: Record<string, unknown> & { spotify?: string[]; appleMusic?: string[] };
albums: AlbumSimple[];
artists: ArtistSimple[];
}
export interface RecentlyPlayedTrack {
endTime: Date;
platform: 'spotify' | 'appleMusic';
track: Track;
}

export interface CurrentlyPlayingTrack {
date: Date;
isPlaying: boolean;
progressMs: number;
deviceName?: string;
track: Track;
platform: 'spotify' | 'appleMusic';
}

export interface TopTrack extends TopObject {
track: Track;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Artist } from './artist';
import { Object, TrackRelease } from '.';
import { TopObject } from './top';
import { TopObject } from '../top';

export const AlbumReleaseType = {
SINGLE: 'SINGLE',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Object } from '.';
import { TopObject } from './top';
import { TopObject } from '../top';

export const ArtistImageSource = {
SPOTIFY: 'SPOTIFY',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Artist, TopArtist } from '.';
import { TopObject } from './top';
import { Artist, TopArtist } from './artist';
import { TopObject } from '../top';

export interface GenreSimple {
tag: string;
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/statsfm/v2/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './album';
export * from './artist';
export * from './genre';
export * from './track';
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AlbumRelease } from './album';
import { Artist } from './artist';
import { Object } from '.';
import { TopObject } from './top';
import { TopObject } from '../top';

export interface TrackRelease {
id: number;
Expand Down
20 changes: 10 additions & 10 deletions src/lib/albums/AlbumsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default class AlbumsManager extends Manager {
* @param {number} id The ID of the album.
* @returns {Promise<Album>} Returns a promise with a single {@link Album}.
*/
async get(id: number): Promise<statsfm.Album> {
const res = await this.http.get<ItemResponse<statsfm.Album>>(`/albums/${id}`);
async get(id: number): Promise<statsfm.v1.Album> {
const res = await this.http.get<ItemResponse<statsfm.v1.Album>>(`/albums/${id}`);

return res.item;
}
Expand All @@ -19,8 +19,8 @@ export default class AlbumsManager extends Manager {
* @param {string} ids The IDs of the albums
* * @returns {Promise<Album[]>} Returns a promise with a {@link Album}s.
*/
async list(ids: number[]): Promise<statsfm.Album[]> {
const res = await this.http.get<ItemsResponse<statsfm.Album[]>>(`/albums/list`, {
async list(ids: number[]): Promise<statsfm.v1.Album[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Album[]>>(`/albums/list`, {
query: {
ids: ids.join(',')
}
Expand All @@ -29,8 +29,8 @@ export default class AlbumsManager extends Manager {
return res.items;
}

async getSpotify(id: string): Promise<statsfm.Album> {
const res = await this.http.get<ItemResponse<statsfm.Album>>(`/albums/${id}`, {
async getSpotify(id: string): Promise<statsfm.v1.Album> {
const res = await this.http.get<ItemResponse<statsfm.v1.Album>>(`/albums/${id}`, {
query: {
type: 'spotify'
}
Expand All @@ -39,8 +39,8 @@ export default class AlbumsManager extends Manager {
return res.item;
}

async listSpotify(ids: string[]): Promise<statsfm.Album[]> {
const res = await this.http.get<ItemsResponse<statsfm.Album[]>>(`/albums/list`, {
async listSpotify(ids: string[]): Promise<statsfm.v1.Album[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Album[]>>(`/albums/list`, {
query: {
ids: ids.join(','),
type: 'spotify'
Expand All @@ -55,8 +55,8 @@ export default class AlbumsManager extends Manager {
* @param {number} id The IDs of the album.
* @returns {Promise<Track[]>} Returns a promise with a {@link Track[]}s.
*/
async tracks(id: number): Promise<statsfm.Track[]> {
const res = await this.http.get<ItemsResponse<statsfm.Track[]>>(`/albums/${id}/tracks`);
async tracks(id: number): Promise<statsfm.v1.Track[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Track[]>>(`/albums/${id}/tracks`);

return res.items;
}
Expand Down
36 changes: 18 additions & 18 deletions src/lib/artists/ArtistsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default class ArtistsManager extends Manager {
* @param {number} id The ID of the artist.
* @returns {Promise<Artist>} Returns a promise with a single {@link Artist}.
*/
async get(id: number): Promise<statsfm.Artist> {
const res = await this.http.get<ItemResponse<statsfm.Artist>>(`/artists/${id}`);
async get(id: number): Promise<statsfm.v1.Artist> {
const res = await this.http.get<ItemResponse<statsfm.v1.Artist>>(`/artists/${id}`);

return res.item;
}
Expand All @@ -19,8 +19,8 @@ export default class ArtistsManager extends Manager {
* @param {number} ids The IDs of the track.
* @returns {Promise<Artist[]>} Returns a promise with a {@link Artist}s.
*/
async list(ids: number[]): Promise<statsfm.Artist[]> {
const res = await this.http.get<ItemsResponse<statsfm.Artist[]>>(`/artists/list`, {
async list(ids: number[]): Promise<statsfm.v1.Artist[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Artist[]>>(`/artists/list`, {
query: {
ids: ids.join(',')
}
Expand All @@ -29,8 +29,8 @@ export default class ArtistsManager extends Manager {
return res.items;
}

async getSpotify(id: string): Promise<statsfm.Artist> {
const res = await this.http.get<ItemResponse<statsfm.Artist>>(`/artists/${id}`, {
async getSpotify(id: string): Promise<statsfm.v1.Artist> {
const res = await this.http.get<ItemResponse<statsfm.v1.Artist>>(`/artists/${id}`, {
query: {
type: 'spotify'
}
Expand All @@ -39,8 +39,8 @@ export default class ArtistsManager extends Manager {
return res.item;
}

async listSpotify(ids: string[]): Promise<statsfm.Artist[]> {
const res = await this.http.get<ItemsResponse<statsfm.Artist[]>>(`/artists/list`, {
async listSpotify(ids: string[]): Promise<statsfm.v1.Artist[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Artist[]>>(`/artists/list`, {
query: {
ids: ids.join(','),
type: 'spotify'
Expand All @@ -55,32 +55,32 @@ export default class ArtistsManager extends Manager {
* @param {number} id The IDs of the artist.
* @returns {Promise<Track[]>} Returns a promise with a {@link Track[]}s.
*/
async tracks(id: number): Promise<statsfm.Track[]> {
const res = await this.http.get<ItemsResponse<statsfm.Track[]>>(`/artists/${id}/tracks`);
async tracks(id: number): Promise<statsfm.v1.Track[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Track[]>>(`/artists/${id}/tracks`);

return res.items;
}

async topTracks(id: number): Promise<statsfm.Track[]> {
const res = await this.http.get<ItemsResponse<statsfm.Track[]>>(`/artists/${id}/tracks/top`);
async topTracks(id: number): Promise<statsfm.v1.Track[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Track[]>>(`/artists/${id}/tracks/top`);

return res.items;
}

async albums(id: number): Promise<statsfm.Album[]> {
const res = await this.http.get<ItemsResponse<statsfm.Album[]>>(`/artists/${id}/albums`);
async albums(id: number): Promise<statsfm.v1.Album[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Album[]>>(`/artists/${id}/albums`);

return res.items;
}

async topAlbums(id: number): Promise<statsfm.Album[]> {
const res = await this.http.get<ItemsResponse<statsfm.Album[]>>(`/artists/${id}/albums/top`);
async topAlbums(id: number): Promise<statsfm.v1.Album[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Album[]>>(`/artists/${id}/albums/top`);

return res.items;
}

async related(id: number): Promise<statsfm.Artist[]> {
const res = await this.http.get<ItemsResponse<statsfm.Artist[]>>(`/artists/${id}/related`);
async related(id: number): Promise<statsfm.v1.Artist[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Artist[]>>(`/artists/${id}/related`);

return res.items;
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib/charts/ChartsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as statsfm from '../../interfaces/statsfm';
import Manager from '../Manager';

export default class ChartsManager extends Manager {
async topTracks(options?: statsfm.QueryWithRange): Promise<statsfm.TopTrack[]> {
const res = await this.http.get<ItemsResponse<statsfm.TopTrack[]>>(`/charts/top/tracks`, {
async topTracks(options?: statsfm.QueryWithRange): Promise<statsfm.v1.TopTrack[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.TopTrack[]>>(`/charts/top/tracks`, {
query: {
...options
}
Expand All @@ -13,8 +13,8 @@ export default class ChartsManager extends Manager {
return res.items;
}

async topArtists(options?: statsfm.QueryWithRange): Promise<statsfm.TopArtist[]> {
const res = await this.http.get<ItemsResponse<statsfm.TopArtist[]>>(`/charts/top/artists`, {
async topArtists(options?: statsfm.QueryWithRange): Promise<statsfm.v1.TopArtist[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.TopArtist[]>>(`/charts/top/artists`, {
query: {
...options
}
Expand All @@ -23,8 +23,8 @@ export default class ChartsManager extends Manager {
return res.items;
}

async topAlbums(options?: statsfm.QueryWithRange): Promise<statsfm.TopAlbum[]> {
const res = await this.http.get<ItemsResponse<statsfm.TopAlbum[]>>(`/charts/top/albums`, {
async topAlbums(options?: statsfm.QueryWithRange): Promise<statsfm.v1.TopAlbum[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.TopAlbum[]>>(`/charts/top/albums`, {
query: {
...options
}
Expand Down
12 changes: 6 additions & 6 deletions src/lib/genres/GenresManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import * as statsfm from '../../interfaces/statsfm';
import Manager from '../Manager';

export default class GenresManager extends Manager {
async get(tag: string): Promise<statsfm.Genre> {
const res = await this.http.get<ItemResponse<statsfm.Genre>>(`/genres/${tag}`);
async get(tag: string): Promise<statsfm.v1.Genre> {
const res = await this.http.get<ItemResponse<statsfm.v1.Genre>>(`/genres/${tag}`);

return res.item;
}

async list(tags: string[]): Promise<statsfm.Genre[]> {
const res = await this.http.get<ItemsResponse<statsfm.Genre[]>>(`/genres`, {
async list(tags: string[]): Promise<statsfm.v1.Genre[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Genre[]>>(`/genres`, {
query: {
ids: tags.join(',')
}
Expand All @@ -19,8 +19,8 @@ export default class GenresManager extends Manager {
return res.items;
}

async artists(id: string): Promise<statsfm.Artist[]> {
const res = await this.http.get<ItemsResponse<statsfm.Artist[]>>(`/genres/${id}/artists`);
async artists(id: string): Promise<statsfm.v1.Artist[]> {
const res = await this.http.get<ItemsResponse<statsfm.v1.Artist[]>>(`/genres/${id}/artists`);

return res.items;
}
Expand Down
10 changes: 6 additions & 4 deletions src/lib/imports/ImportManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Track } from '../../interfaces';
import Manager from '../Manager';
import * as statsfm from '../../interfaces/statsfm';

export default class ChartsManager extends Manager {
changeMatch(streamId: string): Promise<Track[]> {
return this.http.get<Track[]>(`/imports/am/change-match/${streamId}`, { authRequired: true });
export default class ImportManager extends Manager {
changeMatch(streamId: string): Promise<statsfm.v1.Track[]> {
return this.http.get<statsfm.v1.Track[]>(`/imports/am/change-match/${streamId}`, {
authRequired: true
});
}

setNewMatch(streamId: string, newMatch: string): Promise<boolean> {
Expand Down
Loading

0 comments on commit cd0e869

Please sign in to comment.