Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MusicTrack

Hierarchy

  • MusicTrack

Index

Constructors

  • An object that represents a music track.

    example
    let Track = new MusicTrack();
    console.log(Track.url);
    console.log(Track.name);
    console.log(Track.duration);

    Parameters

    Returns MusicTrack

Properties

audio: Audio[]

Array of media urls. May be empty in the case that the service does not provide streaming.

authors: Author[]

An array of the authors of the music track. For example, a YouTube channel or SoundCloud user profile

duration: number

Duration of the track in seconds

durationTimestamp: string

Duration of the track in timestamp (e.g. 12:34)

live: boolean

Is the track live-streaming? (e.g. a YouTube livestream)

metadata: { explicit?: boolean; id?: string; queuedBy?: any; resolvedTo: false | Service }

An object containing additional metadata that may not always be included; e.g. the user that queued the track

Type declaration

  • Optional explicit?: boolean

    Is the track deemed as explicit?

  • Optional id?: string

    ID of the track on the platform (e.g. https://www.youtube.com/watch?v=dQw4w9WgXcQ --> dQw4w9WgXcQ)

  • Optional queuedBy?: any

    A reference to the user that queued the track - Can be set via MusicTrack.setQueuedBy or modified manually

  • resolvedTo: false | Service

    If the track wasn't streamable (e.g. Spotify), was the tracks audio replaced by an alternative source's track, and which service.

name: string

Name of the track

originalData?: any

Original data retreieved from request to service's API. For debug and if theres any data not included in MusicTrack itself thats needed.

playlisted: boolean

Has the track been playlisted?

service: Service

The service providing track (e.g. YouTube)

thumbnail: string

Thumbnail URL of the track

url: string

Friendly URL of the track (e.g. https://youtube.com/watch?v=videoid)

Methods

  • bestAudio(): Promise<Audio>
  • Returns the best audio format.

    Note: if SoundCloud is the service, Audio.url is changed to a time sensitive URL due to SoundCloud APIs.

    Note: if Spotify is the service, use resolveUnstreamableTrack() to try and find an alternative track on YouTube.

    Returns Promise<Audio>

  • fetchMissingAudio(): Promise<void>
  • Adds neccessary audio data to MusicTrack in the case it was not added.

    Returns Promise<void>

  • resolveUnstreamableTrack(): Promise<undefined | { query: string; result: MusicTrack }>
  • If the track is not streamable (e.g. Spotify), attempts to find a track on an alternative source and overwrites the current audio with the new audio. The tracks metadata.resolvedTo property value will also be replaced with the resolved service.

    example
    if (track.service === "spotify"){
    let { query } = await track.resolveUnstreamableTrack();
    console.log(query);
    console.log(await track.bestAudio());
    }

    Returns Promise<undefined | { query: string; result: MusicTrack }>

    Object containing the search query made (query) and found track (result) or undefined if couldn't find an alternative track

  • resource(seek?: number, extraArgs?: any[], audio?: Audio): Promise<FFmpeg>
  • Returns a Prism Media FFmpeg object.

    example
    const resource = await discordVoice.createAudioResource(Track.resource());

    Parameters

    • seek: number = 0

      Number of seconds to seek in the track. Obviously defaults to 0

    • Optional extraArgs: any[]

      An array of extra arguments to pass to Prism when creating the FFmpeg object. Basically just your standard FFmpeg arguments but in array form. For example:

      "-ar",
      "48000",
      "-ac",
      "2"
    • Optional audio: Audio

      Custom audio object to use instead of relying on {@link MusicTrack.bestAudio()}

    Returns Promise<FFmpeg>

Generated using TypeDoc