├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── cli.js ├── license ├── 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 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | 'use strict'; 4 | 5 | const dns = require('dns'); 6 | const https = require('https'); 7 | const fs = require('fs'); 8 | const os = require('os'); 9 | const fse = require('fs-extra'); 10 | const got = require('got'); 11 | const isUrl = require('is-url'); 12 | const chalk = require('chalk'); 13 | const logUpdate = require('log-update'); 14 | const ora = require('ora'); 15 | const updateNotifier = require('update-notifier'); 16 | const pkg = require('./package.json'); 17 | 18 | updateNotifier({pkg}).notify(); 19 | 20 | const arg = process.argv[2]; 21 | const inf = process.argv[3]; 22 | const pre = chalk.cyan.bold('›'); 23 | const pos = chalk.red.bold('›'); 24 | const dir = `${os.homedir()}/facebook-videos/`; 25 | const spinner = ora(); 26 | 27 | if (!arg || arg === '--help') { 28 | console.log(` 29 | Usage: fbdl [source] 30 | 31 | Command: 32 | -l, --low Download video in low resolution 33 | -h, --high Download video in high resolution 34 | 35 | Help: 36 | $ fbdl -l https://www.facebook.com/9gag/videos/10155721204506840/ 37 | `); 38 | process.exit(1); 39 | } 40 | 41 | if (!inf || isUrl(inf) === false) { 42 | logUpdate(`\n${pos} Please provide a valid url \n`); 43 | process.exit(1); 44 | } 45 | 46 | fse.ensureDir(dir, err => { 47 | if (err) { 48 | process.exit(1); 49 | } 50 | }); 51 | 52 | const checkConnection = () => { 53 | dns.lookup('facebook.com', err => { 54 | if (err) { 55 | logUpdate(`\n${pos} Please check your internet connection!\n`); 56 | process.exit(1); 57 | } else { 58 | logUpdate(); 59 | spinner.text = 'Calm down your bazooka'; 60 | spinner.start(); 61 | } 62 | }); 63 | }; 64 | 65 | const downloadMessage = () => { 66 | logUpdate(); 67 | spinner.text = 'Downloading video. Hold on!'; 68 | }; 69 | 70 | const showError = () => { 71 | logUpdate(`\n${pos}${pos} Maybe the video is : \n\n ${pre} Deleted \n ${pre} Not shared publicly!\n\n ${chalk.dim('for -h or --high : High resolution video is not available!\n')}`); 72 | process.exit(1); 73 | }; 74 | 75 | const download = sources => { 76 | const rand = Math.random().toString(16).substr(10); 77 | const save = fs.createWriteStream(`${dir}/${rand}.mp4`); 78 | 79 | https.get(sources, (res, cb) => { 80 | res.pipe(save); 81 | 82 | save.on('finish', () => { 83 | save.close(cb); 84 | logUpdate(`\n${pre} Video Saved! ${chalk.dim(`[${rand}.mp4]`)}\n`); 85 | spinner.stop(); 86 | 87 | save.on('error', () => { 88 | process.exit(1); 89 | }); 90 | }); 91 | }); 92 | }; 93 | 94 | if (arg === '-l' || arg === '--low') { 95 | checkConnection(); 96 | got(inf).then(res => { 97 | downloadMessage(); 98 | const data = res.body.split('sd_src:"')[1].split('",hd_tag')[0]; 99 | download(data); 100 | }).catch(error => { 101 | if (error) { 102 | showError(); 103 | } 104 | }); 105 | } 106 | 107 | if (arg === '-h' || arg === '--high') { 108 | checkConnection(); 109 | got(inf).then(res => { 110 | downloadMessage(); 111 | const data = res.body.split('hd_src:"')[1].split('",sd_src:"')[0]; 112 | download(data); 113 | }).catch(error => { 114 | if (error) { 115 | showError(); 116 | } 117 | }); 118 | } 119 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "fbdl", 3 | "version": "1.0.2", 4 | "description": "Downloading publicly shared vidoes from facebook with an ease!", 5 | "main": "cli.js", 6 | "bin": { 7 | "fbdl": "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/fbdl.git" 18 | }, 19 | "keywords": [ 20 | "facebook", 21 | "video", 22 | "videos", 23 | "download", 24 | "extract", 25 | "fetch", 26 | "easy" 27 | ], 28 | "dependencies": { 29 | "chalk": "^2.0.1", 30 | "fs-extra": "^4.0.0", 31 | "got": "^7.1.0", 32 | "is-url": "^1.2.2", 33 | "log-update": "^2.0.0", 34 | "ora": "^1.3.0", 35 | "update-notifier": "^2.2.0" 36 | }, 37 | "devDependencies": { 38 | "ava": "*", 39 | "xo": "*" 40 | }, 41 | "xo": { 42 | "esnext": true 43 | }, 44 | "author": "Rishi Giri (http://rishigiri.com)", 45 | "license": "MIT", 46 | "bugs": { 47 | "url": "https://github.com/CodeDotJS/fbdl/issues" 48 | }, 49 | "homepage": "https://github.com/CodeDotJS/fbdl#readme" 50 | } 51 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |

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

8 | 9 | > Download publicly shared videos from Facebook with an ease! 10 | 11 | ## Install 12 | 13 | ``` 14 | $ npm install --global fbdl 15 | ``` 16 | 17 | ## Preview 18 | 19 |

20 | 21 |

22 | 23 | ## Usage 24 | 25 | ``` 26 | Usage: fbdl [source] 27 | 28 | Command: 29 | -l, --low Download video in low resolution 30 | -h, --high Download video in high resolution 31 | 32 | Help: 33 | $ fbdl -l https://www.facebook.com/9gag/videos/10155721204506840/ 34 | 35 | ``` 36 | 37 | ## Related 38 | 39 | - __[`fbvideos`](https://github.com/CodeDotJS/fbvidoes)__ `:` `An api to extract downloadable link of a public video from facebook` 40 | - __[`twiger`](https://github.com/CodeDotJS/twiger)__ `:` `A complete media downlodaer for Twitter` 41 | - __[`instavim`](https://github.com/CodeDotJS/instavim)__ `:` `A complete media downloader for Instagram` 42 | - __[`image-of`](https://github.com/CodeDotJS/image-of)__ `:` `Download profile picture of any facebook user` 43 | - __[`smule`](https://github.com/CodeDotJS/smule)__ `:` `A complete media downloader for Smule` 44 | 45 | # License 46 | 47 | MIT © [Rishi Giri](http://rishigiri.ml) 48 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import childProcess from 'child_process'; 2 | import test from 'ava'; 3 | 4 | test.cb('regular', 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('resolution', t => { 16 | const cp = childProcess.spawn('./cli.js', ['-l', 'https://www.facebook.com/9gag/videos/10155721204506840/'], {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 | --------------------------------------------------------------------------------