-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
executable file
·53 lines (42 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
/*
This program makes a web scraping to get some guitar tablature and transform
it to an Arduino Program compatible with the tone() Function
Git-repository: https://github.com/ThiagoAugustoSM/arduino-tablature
Author: thiagoaugustosm
License: MIT
*/
const request = require('request');
const fs = require('fs');
const args = require('yargs').argv;
const makeFile = require('./src/baseFile.js');
const tablature = require('./src/tablature.js');
const scraper = require('./src/scraper.js');
var mkdirp = require('mkdirp');
mkdirp('music', function (err) {
if (err) console.error(err);
else console.log('dir music created with success');
});
var url;
if(args.url != undefined){
url = args.url;
console.log('requesting from:' + args.url);
// Request to get the html from cifraclub's website
request(url, function(error, response, html){
if(!error){
var song = scraper.getSong(url, html);
var tabInNotes = song.tabs.map(tab => tablature.filterTab(tab, song.capo));
var arduinoFile = makeFile.generateFile(tabInNotes);
// Saving file in the same directory
fs.writeFile('music/music.ino', arduinoFile, function (err) {
if (err) throw err;
console.log('Saved!');
});
}else{
console.log("ERROR");
}
});
}
else{
console.log('You must pass a url in a param, example: --url=https://www.cifraclub.com.br/natiruts/andei-so/');
}