Library Core / src
Module: src
Table of contents
Enumerations
Classes
- CatalogDatabase
- CatalogMapper
- Database
- LanguageMapper
- MediaCatalogMapper
- Publication
- PublicationMapper
Variables
Functions
- checkExists
- createDir
- downloadCatalog
- downloadFile
- downloadMediaCatalog
- downloadPublication
- downloadSongStream
- downloadVideoStream
- emptyDir
- getLanguageById
- getLanguages
- getMediaCatalog
- getSongStream
- getVideoStream
- isValidDate
- readLines
- updateCatalog
Variables
CATALOG_URL
• Const CATALOG_URL: "https://download-a.akamaihd.net/meps/jwl/current/catalogs/v3/catalog.db.gz"
The URL of the current catalog.
Defined in
MEDIA_CATALOGS_URL
• Const MEDIA_CATALOGS_URL: "https://app.jw-cdn.org/catalogs/media"
The URL of all the media catalogs.
These are NDJSON files that list images and other metadata used for media found within publications.
Defined in
MEDIA_URL
• Const MEDIA_URL: "https://api.hag27.com/GETPUBMEDIALINKS"
The URL used as for checking media options.
This returns a list of options of download qualities based on the passed in params.
Defined in
PUBLICATION_URL
• Const PUBLICATION_URL: "https://download-a.akamaihd.net"
The URL used as a base for downloading publications.
This is the site hosting most of the files.
Defined in
SONG_PUBLICATION
• Const SONG_PUBLICATION: Object
Params for the current songbook publication, without the track.
Used internally to provide methods which only require a track in order to retrieve a song.
Type declaration
| Name | Type |
|---|---|
doc |
"sjjm" |
issue |
0 |
type |
"pub" |
Defined in
Functions
checkExists
▸ checkExists(path): Promise<boolean>
Checks if a file exists.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
The path to the file. |
Returns
Promise<boolean>
true if the file exists, false if it does not.
Defined in
createDir
▸ createDir(dir): Promise<string | undefined>
Creates the specified directory. Will create parent directories if missing.
Parameters
| Name | Type | Description |
|---|---|---|
dir |
string |
The directory to create. |
Returns
Promise<string | undefined>
Defined in
downloadCatalog
▸ downloadCatalog(path): Promise<void>
Downloads the catalog & writes it to the specified path.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
The path to write the catalog file to. |
Returns
Promise<void>
Defined in
downloadFile
▸ downloadFile(url, path): Promise<void>
A helper function that downloads the requested URL and writes it to the specified path.
Parameters
| Name | Type | Description |
|---|---|---|
url |
string |
The URL of the file to download. |
path |
string |
The path to write the file to. |
Returns
Promise<void>
Defined in
downloadMediaCatalog
▸ downloadMediaCatalog(languageCode, path): Promise<void>
NOTE: You probably want to be using getMediaCatalog instead.
Downloads a Media Catalog & writes it to the specified path.
Parameters
| Name | Type | Description |
|---|---|---|
languageCode |
string |
- |
path |
string |
The path to write the catalog file to. |
Returns
Promise<void>
Defined in
downloadPublication
▸ downloadPublication(url, path): Promise<void>
NOTE: You probably want to be using getPublication in Database which does this for you.
Downloads a publication from a URL & extracts it to the specified directory path.
The resulting structure will be:
/path
/manifest.json
/contents
/(NameFragment).db
/(multiple .jpg files)
Parameters
| Name | Type | Description |
|---|---|---|
url |
string |
The publication URL. |
path |
string |
The path to write the catalog file to. This is usually the publication NameFragment. |
Returns
Promise<void>
Defined in
downloadSongStream
▸ downloadSongStream(track, path, languageId?): Promise<true | null>
Does the same as downloadVideoStream but only requires passing a song number.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
track |
number |
undefined |
The song number to use. |
path |
string |
undefined |
The path to write the song to. |
languageId |
number |
0 | The Meps Language Id to use. Defaults to 0 (English). |
Returns
Promise<true | null>
See downloadVideoStream.
Defined in
downloadVideoStream
▸ downloadVideoStream(videoArgs, path): Promise<true | null>
Does the same as getVideoStream but writes the stream to a file instead of returning the stream.
Parameters
| Name | Type | Description |
|---|---|---|
videoArgs |
Parameters<typeof getVideoStream>[0] |
- |
path |
string |
The path to write the video to. |
Returns
Promise<true | null>
true if the file was written successfully, null if the video could not be found.
Defined in
emptyDir
▸ emptyDir(dir): Promise<void>
Removes the entire specified directory, similar to rm -rf {dir}.
Parameters
| Name | Type | Description |
|---|---|---|
dir |
string |
The directory to remove. |
Returns
Promise<void>
Defined in
getLanguageById
▸ getLanguageById(id): LanguageDTO | null
Searches for the specified language based on the provided id.
Parameters
| Name | Type | Description |
|---|---|---|
id |
number |
The Meps Language Id to search for. |
Returns
LanguageDTO | null
The language if it was found, null if it does not exist.
Defined in
getLanguages
▸ getLanguages(): LanguageDTO[]
Retrieves a list of all languages currently supported.
Returns
An array of languages.
Defined in
getMediaCatalog
▸ getMediaCatalog(dir, languageId): Promise<MediaCatalog | null>
todo Check for latest version, currently just checks existence of file.
Retrieves a media catalog file and returns a {@link MediaCatalog} instance if it exists. Will download the file if it is not yet downloaded.
Parameters
| Name | Type | Description |
|---|---|---|
dir |
string |
The directory where media catalogs are to be stored. |
languageId |
number |
The Meps Language Id to use. |
Returns
Promise<MediaCatalog | null>
A {@link MediaCatalog} if it exists, null if not found.
Defined in
getSongStream
▸ getSongStream(track, languageId?): Promise<NodeJS.ReadableStream | null>
Does the same as getVideoStream but only requires passing a song number.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
track |
number |
undefined |
The song number to use. |
languageId |
number |
0 | The Meps Language Id to use. Defaults to 0 (English). |
Returns
Promise<NodeJS.ReadableStream | null>
See getVideoStream.
Defined in
getVideoStream
▸ getVideoStream(__namedParameters): Promise<NodeJS.ReadableStream | null>
Searches the external Media API endpoint for the requested video and retrieves the highest quality (720p) version of it.
Parameters
| Name | Type |
|---|---|
__namedParameters |
Object |
__namedParameters.doc |
string | number |
__namedParameters.issue |
string | number |
__namedParameters.languageId? |
number |
__namedParameters.track |
string | number |
__namedParameters.type |
VideoDTO["type"] |
Returns
Promise<NodeJS.ReadableStream | null>
A Stream of the video file or null if the video cannot be found.
Defined in
isValidDate
▸ isValidDate(date): date is string
Validates that the passed in date is a string of yyyy-mm-dd format.
Parameters
| Name | Type | Description |
|---|---|---|
date |
unknown |
The date to validate. |
Returns
date is string
true if the date is valid, false if not.
Defined in
readLines
▸ readLines(path, cb): Promise<void>
Reads a file line by line and allows running a callback for each line.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
The path to the file. |
cb |
(line: string) => void |
The callback to apply for each line. |
Returns
Promise<void>
Defined in
updateCatalog
▸ updateCatalog(path): Promise<boolean>
todo Check for latest version, currently just checks existence of file.
Checks whether the currently downloaded catalog is the latest version & updates it if not.
Parameters
| Name | Type | Description |
|---|---|---|
path |
string |
The path to download the catalog to. |
Returns
Promise<boolean>
true if the catalog was updated, false if it was already the latest version.