├── .eslintrc.json ├── .gitignore ├── LICENSE ├── README.md ├── package.json └── periscope.js /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "indent": ["error", "tab"], 4 | "quotes": ["error", "single"], 5 | "quote-props": ["warn", "as-needed"], 6 | "semi": ["error", "always"], 7 | "keyword-spacing": ["error"], 8 | "no-unused-vars": ["warn", { "vars": "all", "args": "none" }], 9 | "no-console": ["off"], 10 | "no-mixed-spaces-and-tabs": ["error", "smart-tabs"], 11 | "no-new-object": ["error"], 12 | "no-array-constructor": ["error"], 13 | "space-before-blocks": ["error", "always"], 14 | "space-before-function-paren": ["error", "never"], 15 | "space-in-parens": ["error", "never"], 16 | "space-infix-ops": ["error"], 17 | "space-unary-ops": ["error", { "words": true, "nonwords": false }], 18 | "object-curly-spacing": ["error", "always"], 19 | "array-bracket-spacing": ["error", "never"], 20 | "guard-for-in": "error", 21 | "no-spaced-func": "error", 22 | "no-trailing-spaces": ["error", { "skipBlankLines": true }], 23 | "handle-callback-err": "error", 24 | "comma-spacing": ["error", {"before": false, "after": true}], 25 | "one-var": ["error", "never"], 26 | "no-redeclare": 0, 27 | "comma-dangle": ["error", "never"], 28 | "arrow-parens": ["warn", "always"], 29 | "arrow-spacing": ["error"], 30 | "no-confusing-arrow": ["error"], 31 | "no-useless-computed-key": ["error"], 32 | "object-shorthand": ["warn", "methods"], 33 | "prefer-arrow-callback": ["error"], 34 | "prefer-rest-params": ["warn"], 35 | "template-curly-spacing": ["warn", "never"] 36 | }, 37 | "env": { 38 | "node": true, 39 | "es6": true, 40 | "mocha": true 41 | }, 42 | "extends": "eslint:recommended" 43 | } 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Matteo Contrini 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-periscope-stream 2 | Get details about a Periscope live 3 | 4 | ## Install 5 | ```js 6 | npm install node-periscope-stream 7 | ``` 8 | 9 | ## Use 10 | ```js 11 | var periscope = require('node-periscope-stream'); 12 | periscope('https://www.periscope.tv/w/[example]', function(err, details) { 13 | if (err) { 14 | console.log(err); 15 | return; 16 | } 17 | }); 18 | ``` 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-periscope-stream", 3 | "version": "1.0.0", 4 | "description": "Get details about a Periscope live stream", 5 | "main": "periscope.js", 6 | "keywords": [ 7 | "periscope", 8 | "stream" 9 | ], 10 | "author": "Matteo Contrini ", 11 | "license": "MIT", 12 | "dependencies": { 13 | "needle": "^2.0.1" 14 | }, 15 | "repository": "matteocontrini/node-periscope-stream", 16 | "bugs": { 17 | "url": "https://github.com/matteocontrini/node-periscope-stream/issues" 18 | }, 19 | "devDependencies": { 20 | "eslint": "^4.9.0" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /periscope.js: -------------------------------------------------------------------------------- 1 | const needle = require('needle'); 2 | 3 | function periscope(url, callback) { 4 | let id = findId(url); 5 | 6 | if (id) { 7 | let api = 'https://api.periscope.tv/api/v2/getAccessPublic?broadcast_id=' + id; 8 | 9 | needle.get(api, (error, response, body) => { 10 | if (error) { 11 | callback(new Error('Network error')); 12 | } 13 | else if (response.statusCode != 200) { 14 | callback(new Error('Response error: ' + response.statusCode)); 15 | } 16 | else { 17 | callback(null, body); 18 | } 19 | }); 20 | } 21 | else { 22 | return callback(new Error('Invalid URL')); 23 | } 24 | } 25 | 26 | function findId(url) { 27 | let pscp = url.match(/pscp.tv\/w\/(.*)/i); 28 | let peri = url.match(/periscope.tv\/w\/(.*)/i); 29 | 30 | if (pscp !== null) return pscp[1]; 31 | if (peri !== null) return peri[1]; 32 | else return null; 33 | } 34 | 35 | module.exports = periscope; 36 | --------------------------------------------------------------------------------