Last active
July 28, 2019 06:59
-
-
Save abhijitparida/a5266cdc29e631b81b8635f94d20de9c to your computer and use it in GitHub Desktop.
YouTube Offline Mixtape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const { spawnSync} = require('child_process'); | |
const fs = require('fs'); | |
console.log('Fetching playlist metadata...'); | |
spawnSync('youtube-dl.exe', [ | |
'https://www.youtube.com/playlist?list=LL3Hn4qVmdoFwdI2FEyw_JlA', | |
'--playlist-end', '100', | |
'--ignore-errors', | |
'--skip-download', | |
'--write-info-json' | |
]); | |
console.log('\nDownloading...'); | |
fs.readdirSync('.') | |
.filter(file => file.endsWith('.info.json')) | |
.map(file => ({ | |
...JSON.parse(fs.readFileSync(file)), | |
info_file_name: file | |
})) | |
.filter(video => video.categories && video.categories.includes('Music')) | |
.forEach((video, i, videos) => { | |
console.log(`[${i+1}/${videos.length}] ${video.title}`); | |
const { stderr } = spawnSync('youtube-dl.exe', [ | |
'--load-info-json', `${video.info_file_name}`, | |
'--format', '140[filesize<10M]', | |
'--download-archive', '%temp%/offline-mixtape.txt' | |
]); | |
const err = stderr ? stderr.toString().trim() : null; | |
if (err) console.log(err); | |
}); | |
console.log('\nCleaning Up...'); | |
fs.readdirSync('.') | |
.filter(file => file.endsWith('.info.json')) | |
.forEach(file => fs.unlinkSync(file)); | |
console.log('\nDone'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment