├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── index.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 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const got = require('got'); 4 | 5 | const msg = 'Either the video is deleted or it\'s not shared publicly!'; 6 | 7 | const lowResolution = link => { 8 | return got(link).then(res => { 9 | const link = res.body.split('sd_src:"')[1].split('",hd_tag')[0]; 10 | return { 11 | url: link 12 | }; 13 | }).catch(error => { 14 | if (error) { 15 | error.message = msg; 16 | } 17 | return error.message; 18 | }); 19 | }; 20 | 21 | const highResolution = link => { 22 | return got(link).then(res => { 23 | const link = res.body.split('hd_src:"')[1].split('",sd_src:"')[0]; 24 | return { 25 | url: link 26 | }; 27 | }).catch(error => { 28 | if (error) { 29 | error.message = msg; 30 | } 31 | return error.message; 32 | }); 33 | }; 34 | 35 | exports.low = lowResolution; 36 | exports.high = highResolution; 37 | -------------------------------------------------------------------------------- /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": "fbvideos", 3 | "version": "1.0.2", 4 | "description": "Easily extract downloadable link of publicly available videos on facebook.", 5 | "main": "index.js", 6 | "engines": { 7 | "node": ">=4" 8 | }, 9 | "scripts": { 10 | "test": "xo && ava" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/CodeDotJS/fbvideos.git" 15 | }, 16 | "keywords": [ 17 | "facebook", 18 | "api", 19 | "download", 20 | "video", 21 | "public", 22 | "link", 23 | "url", 24 | "extract", 25 | "fetch", 26 | "scrap" 27 | ], 28 | "dependencies": { 29 | "got": "^7.1.0" 30 | }, 31 | "devDependencies": { 32 | "ava": "*", 33 | "xo": "^*" 34 | }, 35 | "xo": { 36 | "esnext": true 37 | }, 38 | "author": "Rishi Giri (http://rishigiri.com)", 39 | "license": "MIT", 40 | "bugs": { 41 | "url": "https://github.com/CodeDotJS/fbvideos/issues" 42 | }, 43 | "homepage": "https://github.com/CodeDotJS/fbvideos#readme" 44 | } 45 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |

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

8 | 9 | > :link: Easily extract downloadable link of publicly available videos on facebook. 10 | 11 | ## Install 12 | 13 | ``` 14 | $ npm install --save fbvideos 15 | ``` 16 | 17 | ## Usage 18 | 19 | ```js 20 | const fbvid = require('fbvideos'); 21 | 22 | const video = 'https://www.facebook.com/9gag/videos/10155721204506840/'; 23 | 24 | fbvid.low(video).then(vid => { 25 | console.log(vid) 26 | // => { url: 'https://video.fpat1-1.fna.fbcdn.net/...mp4?934&oe=5972F363' } 27 | 28 | }); 29 | 30 | fbvid.high(video).then(vid => { 31 | console.log(vid); 32 | // => { url: 'https://video.fpat1-1.fna.fbcdn.net/...mp4?934&OE=2kf2lf4g' } 33 | }); 34 | ``` 35 | 36 | ## API 37 | 38 | #### __`fbvid.low(link)`__ 39 | 40 | - `Returns a` __`url`__ `for` __`low`__ `resolution facebook video.` 41 | 42 | __`link`__ 43 | 44 | `Type :` `string` 45 | 46 | #### __`fbvid.high(link)`__ 47 | 48 | - `Returns a` __`url`__ `for` __`high`__ `resolution facebook video.` 49 | 50 | __`link`__ 51 | 52 | `Type :` `string` 53 | 54 | 55 | ## Related 56 | 57 | 58 | - __[`facebookid`](https://github.com/CodeDotJS/facebookid)__ `:` `An api to find user id of any facebook user` 59 | - __[`acuter`](https://github.com/CodeDotJS/acuter)__ `:` `A simple wrapper for twitter media` 60 | 61 | ## License 62 | 63 | MIT © [Rishi Giri](http://rishigiri.ml) 64 | 65 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import m from '.'; 3 | 4 | test('fbdl.low()', async t => { 5 | const video = await m.low('https://www.facebook.com/9gag/videos/10155721204506840/'); 6 | 7 | t.is(video.url.split('?')[0], video.url.split('?')[0]); 8 | }); 9 | 10 | test('fbdl.high()', async t => { 11 | const video = await m.high('https://www.facebook.com/9gag/videos/10155721204506840/'); 12 | 13 | t.is(video.url.split('?')[0], video.url.split('?')[0]); 14 | }); 15 | 16 | --------------------------------------------------------------------------------