-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
FC5570
committed
Oct 1, 2022
1 parent
c285434
commit 2f8022e
Showing
11 changed files
with
200 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules/ | |
dist/ | ||
docs/ | ||
*.gz | ||
.env* | ||
.env* | ||
tests/index.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { Base } from '.'; | ||
import type { Client } from '../'; | ||
import type { APIAudiobook } from '../types'; | ||
|
||
export class Audiobook extends Base { | ||
/** | ||
* The Spotify ID for the audiobook. | ||
*/ | ||
public id!: string; | ||
|
||
/** | ||
* The name of the audiobook. | ||
*/ | ||
public name!: string; | ||
|
||
/** | ||
* A description of the audiobook. HTML tags are stripped away from this field, use html_description field in case HTML tags are needed. | ||
*/ | ||
public description!: string; | ||
|
||
/** | ||
* A description of the audiobook. This field may contain HTML tags. | ||
*/ | ||
public html_description!: string; | ||
|
||
/** | ||
* A link to the Web API endpoint providing full details of the audiobook. | ||
*/ | ||
public href!: string; | ||
|
||
/** | ||
* Whether or not the audiobook has explicit content (true = yes it does; false = no it does not OR unknown). | ||
*/ | ||
public explicit!: boolean; | ||
|
||
/** | ||
* The author(s) for the audiobook. | ||
*/ | ||
public authors!: APIAudiobook['authors']; | ||
|
||
/** | ||
*A list of the languages used in the audiobook, identified by their ISO 639 code. | ||
*/ | ||
public languages!: string[]; | ||
|
||
/** | ||
* The media type of the audiobook. | ||
*/ | ||
public media_type!: string; | ||
|
||
/** | ||
* The cover art for the audiobook in various sizes, widest first. | ||
*/ | ||
public images!: APIAudiobook['images']; | ||
|
||
/** | ||
* External URLs for this audiobook. | ||
*/ | ||
public external_urls!: APIAudiobook['external_urls']; | ||
|
||
/** | ||
* The narrator(s) for the audiobook. | ||
*/ | ||
public narrators!: APIAudiobook['narrators']; | ||
|
||
/** | ||
* The copyright statements of the audiobook. | ||
*/ | ||
public copyrights!: APIAudiobook['copyrights']; | ||
|
||
/** | ||
* The publisher of the audiobook. | ||
*/ | ||
public publisher!: string; | ||
|
||
/** | ||
* The object type. | ||
*/ | ||
public type!: 'audiobook'; | ||
|
||
/** | ||
* The object type. | ||
*/ | ||
public uri!: string; | ||
|
||
/** | ||
* The number of chapters in this audiobook. | ||
*/ | ||
public total_chapters!: number; | ||
|
||
/** | ||
* The chapters of the audiobook. | ||
*/ | ||
public chapters!: APIAudiobook['chapters']; | ||
|
||
public constructor(client: Client, data: APIAudiobook) { | ||
super(client); | ||
Object.assign(this, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { APIImage } from '.'; | ||
|
||
export interface APIAudiobook { | ||
id: string; | ||
name: string; | ||
description: string; | ||
html_description: string; | ||
href: string; | ||
explicit: boolean; | ||
authors: { | ||
name: string; | ||
}[]; | ||
languages: string[]; | ||
media_type: string; | ||
images: APIImage[]; | ||
external_urls: { | ||
spotify: string; | ||
}; | ||
narrators: { | ||
name: string; | ||
}; | ||
copyrights: { | ||
text: string; | ||
type: 'C' | 'P'; | ||
}[]; | ||
publisher: string; | ||
type: 'audiobook'; | ||
uri: string; | ||
total_chapters: number; | ||
chapters: { | ||
href: string; | ||
items: Record<string, unknown>; | ||
limit: number; | ||
next: string; | ||
offset: number; | ||
previous: string; | ||
total: number; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { BaseManager } from '.'; | ||
import { SpotifyTSError, Audiobook, RequestData, type Client, type APIAudiobook } from '../lib'; | ||
|
||
export class AudiobooksManager extends BaseManager { | ||
public constructor(client: Client) { | ||
super(client, 'audiobooks'); | ||
} | ||
|
||
/** | ||
* Get Spotify catalog information for a single audiobook. | ||
* **Note: Audiobooks are only available for the US market.** | ||
* @param {string} id: The Spotify ID for the audiobook. | ||
* @param {string} [country]: The ISO 3166-1 alpha-2 country code. TIf specified, only the content available in this country will be returned, if not, the country of the current user will be used. | ||
* @returns {Promise<Audiobook>} The audiobook. | ||
**/ | ||
public async fetch(id: string, country?: string): Promise<Audiobook> { | ||
if (!id) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'AudiobooksManager', 'fetch', 'id'); | ||
if (typeof id !== 'string') throw new SpotifyTSError('MANAGER_ARGUMENT_INVALID_TYPE', 'AudiobooksManager', 'fetch', 'id', 'string'); | ||
|
||
const data = await super.get<APIAudiobook>(undefined, id, country ? new RequestData({ query: { market: country } }) : undefined); | ||
return new Audiobook(this.client, data); | ||
} | ||
|
||
/** | ||
* Fetch several audiobooks by their Spotify IDs. | ||
* @param {Array<string>} ids: The Spotify IDs of the audiobooks. | ||
* @param {string} [country]: An ISO 3166-1 alpha-2 country code, if specified, returns only the content available in this country. If this argument is not specified, the country code of the user account will be used. | ||
* @returns {Promise<Audiobook[]>} Array of Episode objects. | ||
*/ | ||
public async fetchSeveral(ids: string[], country?: string): Promise<Audiobook[]> { | ||
if (!ids || !ids?.length) throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'AudiobooksManager', 'fetch', 'ids'); | ||
if (!Array.isArray(ids)) throw new SpotifyTSError('MANAGER_ARGUMENT_INVALID_TYPE', 'AudiobooksManager', 'fetch', 'ids', 'Array<string>'); | ||
if (country && typeof country !== 'string') | ||
throw new SpotifyTSError('MANAGER_MISSING_ARGUMENT', 'AudiobooksManager', 'fetch', 'country', 'string'); | ||
|
||
const query = country | ||
? new RequestData({ query: { ids: ids.join(','), market: country } }) | ||
: new RequestData({ query: { ids: ids.join(',') } }); | ||
const { audiobooks } = await super.get<{ audiobooks: APIAudiobook[] }>(undefined, undefined, query); | ||
const parsed = []; | ||
for (const audiobook of audiobooks) parsed.push(new Audiobook(this.client, audiobook)); | ||
|
||
return parsed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters