Added colors in verbose

This commit is contained in:
dbroqua 2019-12-19 10:29:17 +01:00
parent f5e9f696b8
commit 8b64b70be4
3 changed files with 38 additions and 12 deletions

View file

@ -5,5 +5,32 @@ module.exports = {
mastondonApi: process.env.mastondonApi || 'https://mamot.fr/api/v1/', mastondonApi: process.env.mastondonApi || 'https://mamot.fr/api/v1/',
discogsToken: process.env.discogsToken, discogsToken: process.env.discogsToken,
delay: process.env.delay || 4000, delay: process.env.delay || 4000,
rx3List: ['Rx3', 'REAL REBEL RADIO', 'REAL REBEL RADIO homemade'] rx3List: ['Rx3', 'REAL REBEL RADIO', 'REAL REBEL RADIO homemade'],
colors: {
Reset: '\x1b[0m',
Bright: '\x1b[1m',
Dim: '\x1b[2m',
Underscore: '\x1b[4m',
Blink: '\x1b[5m',
Reverse: '\x1b[7m',
Hidden: '\x1b[8m',
FgBlack: '\x1b[30m',
FgRed: '\x1b[31m',
FgGreen: '\x1b[32m',
FgYellow: '\x1b[33m',
FgBlue: '\x1b[34m',
FgMagenta: '\x1b[35m',
FgCyan: '\x1b[36m',
FgWhite: '\x1b[37m',
BgBlack: '\x1b[40m',
BgRed: '\x1b[41m',
BgGreen: '\x1b[42m',
BgYellow: '\x1b[43m',
BgBlue: '\x1b[44m',
BgMagenta: '\x1b[45m',
BgCyan: '\x1b[46m',
BgWhite: '\x1b[47m'
}
} }

View file

@ -9,7 +9,7 @@ setInterval(() => {
// On récupére en base le précédent morceau joué // On récupére en base le précédent morceau joué
libs.getLastSong((err, last) => { libs.getLastSong((err, last) => {
if (err) { if (err) {
console.log('[ERR] GET LAST SONG:', moment().format(), err) console.log(config.colors.FgRed, '[ERR] GET LAST SONG:', moment().format(), err, config.colors.Reset)
return false return false
} }
@ -20,14 +20,14 @@ setInterval(() => {
// On sauvegarde en base le morceau en cours de diffusion // On sauvegarde en base le morceau en cours de diffusion
libs.saveSong(currentSong, (err, savedSond) => { libs.saveSong(currentSong, (err, savedSond) => {
if (err) { if (err) {
console.log('[ERR] SAVE SONG:', moment().format(), err) console.log(config.colors.FgRed, '[ERR] SAVE SONG:', moment().format(), err, config.colors.Reset)
return false return false
} }
// On récupère la cover du morceau actuel // On récupère la cover du morceau actuel
libs.findCover(currentSong, (err, coverUrl) => { libs.findCover(currentSong, (err, coverUrl) => {
if (err) { if (err) {
console.log('[ERR] FIND COVER:', moment().format(), err) console.log(config.colors.FgRed, '[ERR] FIND COVER:', moment().format(), err, config.colors.Reset)
return false return false
} }

15
libs.js
View file

@ -32,7 +32,7 @@ const saveSong = (values, callback) => {
last.length === 0 || last.length === 0 ||
(last[0] !== undefined && last[0].id !== values.id) (last[0] !== undefined && last[0].id !== values.id)
) { ) {
console.log('[INFO][saveSong] song not found:', values.title, values.artist) console.log(config.colors.FgBlue, '[INFO][saveSong] song not found:', values.title, values.artist, config.colors.Reset)
const history = new mongo.Histories(values) const history = new mongo.Histories(values)
history.save(callback) history.save(callback)
@ -73,7 +73,7 @@ const getRemoteCover = (song, callback) => {
dis.search({ q: song.album, artist: song.artist, page: 1, per_page: 1 }, (err, res) => { dis.search({ q: song.album, artist: song.artist, page: 1, per_page: 1 }, (err, res) => {
if (err) { if (err) {
console.log('ERR:', err) console.log(config.colors.FgRed, 'ERR:', err, config.colors.Reset)
callback(err) callback(err)
return false return false
} }
@ -82,7 +82,7 @@ const getRemoteCover = (song, callback) => {
if (res.results && res.results.length === 1) { if (res.results && res.results.length === 1) {
callback(null, res.results[0].cover_image) callback(null, res.results[0].cover_image)
} else { } else {
console.log('[INFO] No cover found for:', song.album, song.artist) console.log(config.colors.FgBlue, '[INFO] No cover found for:', song.album, song.artist, config.colors.Reset)
callback(null, null) callback(null, null)
} }
}) })
@ -115,7 +115,7 @@ const findCover = (song, callback) => {
if (metadata) { if (metadata) {
// On a déjà une pochette pour ce morceau // On a déjà une pochette pour ce morceau
if (metadata.cover) { if (metadata.cover) {
console.log('[INFO][findCover] cover exists:', metadata.cover) console.log(config.colors.FgBlue, '[INFO][findCover] cover exists:', metadata.cover, config.colors.Reset)
callback(null, metadata.cover) callback(null, metadata.cover)
return true return true
@ -127,7 +127,7 @@ const findCover = (song, callback) => {
callback(err) callback(err)
return false return false
} }
console.log('[INFO][findCover] cover does not exists but found on discogs:', coverUrl) console.log(config.colors.FgBlue, '[INFO][findCover] cover does not exists but found on discogs:', coverUrl, config.colors.Reset)
metadata.updateOne({ cover: coverUrl }) metadata.updateOne({ cover: coverUrl })
callback(null, coverUrl) callback(null, coverUrl)
}) })
@ -137,7 +137,7 @@ const findCover = (song, callback) => {
callback(err) callback(err)
return false return false
} }
console.log('[INFO][findCover] cover does not exists but found on discogs (2):', coverUrl) console.log(config.colors.FgBlue, '[INFO][findCover] cover does not exists but found on discogs (2):', coverUrl, config.colors.Reset)
song.cover = coverUrl song.cover = coverUrl
const metadata = new mongo.Metadata(song) const metadata = new mongo.Metadata(song)
@ -170,7 +170,6 @@ const getStream = (callback) => {
} }
if (res !== null && res.artist !== undefined && res.title !== undefined) { if (res !== null && res.artist !== undefined && res.title !== undefined) {
console.log('[INFO][getStream] CURRENT SONG:', res.title, res.artist)
callback(null, res) callback(null, res)
} else { } else {
error = true error = true
@ -205,7 +204,7 @@ const getMedia = (coverUrl, callback) => {
callback(null, dest) callback(null, dest)
}) })
.on('error', (error) => { .on('error', (error) => {
console.log('ERR:', error) console.log(config.colors.FgRed, 'ERR:', error, config.colors.Reset)
callback(error) callback(error)
}) })
} }