+
+function parseDate (dateAsStr: string): Date {
+ if (!/\d{4}-\d{2}-\d{2}/.test(dateAsStr)) {
+ exitError(`Invalid date passed: ${dateAsStr}. Expected format: YYYY-MM-DD. See help for usage.`)
+ }
+ const date = new Date(dateAsStr)
+ date.setHours(0, 0, 0)
+ if (isNaN(date.getTime())) {
+ exitError(`Invalid date passed: ${dateAsStr}. See help for usage.`)
+ }
+ return date
+}
+
+function formatDate (date: Date): string {
+ return date.toISOString().split('T')[0]
+}
+
+function convertIntoMs (secondsAsStr: string): number {
+ const seconds = parseInt(secondsAsStr, 10)
+ if (seconds <= 0) {
+ exitError(`Invalid duration passed: ${seconds}. Expected duration to be strictly positive and in seconds`)
+ }
+ return Math.round(seconds * 1000)
+}
+
+function exitError (message: string, ...meta: any[]) {
+ // use console.error instead of log.error here
+ console.error(message, ...meta)
+ process.exit(-1)
+}
+
+function getYoutubeDLInfo (youtubeDL: any, url: string, args: string[]) {
+ return new Promise<any>((res, rej) => {
+ const options = [ '-j', '--flat-playlist', '--playlist-reverse', ...args ]
+
+ youtubeDL.getInfo(url, options, processOptions, async (err, info) => {
+ if (err) return rej(err)
+
+ return res(info)
+ })
+ })
+}