From 58652578063094e101e47e20bbd9f1b381e7483d Mon Sep 17 00:00:00 2001 From: przemyslawpluta Date: Wed, 13 Jan 2016 21:23:28 +0000 Subject: download subtitles only --- README.md | 1 + lib/videos.js | 21 ++++++++++++++++++++- package.json | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5a051b1..b423d28 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Videos: --cwd same as --cw and dumps list of videos to file in -d --co arrange video files in correct order of the courseware --cc get closed captions + --cco get only closed captions without downloading videos --hq get high quality videos Handouts: diff --git a/lib/videos.js b/lib/videos.js index 9c90f92..0fe77b4 100644 --- a/lib/videos.js +++ b/lib/videos.js @@ -22,7 +22,7 @@ var path = require('path'), getYouTubeID = require('get-youtube-id'); var isDebug = /[debug]/, downloadPath = '', proxy = '', downloadList = [], hash = {}, - co = false, ncc = false, handout = false, cc = false, uz = false, hq = false, verbose = false, retry = 10, maxRetry; + co = false, ncc = false, handout = false, cc = false, uz = false, hq = false, verbose = false, retry = 10, cco = false, maxRetry; function setOptions(argv) { @@ -38,6 +38,10 @@ function setOptions(argv) { if (argv.co) { co = true; } if (argv.retry) { retry = argv.retry; } if (argv.verbose) { verbose = true; } + if (argv.cco) { + cc = true; + cco = true; + } } function rename(downloadPath, item, id, count, pass) { @@ -70,6 +74,8 @@ var handleList = function handleList(list, tags) { if (proxy) { opt = opt.concat(['--proxy', proxy]); } + if (cco) { opt = opt.concat(['--skip-download']); } + var getHandouts = function getHandouts(item) { var name = path.basename(item), bar, dounloadFile, dlh, left, extname, unzipFile, progressSoFar = -1, hold = 0, @@ -167,6 +173,8 @@ var handleList = function handleList(list, tags) { if (handout) { return getHandouts(item); } + if (cco) { return getSubtitlesOnly(item); } + var downloaded = 0, size = 0, stash = {}, bar; if (fs.existsSync(downloadPath + hash[item])) { @@ -226,6 +234,17 @@ var handleList = function handleList(list, tags) { }); }, + getSubtitlesOnly = function getSubtitlesOnly(item) { + + youtubedl.getInfo(item, [], function getInfo(err, info) { + if (err) { console.log('i'.red + ' Get Info Failed: '.red + err.stack); } + if (info) { console.log('i'.magenta + ' Downloading Subtitles: ' + info._filename.cyan + ' > ' + item); } + var left = (currentList.length) ? currentList.length + ' left ...' : ''; + getSubtitles(item, left, currentList, tags); + }); + + }, + delay = function delay(target) { setTimeout(function timeout() { getVideos(target); }, 5000); }; diff --git a/package.json b/package.json index c1dc09f..972ad06 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "filesize": "~3.1.5", "get-youtube-id": "~1.0.0", "glob": "~6.0.3", - "inquirer": "~0.11.1", + "inquirer": "~0.11.2", "lodash": "~3.10.1", "mkdirp": "~0.5.1", "moment": "~2.11.1", -- cgit v1.2.3