music-term
v1.0.2
Published
Music on terminal and VS Code Extension
Downloads
1
Readme
Musicterm
Music on terminal and VS Code Extension
Percobaan Menggunakan Puppeteer
cli app => puppeteer membuka youtube query => headless browser and play/next/stop
Fitur
- Mencari Lagu dengan keyword (FullText Search)
- Ads Block (Auto Block 90% berhasil)
- Play Next
- Stop
Cara Pakai :
- Install
npm i -g music-term
- Cari Lagu
mst -s <nama lagu>
Test :
- OSX 15
- Ubuntu 18
VSCODE Extension
- Coming Soon
Telaah
parsing argumen untuk pencarian
let args = process.argv;
let pointer_s = args.indexOf('-s');
let keyword = args.splice(pointer_s+1,args.length).join(' ');
Puppeteer buka browser headless lalu buka tab baru dan buka query pencarian youtube
const page = await browser.newPage();
await page.setViewport({width: 1200, height: 720});
await page.goto("https://www.youtube.com/results?search_query="+target, { waitUntil: 'networkidle0' });
page.click('ytd-thumbnail');
await page.waitForSelector('.title');
Hotkeys control untuk stop atau next lagu
keypress(process.stdin);
process.stdin.on('keypress', function (ch, key) {
switch (key.name) {
case "c":
console.log("Thank U...")
process.exit(-1);
break;
case "n":
page.click('.ytp-next-button').then(function() {
process.stdout.write('Loading...');
setTimeout(() => {
process.stdout.clearLine();
process.stdout.cursorTo(0);
page.title().then(title => process.stdout.write("🔊 Playing >> "+title));
}, 2000);
});
process.stdout.clearLine();
process.stdout.cursorTo(0);
break;
case "p":
if(isStop===false){
page.click('.ytp-play-button');
process.stdout.clearLine();
process.stdout.cursorTo(0);
process.stdout.write("Paused");
isStop=true;
}else{
isStop=false;
page.click('.ytp-play-button').then(
() => {
process.stdout.clearLine();
process.stdout.cursorTo(0);
page.title().then(title => process.stdout.write("Playing >> "+title));
}
);
}
break;
default:
break;
}
});
process.stdin.setRawMode(true);
process.stdin.resume();