From 820b7940db2f1d533848f024fbb1d6f4841ce598 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 18 Feb 2018 19:31:30 -0400 Subject: Move downloadPlaylistFromOptionValue into general-util --- src/general-util.js | 23 +++++++++++++++++++++++ src/play.js | 21 ++++----------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/general-util.js b/src/general-util.js index 67f53e3..63ef1b2 100644 --- a/src/general-util.js +++ b/src/general-util.js @@ -1,3 +1,9 @@ +const { promisify } = require('util') +const fs = require('fs') +const fetch = require('node-fetch') + +const readFile = promisify(fs.readFile) + module.exports.showTrackProcessStatus = function( total, doneCount, noLineBreak = false ) { @@ -14,3 +20,20 @@ module.exports.showTrackProcessStatus = function( (noLineBreak ? '' : '\n') ) } + +function downloadPlaylistFromURL(url) { + return fetch(url).then(res => res.text()) +} + +function downloadPlaylistFromLocalPath(path) { + return readFile(path) +} + +module.exports.downloadPlaylistFromOptionValue = function(arg) { + // TODO: Verify things! + if (arg.startsWith('http://') || arg.startsWith('https://')) { + return downloadPlaylistFromURL(arg) + } else { + return downloadPlaylistFromLocalPath(arg) + } +} diff --git a/src/play.js b/src/play.js index d5df591..158c887 100755 --- a/src/play.js +++ b/src/play.js @@ -19,6 +19,10 @@ const { flattenGrouplike } = require('./playlist-utils') +const { + downloadPlaylistFromOptionValue +} = require('./general-util') + const { compileKeybindings, getComboForCommand, stringifyCombo } = require('./keybinder') @@ -26,23 +30,6 @@ const { const readFile = promisify(fs.readFile) const writeFile = promisify(fs.writeFile) -function downloadPlaylistFromURL(url) { - return fetch(url).then(res => res.text()) -} - -function downloadPlaylistFromLocalPath(path) { - return readFile(path) -} - -function downloadPlaylistFromOptionValue(arg) { - // TODO: Verify things! - if (arg.startsWith('http://') || arg.startsWith('https://')) { - return downloadPlaylistFromURL(arg) - } else { - return downloadPlaylistFromLocalPath(arg) - } -} - function clearConsoleLine() { process.stdout.write('\x1b[1K\r') } -- cgit 1.3.0-6-gf8a5