New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nocopyrightsounds-api

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nocopyrightsounds-api - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

.github/.gitkeep

4

dist/cjs/main.d.ts

@@ -1,2 +0,2 @@

import Song from './classes/song'
export declare const getSongs: (page: number) => Promise<Song[]>
export * from './modules/musiclist'
export * from './modules/search'
'use strict'
Object.defineProperty(exports, '__esModule', { value: true })
exports.getSongs = void 0
var node_fetch_1 = require('node-fetch')
var node_html_parser_1 = require('node-html-parser')
var artist_1 = require('./classes/artist')
var song_1 = require('./classes/song')
var getSongs = function (page) {
return new Promise(function (resolve, reject) {
node_fetch_1
.default('https://ncs.io/music?page=' + (page ? page : 1))
.then(function (res) {
return res.text()
})
.then(function (html) {
var root = node_html_parser_1.parse(html)
var songsHtml = root.querySelectorAll('div.col-lg-2.item')
var songs = songsHtml.map(function (song) {
var _a
var link = song.querySelector('a[href]').getAttribute('href')
var imageUrl =
(_a = song
.querySelector('div.img[style]')
.getAttribute('style')) === null || _a === void 0
? void 0
: _a.split("'")[1]
var name = song.querySelector('.bottom p strong').innerHTML
var optionsEl = song.querySelector('div.options')
var date = optionsEl.querySelector('p[title]').getAttribute('title')
var genre = optionsEl.querySelector('strong').innerHTML
var songLinkEl = optionsEl.querySelector('a.btn.black.player-play')
var songUrl = songLinkEl.getAttribute('data-url')
var artistsEl = songLinkEl.getAttribute('data-artist')
if (!artistsEl || !name || !date || !link || !imageUrl || !songUrl)
return new song_1.default('', '', '', [], '', '', '')
var artists =
artistsEl === null || artistsEl === void 0
? void 0
: artistsEl.split(', ').map(function (art) {
var artEl = node_html_parser_1.parse(art)
var url = artEl.getAttribute('href')
var name = artEl.innerHTML
if (!url) return new artist_1.default(name, '')
else return new artist_1.default(name, url)
})
return new song_1.default(
name,
date,
genre,
artists,
link,
imageUrl,
songUrl
)
var __createBinding =
(this && this.__createBinding) ||
(Object.create
? function (o, m, k, k2) {
if (k2 === undefined) k2 = k
Object.defineProperty(o, k2, {
enumerable: true,
get: function () {
return m[k]
}
})
resolve(songs)
}
: function (o, m, k, k2) {
if (k2 === undefined) k2 = k
o[k2] = m[k]
})
.catch(function (err) {
reject(err)
})
})
}
exports.getSongs = getSongs
var __exportStar =
(this && this.__exportStar) ||
function (m, exports) {
for (var p in m)
if (p !== 'default' && !Object.prototype.hasOwnProperty.call(exports, p))
__createBinding(exports, m, p)
}
Object.defineProperty(exports, '__esModule', { value: true })
__exportStar(require('./modules/musiclist'), exports)
__exportStar(require('./modules/search'), exports)

@@ -1,2 +0,2 @@

import Song from './classes/song'
export declare const getSongs: (page: number) => Promise<Song[]>
export * from './modules/musiclist'
export * from './modules/search'

@@ -1,50 +0,2 @@

import fetch from 'node-fetch'
import { parse as parseHTML } from 'node-html-parser'
import Artist from './classes/artist'
import Song from './classes/song'
export var getSongs = function (page) {
return new Promise(function (resolve, reject) {
fetch('https://ncs.io/music?page=' + (page ? page : 1))
.then(function (res) {
return res.text()
})
.then(function (html) {
var root = parseHTML(html)
var songsHtml = root.querySelectorAll('div.col-lg-2.item')
var songs = songsHtml.map(function (song) {
var _a
var link = song.querySelector('a[href]').getAttribute('href')
var imageUrl =
(_a = song
.querySelector('div.img[style]')
.getAttribute('style')) === null || _a === void 0
? void 0
: _a.split("'")[1]
var name = song.querySelector('.bottom p strong').innerHTML
var optionsEl = song.querySelector('div.options')
var date = optionsEl.querySelector('p[title]').getAttribute('title')
var genre = optionsEl.querySelector('strong').innerHTML
var songLinkEl = optionsEl.querySelector('a.btn.black.player-play')
var songUrl = songLinkEl.getAttribute('data-url')
var artistsEl = songLinkEl.getAttribute('data-artist')
if (!artistsEl || !name || !date || !link || !imageUrl || !songUrl)
return new Song('', '', '', [], '', '', '')
var artists =
artistsEl === null || artistsEl === void 0
? void 0
: artistsEl.split(', ').map(function (art) {
var artEl = parseHTML(art)
var url = artEl.getAttribute('href')
var name = artEl.innerHTML
if (!url) return new Artist(name, '')
else return new Artist(name, url)
})
return new Song(name, date, genre, artists, link, imageUrl, songUrl)
})
resolve(songs)
})
.catch(function (err) {
reject(err)
})
})
}
export * from './modules/musiclist'
export * from './modules/search'
{
"name": "nocopyrightsounds-api",
"version": "1.0.2",
"version": "1.0.3",
"description": "A webscraper for the NoCopyrightSounds website to provide an API",

@@ -16,3 +16,4 @@ "main": "dist/cjs/main.js",

"prepublishOnly": "npm run build && npm run prettier && npm version patch",
"prettier": "prettier --write ."
"prettier": "prettier --write .",
"test": "tsc -p tests/tsconfig.test.json && node tests/dist/tests/main.test.js"
},

@@ -19,0 +20,0 @@ "keywords": [],

# NoCopyrightSounds API
This is a webscraper designed to provide an api like access to the NCS website
## Features
- List
- Search
## import
```js
//module (reccomended)
import * as ncs from 'nocopyrightsounds-api'
//CommonJS
const ncs = require('nocopyrightsounds-api')
```
## examples
### get all songs from the first page in the music library
```js
import * as ncs from 'nocopyrightsounds-api'
ncs
.getMusic(/*page here*/)
.then(songs => {
//use the songs here
console.log(songs)
})
.catch(err => {
//error handeling here
console.error(err)
})
```
### get all songs from the first page of house songs
```js
import * as ncs from 'nocopyrightsounds-api'
ncs
.search(
{
genre: 10
} /*page here*/
)
.then(songs => {
//use the songs here
console.log(songs)
})
.catch(err => {
//error handeling here
console.error(err)
})
```
### download the newest song
```js
import * as ncs from 'nocopyrightsounds-api'
import * as fs from 'fs'
import https from 'https'
ncs
.getMusic()
.then(async songs => {
const newest = songs[0]
const directUrl = newest.songUrl
const writeStream = fs.createWriteStream(`${newest.name}.mp3`)
https.get(directUrl, res => {
res.pipe(writeStream)
})
})
.catch(err => {
//just simple error handeling
console.error(err)
})
```

@@ -1,50 +0,2 @@

import fetch from 'node-fetch'
import { parse as parseHTML } from 'node-html-parser'
import type { HTMLElement } from 'node-html-parser'
import Artist from './classes/artist'
import Song from './classes/song'
export const getSongs = (page: number): Promise<Song[]> => {
return new Promise<Song[]>((resolve, reject) => {
fetch(`https://ncs.io/music?page=${page ? page : 1}`)
.then((res) => {
return res.text()
})
.then((html) => {
const root = parseHTML(html)
const songsHtml = root.querySelectorAll('div.col-lg-2.item')
const songs: Song[] = songsHtml.map((song: HTMLElement) => {
const link = song.querySelector('a[href]').getAttribute('href')
const imageUrl = song
.querySelector('div.img[style]')
.getAttribute('style')
?.split("'")[1]
const name = song.querySelector('.bottom p strong').innerHTML
const optionsEl = song.querySelector('div.options')
const date = optionsEl.querySelector('p[title]').getAttribute('title')
const genre = optionsEl.querySelector('strong').innerHTML
const songLinkEl = optionsEl.querySelector('a.btn.black.player-play')
const songUrl = songLinkEl.getAttribute('data-url')
const artistsEl = songLinkEl.getAttribute('data-artist')
if (!artistsEl || !name || !date || !link || !imageUrl || !songUrl)
return new Song('', '', '', [], '', '', '')
const artists: Artist[] = artistsEl
?.split(', ')
.map((art: string) => {
const artEl = parseHTML(art)
const url = artEl.getAttribute('href')
const name = artEl.innerHTML
if (!url) return new Artist(name, '')
else return new Artist(name, url)
})
return new Song(name, date, genre, artists, link, imageUrl, songUrl)
})
resolve(songs)
})
.catch((err) => {
reject(err)
})
})
}
export * from './modules/musiclist'
export * from './modules/search'

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc