feat: chalk, formatting, minor fixes

This commit is contained in:
Mateusz Pstrucha committed 2021-10-20 02:21:03 +02:00
1 parent 650b261f3a
commit 289c865e8d
6 files changed
+117 -16

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
# radio-rolnik Player
## Resources
https://github.com/Maathias/radio-rolnik/
https://github.com/Maathias/radio-rolnik-api/
## Requirements
- shell
- VLC
- python3
- python
- dotenv
- vlc
- pafy
- youtube_dl
## .env
### General
```ini
DOMAIN=https://radio.rolniknysa.pl/api
SECRET=<server api secret>
VOLUME_DEFAULT=100
```
+1 -1
View File
@@ -4,7 +4,7 @@ class Track {
this.tid = tid
this.ytid = id
this.title = title
this.duration = duration
this.duration = duration + 2e3
}
}
+26 -9
View File
@@ -1,4 +1,5 @@
import dotenv from 'dotenv'
import chalk from 'chalk'
import { player, queueCommand } from './modules/playback.js'
import { getTop, updateNext, updateStatus } from './modules/calls.js'
@@ -24,10 +25,11 @@ function sToHM(seconds) {
return [h, m]
}
console.info(`_______________________________`)
console.info(`Fetching playlist data`)
getTop()
.then((data) => {
.then(async (data) => {
console.info(`Parsing playlist`)
let schedule = durations.map(() => [])
@@ -59,12 +61,9 @@ getTop()
for (let nthPrzerwa in seconds) {
let [begin, end] = seconds[nthPrzerwa]
// skip przerwa if it already passed
if (begin < currentSeconds) continue
var tracktotal = 0
console.info(`Przerwa #${nthPrzerwa}`)
console.info(chalk.green(`\nPrzerwa #${nthPrzerwa}`))
schedule[nthPrzerwa].forEach((track, i) => {
tracktotal += (schedule[nthPrzerwa][i - 1]?.duration ?? 0) / 1e3
@@ -73,19 +72,36 @@ getTop()
let [h, m] = sToHM(currentSeconds + sched)
console.info(`scheduling ${track.tid} @ ${h}:${m} in ${sched}s`)
console.info(
`scheduling ${track.tid} @ ${chalk.red(`${h}:${m}`)} in ${sched}s`
)
console.info(
` (${chalk.cyan((track.duration / 60e3).toFixed(1))}) [${chalk.blue(
track.title.slice(0, 50)
)}]`
)
if (sched < 0) return
setTimeout(() => {
console.info(
`playing ${track.tid} (${track.ytid}) [${track.duration}] ${track.title}`
`${chalk.magenta(`${h}:${m}`)} playing ${track.tid} (${track.ytid})`
)
console.info(
`(${chalk.cyan((track.duration / 60e3).toFixed(1))}) ${chalk.blue(
track.title.slice(0, 50)
)} `
)
play(track)
updateNext(schedule[nthPrzerwa][i + 1]?.tid ?? null)
}, sched * 1e3)
})
setTimeout(() => {
console.info(`Beginning of #${nthPrzerwa} approaching`)
console.info(`Beginning of #${nthPrzerwa} in 10s`)
}, (begin - currentSeconds) * 1e3 - 10e3)
let endin = end - currentSeconds,
@@ -95,10 +111,11 @@ getTop()
setTimeout(() => {
console.info(`Ending playback for #${nthPrzerwa}`)
player.fadeOut(10)
player.fadeOut(6)
updateStatus(null, null, null, true)
}, endin * 1e3)
}
console.info(`Track scheduling done`)
console.info(`‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾`)
})
+43
View File
@@ -54,6 +54,14 @@
"@types/node": "*"
}
},
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"requires": {
"color-convert": "^2.0.1"
}
},
"cacheable-lookup": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz",
@@ -73,6 +81,15 @@
"responselike": "^2.0.0"
}
},
"chalk": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
"requires": {
"ansi-styles": "^4.1.0",
"supports-color": "^7.1.0"
}
},
"clone-response": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.2.tgz",
@@ -81,6 +98,19 @@
"mimic-response": "^1.0.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"decompress-response": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz",
@@ -140,6 +170,11 @@
"responselike": "^2.0.0"
}
},
"has-flag": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
},
"http-cache-semantics": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz",
@@ -227,6 +262,14 @@
"lowercase-keys": "^2.0.0"
}
},
"supports-color": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
"requires": {
"has-flag": "^4.0.0"
}
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
+1
View File
@@ -18,6 +18,7 @@
},
"homepage": "https://github.com/Maathias/radio-rolnik-player#readme",
"dependencies": {
"chalk": "^4.1.2",
"dotenv": "^10.0.0",
"got": "^11.8.2",
"ky": "^0.28.5"
+18 -6
View File
@@ -1,14 +1,26 @@
export default [
[
[19, 57],
[19, 58],
[10, 35],
[10, 50],
],
[
[19, 53],
[19, 54],
[9, 40],
[9, 50],
],
[
[13, 20],
[13, 21],
[8, 45],
[8, 55],
],
[
[11, 35],
[11, 45],
],
[
[12, 30],
[12, 40],
],
[
[13, 25],
[13, 30],
],
]