url-song-utilities

1.0.2 • Public • Published

Welcome to url-song-utilities 👋

A module to get information about music titles and even be able to download them !

🏓 Installation

npm i url-song-utilities

✨ Utilisation

Available methods :

#Search a music
<module>.searchSong('<song>')

#Find the type of an url
<module>.sourceUrl('<URL>')

#Search for music lyrics
<module>.getLyrics('<song>')

#Download a music with a YouTube url
<module>.download('<URL>')

#Changing the url of a YouTube video
<module>.toPlayableLink('<YouTube URL>')

Examples :

  • For the following examples we will define player as follows :
const player = require('url-song-utilities');
  • Search a music
//The bot will try to get information about the music
await player.searchSong('PETIT BISCUIT - Sunset Lover').then(song => {
    //It returns the information to the console
    console.log(song);
}).catch(err => {
    //If the module did not find the music it returns a error
    console.log('No music found !');
})
  • Find the type of an url (we will use a YouTube URL for the example)
//The bot will try to find the source of the provided url (YouTube or Spotify)
await player.sourceUrl('https://youtu.be/k2qgadSvNyU').then(data => {
    //If the module returns 'undefined', the source is not found
    if (!data) return console.log('Cannot determine the source !');
    //If the module finds the source
    console.log(data);
})
  • Search for music lyrics
//The bot will try to find the lyrics of the music
await player.getLyrics('Luis Fonsi - Despacito').then(lyrics => {
    //If the module returns 'undefined' it means that the module did not find any lyrics
    if (!lyrics) return console.log('I did not find any lyrics !');
    //If the module finds lyrics
    console.log(lyrics);
})
  • Download a music with a URL
//The bot will need the fs module function to save the file
const { createWriteStream } = require("fs");
//The bot will search for the music
await player.download('https://youtu.be/nceqQyqIa5o').then(stream => {
    //The bot will record the music under './song.mp3'
    //You can use other formats such as (mp3, mp4...)
    stream.pipe(createWriteStream('song.mp3'));
})
  • Changing the url of a YouTube video
//The bot will try to transform the music
await player.toPlayableLink('https://youtu.be/ZMqhjKRUGsY').then(url => {
    //If the module returns 'undefined', it means that the module did not find the music
    if (!url) return console.log('No music found !');
    //If the module succeeded in generating a link
    console.log(url);
})
  • Result of a search (example : TROLLZ - 6ix9ine with Nicki Minaj)
{
  title: 'TROLLZ - 6ix9ine with Nicki Minaj (Official Lyric Video)',
  id: '-wts5viH28E',
  url: 'https://www.youtube.com/watch?v=-wts5viH28E',
  channel: {
    name: 'Tekashi 6ix9ine',
    url: 'https://www.youtube.com/channel/UCF6jRAgCbSanHolKt0Vt6Qw'
  },
  thumbnail: 'https://i.ytimg.com/vi/-wts5viH28E/hqdefault.jpg?sqp=-oaymwEjCNACELwBSFryq4qpAxUIARUAAAAAGAElAADIQj0AgKJDeAE=&rs=AOn4CLDDvxmF9oWa7wca5PXqcYcDvJi-_w',
  duration: 204,
  source: 'YouTube'
}

🎉 Bonus

  • Download event
//The bot will need the fs module function to save the file
const { createWriteStream } = require("fs");
//The bot will search for the music
await player.download('https://youtu.be/nceqQyqIa5o').then(stream => {
    //The bot will record the music under './song.mp3'
    //You can use other formats such as (mp3, mp4...)
    stream.pipe(createWriteStream('song.mp3')).on('finish', () => {
        //When the file will be downloaded the bot will send back a message
        console.log('Music downloaded !');
    })
})
  • Search and download
//The bot will need the fs module function to save the file
const { createWriteStream } = require("fs");
//The bot will search for the music (on Spotify for example)
await player.searchSong('https://open.spotify.com/track/22LAwLoDA5b4AaGSkg6bKW').then(async song => {
    await player.download(song.url).then(stream => {
        //The bot will download the file with the name it has found
        stream.pipe(createWriteStream(song.title + '.mp3'));
    })
}).catch(err => {
    //If the module did not find the music it returns a error
    return console.log('No music found !');
})
  • Changing the url of a YouTube video (example : EJS)

Why use the toPlayableLink() function ? This function transforms a YouTube link into a Google Drive link, which can be read in sites such as (HTML, EJS...). Without using this function it will be impossible to play the requested video directly with the YouTube link.

<!-- const player = require('url-song-utilities'); -->
<!-- var data = await player.searchSong('HUGEL feat. Amber Van Day - Mamma Mia (Official Video)'); -->
<!-- var stream = await player.toPlayableLink(data.url); -->
 
<figure>
    <figcaption>You are currently listening to : <%= data.title %></figcaption>
    <audio controls src="<%= stream %>">
        Your browser does not support the <code>audio</code> element.
    </audio>
</figure>

👤 Developers

This project was designed by Zerio & Simon.

🤝 Contributing

Contributions, issues and feature requests are welcome !
Feel free to check issues page.

📝 License

Copyright © 2020 Zerio & Simon.

Give a ⭐️ (on the Github project) if this project helped you !

Package Sidebar

Install

npm i url-song-utilities

Weekly Downloads

5

Version

1.0.2

License

ISC

Unpacked Size

48.3 kB

Total Files

6

Last publish

Collaborators

  • zerioshow
  • simon_leclere