README

# YoutubeMusic

This guide explains how to use the YoutubeMusic class provided by the YoutubeMusic.js library to interact with the YouTube Music API.

# Importing the Class

// Importing the class - TypeScript ESNext
import { YoutubeMusic } from "youtubemusic.js";

# Creating an Instance

Create an instance of the YoutubeMusic class to use its methods:

const instance = new YoutubeMusic();

# Usage

# Searching for a Song

You can search for a song using the search method. It takes two parameters: the search query and the type of search (e.g., playlists, tracks). Here's an example of how to search for the song "True Faith":

import { Search } from "youtubemusic.js";

instance.search("True Faith", Search.Tracks).then((searchResponse) => {
  console.log(searchResponse);
});

In this example, Search.Playlists specifies that you want to search in playlists. You can change it to Search.Tracks or other search types based on your requirement.

Query Parameter Description Default Required
query Search Query Track True
[
  {
    title: "True Faith",
    id: "qCNbdYd9K30",
    duration: "5:56",
    artists: [[Object]],
    album: "Substance",
    thumbnail:
      "https://lh3.googleusercontent.com/h3IDPP-9fRzJ9JuahhPYCgH92QV4DJjIk6N5K3fY8yTR58EhfX55Z0v77NvHkY_7PL7AF2PlVvA-Gfw=w800-h800-s-l90-rj",
  },
  {
    title: "True Faith",
    id: "AxUbccX4NW4",
    duration: "4:13",
    artists: [[Object]],
    album: "Singles",
    thumbnail:
      "https://lh3.googleusercontent.com/eGHqnFdxMIp7aeEyAvpHpzoJtjjkjYA5cMHRiQvHIFo6fAAnTLskPm07_6E6Kys5iRK8WavUe28voxTK=w800-h800-l90-rj",
  },
  {
    title: "True Faith",
    id: "girKHerKXUg",
    duration: "4:42",
    artists: [[Object]],
    album: "Stolen",
    thumbnail:
      "https://lh3.googleusercontent.com/-CxLMRVEAyM_2Dzp-dKKuQDtksf2DZRFOIza6eUrJXkpAI93Ev08ciJMIbS7cwTED0xI50pj9wqKTfc=w800-h800-l90-rj",
  },
  {
    title: "True Faith (2011 Total Version)",
    id: "fGrb7abRVHw",
    duration: "4:13",
    artists: [[Object]],
    album: "Total: From Joy Division to New Order",
    thumbnail:
      "https://lh3.googleusercontent.com/3D_gMByrI7yW_uEkH6GUSUjKYGGAkXOTqkrIB3ZOb7qVZTGwit3Yt5el8gN004-61hRqnED-o5I2LzVe=w800-h800-s-l90-rj",
  },
  {
    title: "True Faith (The Morning Sun Extended Remix)",
    id: "bz7pGEmwWQ0",
    duration: "9:02",
    artists: [[Object]],
    album: "Best Remixes",
    thumbnail:
      "https://lh3.googleusercontent.com/NZkyE00ndZCJ0NcB1i35bjeOSEjREmtLCHrt0e_kldeRWk0eIFabw4dT5sfZnXxHZ6CqAysue1EkprQX=w800-h800-l90-rj",
  },
  {
    title: "True Faith (Inspired by Lotte Kestner's Cover)",
    id: "NWdOh0Rc4jQ",
    duration: "4:20",
    artists: [],
    album: "The Last of Us Part II: Covers and Rarities",
    thumbnail:
      "https://lh3.googleusercontent.com/tQVho6fCkASpSOmLAIrXlh_t-9lUl7AXxN8EpmHljBiALBgLF39AnCBnsShCYtQ6Vzdkv4d_fTQFDqE=w800-h800-l90-rj",
  },
  {
    title: "Paano Ka Magiging Akin",
    id: "2HKLx7aPEp0",
    duration: "4:46",
    artists: [[Object]],
    album: "Paano Ka Magiging Akin",
    thumbnail:
      "https://lh3.googleusercontent.com/WPJgCKkAv4YCE618zgIwCdOtCvNfvOGhfewBpOS6Essydoi3w8tf5tu5nQzJ1G2m2LpmMalab_TIAp4=w800-h800-l90-rj",
  },
  {
    title: "True Faith (New Version - US)",
    id: "_yAUQURIor0",
    duration: "5:53",
    artists: [[Object]],
    album: "Bright Lights, Big City (Original Motion Picture Soundtrack)",
    thumbnail:
      "https://lh3.googleusercontent.com/oXwUb7ZbXaaS-oUmEmHuR-JTKjV_dO8Zeq8t-fPr7DtOcGzdqyFCx9SqgNoWo0wY3Z477VqzS_2cZQUgHg=w800-h800-l90-rj",
  },
  {
    title: "Sayang Ang Lahat",
    id: "D-HqVOPzLkg",
    duration: "4:30",
    artists: [[Object]],
    album: "Stray to Be Found",
    thumbnail:
      "https://lh3.googleusercontent.com/q4slvknjGg1LN1vTitciy6yndlr-hikBJGEbUuhZ6ECZ1e6ads7RRXcYdvFxc3H9RHE-9HEPPih2jWyjbQ=w800-h800-l90-rj",
  },
  {
    title: 'True Faith (Shep Pettibone 12" Remix)',
    id: "YKy0TXGN2lM",
    duration: "9:04",
    artists: [[Object]],
    album: "Brotherhood (Collector's Edition)",
    thumbnail:
      "https://lh3.googleusercontent.com/vrCGZM6ryt7TFnbrCgflTkfQ3pqPbDcegKq61RmSVVEW0S2HxrNNgOyI9zHSpsFYsOqi9HdeloKJpjbh=w800-h800-l90-rj",
  },
  {
    title: "Ambon",
    id: "q7d4gXkMaEI",
    duration: "4:22",
    artists: [[Object]],
    album: "Dream Journal",
    thumbnail:
      "https://lh3.googleusercontent.com/VN6lhhQ6dpUSNQwRbPMah4z-hdqTLr-luytIuBreTOYSJDCcTIBNz58pjXZ8Mk60fFuGuN4is0A81gk9=w800-h800-l90-rj",
  },
  {
    title: "True Faith",
    id: "vxw54qWWZx4",
    duration: "6:59",
    artists: [[Object]],
    album: "Live at Bestival 2012",
    thumbnail:
      "https://lh3.googleusercontent.com/THauOwwJPvldu2pEDTMsU6K_QHoKJxaz7MSBnl7CCRH45gBDm3XzqcNYuPp3g8vvl_Br38pIAnSZkvTi=w800-h800-l90-rj",
  },
  {
    title: "Perfect",
    id: "diyh8kjIbxA",
    duration: "4:23",
    artists: [[Object]],
    album: "Dream Journal",
    thumbnail:
      "https://lh3.googleusercontent.com/VN6lhhQ6dpUSNQwRbPMah4z-hdqTLr-luytIuBreTOYSJDCcTIBNz58pjXZ8Mk60fFuGuN4is0A81gk9=w800-h800-l90-rj",
  },
  {
    title: "Dahil Ikaw",
    id: "Df9r6oL3icQ",
    duration: "4:53",
    artists: [[Object]],
    album: "Pinoy Biggie Hits",
    thumbnail:
      "https://lh3.googleusercontent.com/WugVWiRJn9g0AU0Aiaut4C7xyUz52pRBZ-EP0EQrdUip25hO7Lk4HmxSdqPWS44r_k6A6b4ZE5hlzyqp=w800-h800-l90-rj",
  },
  {
    title: "Baliw",
    id: "QukEyt7BXjM",
    duration: "4:19",
    artists: [[Object]],
    album: "Eto Hits... Acoustic",
    thumbnail:
      "https://lh3.googleusercontent.com/2oM8rp0uPYFSR2YXeUrHcyiO2c49tKpSDEOweVT0QeanDIBv4p5rUX6rHJJc-KizSTooRSDAn3txq9ki=w800-h800-l90-rj",
  },
  {
    title: "True Faith",
    id: "7b-hOj8IrTI",
    duration: "4:14",
    artists: [[Object]],
    album: "In Dreams",
    thumbnail:
      "https://lh3.googleusercontent.com/YM0Zujho91Cm8c0bN3PoBqT-9fcfZpITL1m4Dj5V_87ULgK_U04Q7D0CsYF1SmqoAKHvpeLiaj8CqXU=w800-h800-l90-rj",
  },
  {
    title: "True Faith (BBC Session)",
    id: "lD3uSTDA7Ws",
    duration: "5:03",
    artists: [[Object]],
    album: "True Faith (BBC Session)",
    thumbnail:
      "https://lh3.googleusercontent.com/HzlsR2g0NROpJvThNcNc5bspiyqi2HBlYLE6SpnekH-Pgd5hbLFQMNH_Ltwgu59GhpHCW3Q_Iyvnyaj1=w800-h800-l90-rj",
  },
  {
    title: "Sumasarap Ang Gising",
    id: "XdWkNHG53rk",
    duration: "3:12",
    artists: [[Object]],
    album: "Dream Journal",
    thumbnail:
      "https://lh3.googleusercontent.com/VN6lhhQ6dpUSNQwRbPMah4z-hdqTLr-luytIuBreTOYSJDCcTIBNz58pjXZ8Mk60fFuGuN4is0A81gk9=w800-h800-l90-rj",
  },
  {
    title: "True Faith - Inspired by Lotte Kestner's cover",
    id: "hVQi0_jv0h8",
    duration: "5:17",
    artists: [[Object]],
    album: "Survivor (A Luiza Caspary's story)",
    thumbnail:
      "https://lh3.googleusercontent.com/nLdEad2Hb7lvueMeV0ZMTBdZQzv7FB7MnH_NZ8KsSi_ZkZdITLnqFjbTaLxDbNKf6FWgHhwoJK5_5T8=w800-h800-l90-rj",
  },
  {
    title: "True Faith",
    id: "QFgOSgcJ9rA",
    duration: "4:33",
    artists: [[Object]],
    album: "True Faith",
    thumbnail:
      "https://lh3.googleusercontent.com/WUq9JHhhcA0rDleKlRNn03AVu960-raN9Ty5vIvpSGbPfMLd-GPJy4jsoc2eJfBaih-iUS9vCtY9QXC_=w800-h800-l90-rj",
  },
];

# Getting Information about a Song

To retrieve information about a specific song, use the get method. Provide the video ID of the song and specify the type of information you want (e.g., track details). Here's an example:

import { Get } from "youtubemusic.js";

instance.get("qCNbdYd9K30", Get.Track).then((trackResponse) => {
  console.log(trackResponse);
});

In this example, "qCNbdYd9K30" is the video ID of the song. Change Get.Track to other options like Get.Playlist if you want information about a playlist.

Query Parameter Description Default Required
id The id of the track Track True
{
  title: 'True Faith',
  description: 'Provided to YouTube by Rhino\n' +
    '\n' +
    'True Faith · New Order\n' +
    '\n' +
    'Substance\n' +
    '\n' +
    '℗ 1987 Warner Music UK Ltd\n' +
    '\n' +
    'Guitar, Keyboards, Programmer, Synthesizer, Vocals: Bernard Sumner\n' +
    'Producer: Bernard Sumner\n' +
    'Guitar, Keyboards, Programmer, Synthesizer: Gillian Gilbert\n' +
    'Producer: Gillian Gilbert\n' +
    'Bass  Guitar: Peter Hook\n' +
    'Keyboards, Programmer, Synthesizer: Peter Hook\n' +
    'Producer: Peter Hook\n' +
    'Producer: Stephen Hague\n' +
    'Drums, Keyboards, Programmer, Synthesizer: Stephen Morris\n' +
    'Producer: Stephen Morris\n' +
    'Writer: Bernard Sumner\n' +
    'Writer: Gillian Gilbert\n' +
    'Writer: Peter Hook\n' +
    'Writer: Stephen Hague\n' +
    'Writer: Stephen Morris\n' +
    '\n' +
    'Auto-generated by YouTube.',
  keywords: [ 'New Order', 'Substance', 'True Faith' ],
  videoId: 'qCNbdYd9K30',
  author: { name: 'New Order - Topic', id: 'UCXExK7We8VKsIzFFQYNEgBg' },
  thumbnail: [
    {
      url: 'https://i.ytimg.com/vi/qCNbdYd9K30/hqdefault.jpg?sqp=-oaymwEiCKgBEF5IWvKriqkDFQgBFQAAAAAYASUAAMhCPQCAokN4AQ==&rs=AOn4CLCQYXZe5jKO2Q2Eh7amZWJyDKTwGw',
      width: 168,
      height: 94
    },
    {
      url: 'https://i.ytimg.com/vi/qCNbdYd9K30/hqdefault.jpg?sqp=-oaymwEiCMQBEG5IWvKriqkDFQgBFQAAAAAYASUAAMhCPQCAokN4AQ==&rs=AOn4CLCLuXEYAziDv5RlMakxREz5UeDxBA',
      width: 196,
      height: 110
    },
    {
      url: 'https://i.ytimg.com/vi/qCNbdYd9K30/hqdefault.jpg?sqp=-oaymwEjCPYBEIoBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLBPjt4kUNmGaQqQ48BZzaxbbEIIvQ',
      width: 246,
      height: 138
    },
    {
      url: 'https://i.ytimg.com/vi/qCNbdYd9K30/hqdefault.jpg?sqp=-oaymwEjCNACELwBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLDYnzkkZ2iEqZPbh794S6qUsTrVNA',
      width: 336,
      height: 188
    },
    {
      url: 'https://i.ytimg.com/vi/qCNbdYd9K30/maxresdefault.jpg',
      width: 1920,
      height: 1080
    }
  ],
  views: { label: '4.1M', initial: '4066149' },
  duration: { label: '05:56', initial: '356' },
  date: { formatted: 'September 3, 2020', initial: '09/03/20' },
  embed: {
    iframeUrl: 'https://www.youtube.com/embed/qCNbdYd9K30',
    width: 960,
    height: 720
  },
  category: 'Music'
}

search
https://github.com/TrishCX/YoutubeMusic.js/blob/main/src/classes/YoutubeMusic.ts
get
https://github.com/TrishCX/YoutubeMusic.js/blob/main/src/classes/YoutubeMusic.ts