├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── cli.js ├── license ├── media ├── puf.png ├── pufetch.gif └── pufetch.png ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [{package.json,*.yml}] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | - '6' 5 | - '4' 6 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | const dns = require('dns'); 6 | const isUrl = require('is-url'); 7 | const got = require('got'); 8 | const ora = require('ora'); 9 | const jsonFile = require('jsonfile'); 10 | const chalk = require('chalk'); 11 | const cheerio = require('cheerio'); 12 | const logUpdate = require('log-update'); 13 | const updateNotifier = require('update-notifier'); 14 | const pkg = require('./package.json'); 15 | 16 | updateNotifier({pkg}).notify(); 17 | 18 | const spinner = ora(); 19 | const arg = process.argv[2]; 20 | const inf = process.argv[3]; 21 | const val = process.argv[4]; 22 | 23 | const setName = `${Math.random().toString(16).substr(10)}.json`; 24 | 25 | let rad = `${process.argv[5]}.json` || setName; 26 | 27 | if (rad === 'undefined.json') { 28 | rad = setName; 29 | } 30 | 31 | const log = console.log; 32 | const end = process.exit; 33 | const url = 'https://youtube.com/watch?v='; 34 | 35 | const checkConnection = () => { 36 | dns.lookup('youtube.com', err => { 37 | if (err) { 38 | logUpdate(`\n${chalk.red(' ✖ ')} ${chalk.dim('Please check your internet connection!')}\n`); 39 | end(1); 40 | } else { 41 | logUpdate(); 42 | spinner.text = 'Puffing...'; 43 | spinner.start(); 44 | } 45 | }); 46 | }; 47 | 48 | if (!arg || arg === '-h' || arg === '--help') { 49 | log(` 50 | ${chalk.keyword('orange')('⚡⚡')} ${chalk.blue('Youtube Playlist Link Fetcher')} ${chalk.keyword('orange')('⚡⚡')} 51 | 52 | Usage: puf [url] 53 | puf [url] ${chalk.dim('')} 54 | 55 | Commands: 56 | -f, ${chalk.dim('--fetch')} Fetch url of items in the playlist 57 | -e, ${chalk.dim('--export')} Export urls into json 58 | 59 | Extra: 60 | ${chalk.dim('-f')} url --name Show links along with the title 61 | ${chalk.dim('-e')} url --name Set desired name of the exported playlist 62 | 63 | Help: 64 | $ puf -f ${chalk.dim('https://goo.gl/QcSugM')} --name 65 | $ puf -e ${chalk.dim('https://goo.gl/QcSugM')} --name course 66 | `); 67 | end(1); 68 | } 69 | 70 | if (!inf || isUrl(inf) === false) { 71 | log(`\n ${chalk.red('✖')} Things don't work this way. Provide a valid url\n\n ${chalk.blue('✔')} ${chalk.dim('Type')} ${chalk.cyan('$ puf --help')} ${chalk.dim('for more help')}\n`); 72 | end(1); 73 | } 74 | 75 | if (arg === '-f' || arg === '--fetch') { 76 | checkConnection(); 77 | got(inf).then(res => { 78 | const $ = cheerio.load(res.body); 79 | const thumb = $('tr'); 80 | 81 | logUpdate(); 82 | 83 | if ((arg === '-f' || arg === '--fetch') && val === '--name') { 84 | $(thumb).each((i, links) => { 85 | const sources = `${url}${$(links).attr('data-video-id')}`; 86 | const names = $(links).attr('data-title'); 87 | 88 | log(` ${chalk.bold.blue('⚡⚡')} ${chalk.green(names)}`); 89 | log(` ${chalk.yellow('⏩ ')} ${sources} \n`); 90 | spinner.stop(); 91 | }); 92 | } else { 93 | $(thumb).each((i, links) => { 94 | const sources = `${url}${$(links).attr('data-video-id')}`; 95 | log(` ${chalk.yellow('⏩ ')} ${sources} \n`); 96 | spinner.stop(); 97 | }); 98 | } 99 | }).catch(err => { 100 | logUpdate(`\n${err}\n`); 101 | end(1); 102 | }); 103 | } 104 | 105 | if (arg === '-e' || arg === '--export') { 106 | checkConnection(); 107 | 108 | got(inf).then(res => { 109 | const $ = cheerio.load(res.body); 110 | const tr = $('tr'); 111 | 112 | logUpdate(`\n ${chalk.blue('🍁')} Done! Playlist exported as : \n\n ${chalk.green('🌴')} ${chalk.yellow(rad)} into ${chalk.blue(process.cwd())}\n`); 113 | 114 | for (let i = 0; i < tr.length; i++) { 115 | const obj = { 116 | playlist: [] 117 | }; 118 | 119 | for (let j = 0; j <= i; j++) { 120 | obj.playlist.push({ 121 | id: tr.eq(j).attr('data-video-id'), 122 | url: url + tr.eq(j).attr('data-video-id'), 123 | name: tr.eq(j).attr('data-title') 124 | }); 125 | } 126 | 127 | jsonFile.writeFile(rad, obj, {spaces: 2}, err => { 128 | end(1); 129 | log(err); 130 | }); 131 | } 132 | spinner.stop(); 133 | }).catch(err => { 134 | if (err) { 135 | logUpdate(`${err}`); 136 | end(1); 137 | } 138 | }); 139 | } 140 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Rishi Giri (rishigiri.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /media/puf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeDotJS/pufetch/e1c99b6399719546f746b01fa17c50ef75c48734/media/puf.png -------------------------------------------------------------------------------- /media/pufetch.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeDotJS/pufetch/e1c99b6399719546f746b01fa17c50ef75c48734/media/pufetch.gif -------------------------------------------------------------------------------- /media/pufetch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeDotJS/pufetch/e1c99b6399719546f746b01fa17c50ef75c48734/media/pufetch.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pufetch", 3 | "version": "1.0.0", 4 | "description": "Extract or export video links from a YouTube Playlist.", 5 | "main": "cli.js", 6 | "bin": { 7 | "puf": "cli.js" 8 | }, 9 | "engines": { 10 | "node": ">=4" 11 | }, 12 | "scripts": { 13 | "test": "xo && ava" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/CodeDotJS/pufetch.git" 18 | }, 19 | "keywords": [ 20 | "search", 21 | "link", 22 | "playlist", 23 | "youtube", 24 | "urls", 25 | "command-line", 26 | "export", 27 | "json", 28 | "cli-app", 29 | "cli", 30 | "scrap", 31 | "fetch", 32 | "cool" 33 | ], 34 | "dependencies": { 35 | "chalk": "^2.3.0", 36 | "cheerio": "^1.0.0-rc.2", 37 | "got": "^8.0.0", 38 | "is-url": "^1.2.2", 39 | "jsonfile": "^4.0.0", 40 | "log-update": "^2.3.0", 41 | "ora": "^1.3.0", 42 | "update-notifier": "^2.3.0" 43 | }, 44 | "devDependencies": { 45 | "ava": "*", 46 | "xo": "*" 47 | }, 48 | "xo": { 49 | "esnext": true 50 | }, 51 | "author": "Rishi Giri (http://rishigiri.ml)", 52 | "license": "MIT", 53 | "bugs": { 54 | "url": "https://github.com/CodeDotJS/pufetch/issues" 55 | }, 56 | "homepage": "https://github.com/CodeDotJS/pufetch#readme" 57 | } 58 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |

2 |
3 | 4 |
5 | 6 |
7 |

8 | 9 |

The best youtube playlist url scrapper and exporter!

10 | 11 | ## Install 12 | 13 | ``` 14 | $ npm install --global pufetch 15 | ``` 16 | 17 | ## Preview 18 | 19 |

20 | 21 | ⚡⚡ __`What you can do with it?`__ 22 | 23 | ✔ `List all the url of the items present in the playlist which is publically available` 24 | 25 | ✔ `Scrap the link along with the suitable titles` 26 | 27 | ✔ `Export the content of the playlist into a json file` 28 | 29 | ✔ `Works even with the shortened playlist url` 30 | 31 | 32 | ## Usage 33 | 34 | ``` 35 | Usage: puf [url] 36 | puf [url] 37 | 38 | Commands: 39 | -f, --fetch Fetch all video links from the playlist 40 | -e, --export Export urls into json 41 | 42 | Extra: 43 | -f url --name Show links along with the title 44 | -e url --name Set desired name of the exported playlist 45 | 46 | Help: 47 | $ puf -f https://goo.gl/QcSugM --name 48 | $ puf -e https://goo.gl/QcSugM --name course 49 | 50 | ``` 51 | 52 | __`NOTE :`__ `Doesn't work with private playlists` 53 | 54 | ## Related 55 | 56 | - __[`kote`](https://github.com/CodeDotJS/kote)__ `:` `Daily injection of wisdom, fun ,and love through command line` 57 | 58 | 59 | ## License 60 | 61 | MIT © [Rishi Giri](http://rishigiri.ml) 62 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import childProcess from 'child_process'; 2 | import test from 'ava'; 3 | 4 | test.cb('default', t => { 5 | const cp = childProcess.spawn('./cli.js', {stdio: 'inherit'}); 6 | 7 | cp.on('error', t.ifError); 8 | 9 | cp.on('close', code => { 10 | t.is(code, 1); 11 | t.end(); 12 | }); 13 | }); 14 | 15 | test.cb('listUrl', t => { 16 | const cp = childProcess.spawn('./cli.js', ['-f', 'https://goo.gl/QcSugM'], {stdio: 'inherit'}); 17 | 18 | cp.on('error', t.ifError); 19 | 20 | cp.on('close', code => { 21 | t.is(code, 0); 22 | t.end(); 23 | }); 24 | }); 25 | 26 | test.cb('listNameWithLink', t => { 27 | const cp = childProcess.spawn('./cli.js', ['-f', 'https://www.youtube.com/playlist?list=PLc96kFUJVrtPhEfjgA1mWH1PcXk33Yr-c', '--name'], {stdio: 'inherit'}); 28 | 29 | cp.on('error', t.ifError); 30 | 31 | cp.on('close', code => { 32 | t.is(code, 0); 33 | t.end(); 34 | }); 35 | }); 36 | 37 | test.cb('randomExport', t => { 38 | const cp = childProcess.spawn('./cli.js', ['-e', 'https://goo.gl/QcSugM'], {stdio: 'inherit'}); 39 | 40 | cp.on('error', t.ifError); 41 | 42 | cp.on('close', code => { 43 | t.is(code, 1); 44 | t.end(); 45 | }); 46 | }); 47 | 48 | test.cb('exportWithName', t => { 49 | const cp = childProcess.spawn('./cli.js', ['-e', 'https://goo.gl/QcSugM', '--name', 'course'], {stdio: 'inherit'}); 50 | 51 | cp.on('error', t.ifError); 52 | 53 | cp.on('close', code => { 54 | t.is(code, 1); 55 | t.end(); 56 | }); 57 | }); 58 | --------------------------------------------------------------------------------