Skip to content

Commit

Permalink
add lyrics 2
Browse files Browse the repository at this point in the history
  • Loading branch information
thoriqazzikraa committed Mar 16, 2024
1 parent 0444b0d commit 303c127
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const scrape = require("scrape-websitee")
similarSongs, // (query)
findSongs, // (query)
lyrics, // (query)
lyrics2, // (query)
similarBand, // (query)
igStalk, // (username)
igStalk2, // (username)
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrape-websitee",
"version": "1.0.67",
"version": "1.0.68",
"description": "Website Scraping",
"main": "index.js",
"scripts": {
Expand All @@ -26,7 +26,7 @@
"dependencies": {
"axios": "^1.4.0",
"cheerio": "^1.0.0-rc.12",
"file-type-cjs-fix": "^1.1.1",
"file-type": "16.5.3",
"form-data": "^4.0.0",
"fs": "^0.0.1-security",
"node-fetch": "2.6.6",
Expand Down
29 changes: 29 additions & 0 deletions src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,34 @@ async function findSongs(text) {
}
}

async function lyrics2(query) {
let result = {}
try {
const suggestSongs = async () => {
const { data } = await axios.get(`https://search.azlyrics.com/suggest.php?q=${query}`)
return data
}
const thisSongs = await suggestSongs(query)
const datazlr = await fetch(thisSongs.songs[0].url).then((a) => a.text())
const htmlText = datazlr
const indexOfComment = htmlText.indexOf("Usage of azlyrics.com content by any third-party lyrics provider is prohibited by our licensing agreement. Sorry about that.")
const startIndex = htmlText.lastIndexOf("<div", indexOfComment)
const endIndex = htmlText.indexOf("</div>", indexOfComment) + 6
const lyrics = htmlText
.substring(startIndex, endIndex)
.replace(/<!--[^>]*-->/g, "")
.replace(/<br>/g, "")
.replace(/<\/?div[^>]*>/g, "")
.replace(/<\/?i[^>]*>/g, "")
.trim()
result.title = thisSongs.songs[0].autocomplete
result.lyrics = lyrics
return result
} catch (err) {
return String(err)
}
}

async function lyrics(query) {
let result = {}
try {
Expand Down Expand Up @@ -345,6 +373,7 @@ module.exports = {
similarSongs,
findSongs,
lyrics,
lyrics2,
similarBand,
igStalk,
igStalk2,
Expand Down
2 changes: 1 addition & 1 deletion src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const axios = require("axios")
const fetch = require("node-fetch")
const fs = require("fs")
const formData = require("form-data")
const { fromBuffer } = require("file-type-cjs-fix")
const { fromBuffer } = require("file-type")

async function uploadFile(buffer) {
const { ext, mime } = await fromBuffer(buffer)
Expand Down

0 comments on commit 303c127

Please sign in to comment.