From cb5f63fa4455cf5c57ac233ba2025830fd629404 Mon Sep 17 00:00:00 2001 From: Mateusz Pstrucha Date: Tue, 19 Apr 2022 20:25:43 +0200 Subject: [PATCH] fix: --rolling --- index.js | 21 ++++++++++++++++----- src/standalone.js | 11 +++++++---- src/web.js | 4 +++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index f8b14d7..9bc6f59 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,14 @@ import yargs from 'yargs' +import { readFileSync } from 'fs' +import web from './src/web.js' import cache from './src/cache.js' import schedule from './src/schedule.js' import standalone from './src/standalone.js' import test from './src/test.js' import words, { one } from './src/words.js' -import { logTrack } from './src/modules/log.js' +import { logAction, logTrack } from './src/modules/log.js' import { convert } from './src/modules/youtube.js' // Check Node version @@ -54,6 +56,10 @@ const args = yargs(process.argv.slice(2)) type: 'array', default: [], }) + .option('playlist', { + alias: 'p', + type: 'string', + }) .option('artists', { alias: 'a', type: 'array', @@ -64,13 +70,13 @@ const args = yargs(process.argv.slice(2)) switch (args._[0]) { default: - console.log('Defaulting to Web module') + console.log('Defaulting to standalone') + case 'standalone': + standalone({ rolling: args.r }) + break case 'web': web() break - case 'standalone': - standalone() - break case 'lyrics': if (args.T || args.t.length > 0 || args.a.length > 0) { let tid = args.T, @@ -101,4 +107,9 @@ switch (args._[0]) { break case 'test': test() + case 'playlist': + logAction('Reading playlist', args.p) + const tids = JSON.parse(readFileSync(`./${args.p}.json`)) + standalone({ tids }) + break } diff --git a/src/standalone.js b/src/standalone.js index cf82751..210f056 100644 --- a/src/standalone.js +++ b/src/standalone.js @@ -7,15 +7,18 @@ import { parse, cache, scheduler } from './modules/parse.js' import { logAction, logSchedule, logTrack, logValue } from './modules/log.js' import { local } from './modules/playback.js' -export default async function standalone() { +export default async function standalone({ tids, rolling } = {}) { logValue('Volume', defaultVolume) logValue('Offset', offset) logValue('Verbose', verbose) logValue('Limit', process.env.LIMIT) + console.log(rolling) + const _tids = (tids ?? (await getTop(rolling ? 'rolling' : 'once'))).slice( + 0, + limit + ) // tids - const { schedule, tracks, ends } = await getTop() // tids - .then((tids) => tids.slice(0, limit)) - .then(convert) // Tracks + const { schedule, tracks, ends } = await convert(_tids) // Tracks .then(parse) // chart .then(cache) .then(scheduler) // schedule diff --git a/src/web.js b/src/web.js index 18e086e..5e1fd20 100644 --- a/src/web.js +++ b/src/web.js @@ -1 +1,3 @@ -export default function web() {} +export default function web() { + console.log('to be implemented') +}