Skip to content

Commit

Permalink
add jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
thoriqazzikraa committed May 31, 2024
1 parent da5d531 commit bb38b6f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
## Usage

```js
// CommonJS
const {
getOriginalUrl,
search,
Expand All @@ -21,6 +22,20 @@ const {
} = require("@nechlophomeriaa/spotifydl")
```

```js
// ESM
import {
getOriginalUrl,
search,
downloads,
downloads2,
downloadAlbum,
downloadAlbum2,
downloadTrack,
downloadTrack2
} from "@nechlophomeriaa/spotifydl"
```

## Search Function

```js
Expand Down
40 changes: 40 additions & 0 deletions dist/cjs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ async function getOriginalUrl(url) {
return data.url
}

/**
* Downloader function version 2
* @param { String } url
* @returns { Promise }
*/
async function downloads2(url) {
if (!isUrl(url)) throw new Error("Please input URL")
if (url.includes("spotify.link")) {
Expand All @@ -41,6 +46,11 @@ async function downloads2(url) {
}
}

/**
* Downloader function version 1
* @param { String } url
* @returns { Promise }
*/
async function downloads(url) {
if (!isUrl(url)) throw new Error("Please input Url")
if (url.includes("spotify.link")) {
Expand Down Expand Up @@ -79,13 +89,25 @@ async function downloads(url) {
}
}

/**
* Search track in spotify api
* @param { String } query
* @param { Number } limit
* @returns { Promise }
*/
async function search(query, limit) {
if (isUrl(query)) throw new Error("Search function not support for url")
const limits = limit ? limit : 1
const data = await spotify.search({ q: query, type: "track", limit: limits })
return data.tracks
}

/**
* Function for downloader album or playlist using url version 2
* With metadata
* @param { String } url
* @returns { Promise }
*/
async function downloadAlbum2(url) {
let result = {}
if (!isUrl(url)) throw new Error("Please input an url")
Expand Down Expand Up @@ -132,6 +154,12 @@ async function downloadAlbum2(url) {
}
}

/**
* Function for downloader album or playlist using url version 1
* With metadata
* @param { String } url
* @returns { Promise }
*/
async function downloadAlbum(url) {
let result = { type: null, metadata: {}, trackList: [] }
if (!isUrl(url)) throw new Error("Input Url")
Expand Down Expand Up @@ -182,6 +210,12 @@ async function downloadAlbum(url) {
}
}

/**
* Function for downloading track using query or url version 2
* With metadata
* @param { String } song
* @returns { Promise }
*/
async function downloadTrack2(song) {
let result = {}
if (isUrl(song)) {
Expand Down Expand Up @@ -261,6 +295,12 @@ async function downloadTrack2(song) {
}
}

/**
* Function for downloading track using query or url version 1
* With metadata
* @param { String } song
* @returns { Promise }
*/
async function downloadTrack(song) {
let result = {}
if (isUrl(song)) {
Expand Down
40 changes: 40 additions & 0 deletions dist/esm/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ async function getOriginalUrl(url) {
return data.url
}

/**
* Downloader function version 2
* @param { String } url
* @returns { Promise }
*/
async function downloads2(url) {
if (!isUrl(url)) throw new Error("Please input URL")
if (url.includes("spotify.link")) {
Expand All @@ -41,6 +46,11 @@ async function downloads2(url) {
}
}

/**
* Downloader function version 1
* @param { String } url
* @returns { Promise }
*/
async function downloads(url) {
if (!isUrl(url)) throw new Error("Please input Url")
if (url.includes("spotify.link")) {
Expand Down Expand Up @@ -79,13 +89,25 @@ async function downloads(url) {
}
}

/**
* Search track in spotify api
* @param { String } query
* @param { Number } limit
* @returns { Promise }
*/
async function search(query, limit) {
if (isUrl(query)) throw new Error("Search function not support for url")
const limits = limit ? limit : 1
const data = await spotify.search({ q: query, type: "track", limit: limits })
return data.tracks
}

/**
* Function for downloader album or playlist using url version 2
* With metadata
* @param { String } url
* @returns { Promise }
*/
async function downloadAlbum2(url) {
let result = {}
if (!isUrl(url)) throw new Error("Please input an url")
Expand Down Expand Up @@ -132,6 +154,12 @@ async function downloadAlbum2(url) {
}
}

/**
* Function for downloader album or playlist using url version 1
* With metadata
* @param { String } url
* @returns { Promise }
*/
async function downloadAlbum(url) {
let result = { type: null, metadata: {}, trackList: [] }
if (!isUrl(url)) throw new Error("Input Url")
Expand Down Expand Up @@ -182,6 +210,12 @@ async function downloadAlbum(url) {
}
}

/**
* Function for downloading track using query or url version 2
* With metadata
* @param { String } song
* @returns { Promise }
*/
async function downloadTrack2(song) {
let result = {}
if (isUrl(song)) {
Expand Down Expand Up @@ -261,6 +295,12 @@ async function downloadTrack2(song) {
}
}

/**
* Function for downloading track using query or url version 1
* With metadata
* @param { String } song
* @returns { Promise }
*/
async function downloadTrack(song) {
let result = {}
if (isUrl(song)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"name": "@nechlophomeriaa/spotifydl",
"description": "Simple Scraper Spotify Track/Album/Playlist Downloader with Metadata",
"version": "1.0.14",
"version": "1.0.15",
"main": "./dist/cjs/index.js",
"type": "commonjs",
"exports": {
Expand Down

0 comments on commit bb38b6f

Please sign in to comment.