├── .babelrc ├── .editorconfig ├── .github └── demo.gif ├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── package-lock.json ├── package.json └── src ├── index.js └── passandoNaTv.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "es2015", 4 | "stage-0" 5 | ], 6 | "ignore": [ 7 | "lib/__tests__/*", 8 | "lib/**/*.spec.js" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | indent_size = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.github/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/felipemfp/passando-na-tv/628427f743112b8db4d71615e1449606974f81e1/.github/demo.gif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | npm-debug.log* 3 | node_modules 4 | lib 5 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | src/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Felipe Pontes 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 | # passando-na-tv 2 | 3 | [![npm version](https://badge.fury.io/js/passando-na-tv.svg)](https://badge.fury.io/js/passando-na-tv) 4 | 5 | > :tv: A CLI tool for brazilian tv broadcasters 6 | 7 | ![demo](https://cdn.rawgit.com/felipemfp/passando-na-tv/f3265e03/.github/demo.gif) 8 | 9 | ## Instalação 10 | 11 | ```sh 12 | npm i -g passando-na-tv 13 | ``` 14 | 15 | ## Como usar? 16 | 17 | ``` 18 | Como usar 19 | $ passando-na-tv [canal] 20 | 21 | Opções 22 | --filmes, -f Apenas canais de filmes 23 | --series, -s Apenas canais de séries 24 | --esportes, -e Apenas canais de esportes 25 | --infantil, -i Apenas canais infantis 26 | --documentarios, -d Apenas canais de documentários 27 | --noticias, -n Apenas canais de notícias 28 | --abertos, -a Apenas canais abertos 29 | --entretenimento, -t Apenas canais de entretenimento 30 | --help, -h Apresentar ajuda 31 | 32 | Exemplos 33 | $ passando-na-tv --filmes 34 | ... lista de programas em apenas os canais de filmes 35 | $ passando-na-tv axn 36 | ... lista de programas nos canais AXN 37 | 38 | Dados fornecidos por meuguia.TV 39 | ``` 40 | 41 | ## Agradecimentos 42 | 43 | - [meuguia.TV](http://meuguia.tv/) por fornecer os dados 44 | 45 | ### Feito com... 46 | 47 | - [meuguia.js](https://github.com/felipemfp/meuguia.js) 48 | - [meow](https://github.com/sindresorhus/meow) 49 | - [inquirer.js](https://github.com/SBoudrias/Inquirer.js) 50 | - [chalk](https://github.com/chalk/chalk) 51 | - [update-notifier](https://github.com/yeoman/update-notifier) 52 | 53 | #### E no desenvolvimento... 54 | 55 | - [jest](https://github.com/facebook/jest) 56 | - [nock](https://github.com/node-nock/nock) 57 | - [babel](https://github.com/babel/babel) 58 | 59 | ## Contribuição 60 | 61 | Ficaremos muito felizes se você contribuir com este projeto seja enviando _Pull Request_ ou notificando bugs pelas _Issues_. 62 | 63 | ## Versionamento 64 | 65 | Estamos usando o [SemVer](http://semver.org/) para versionamento. Para ver as versões disponíveis: [tags deste repositório](https://github.com/felipemfp/passando-na-tv/tags). 66 | 67 | ## Autores 68 | 69 | * **Felipe Pontes** - *Trabalho inicial* - [felipemfp](https://github.com/felipemfp) 70 | 71 | Veja também a lista de [contribuidores](https://github.com/felipemfp/passando-na-tv/contributors) que participaram deste projeto. 72 | 73 | ## Licença 74 | 75 | Este projeto é licenciado pela Licença MIT - veja o arquivo [LICENSE](LICENSE) para mais detalhes. 76 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "passando-na-tv", 3 | "version": "0.1.5", 4 | "description": "O que está passando na TV?", 5 | "main": "./lib/index.js", 6 | "bin": { 7 | "passando-na-tv": "./lib/index.js" 8 | }, 9 | "scripts": { 10 | "prestart": "npm run build --silent", 11 | "start": "node .", 12 | "build": "babel src -d lib --ignore spec.js", 13 | "prepare": "npm run build", 14 | "test": "jest --no-watchman" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/felipemfp/passando-na-tv.git" 19 | }, 20 | "keywords": [ 21 | "meuguia.tv", 22 | "tv" 23 | ], 24 | "author": "Felipe Pontes (https://felipemfp.github.io)", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/felipemfp/passando-na-tv/issues" 28 | }, 29 | "homepage": "https://github.com/felipemfp/passando-na-tv#readme", 30 | "dependencies": { 31 | "chalk": "^1.1.3", 32 | "inquirer": "^3.0.1", 33 | "meow": "^3.7.0", 34 | "meuguia": "^0.2.1", 35 | "update-notifier": "^2.1.0" 36 | }, 37 | "devDependencies": { 38 | "babel-cli": "^6.22.2", 39 | "babel-preset-es2015": "^6.22.0", 40 | "babel-preset-stage-0": "^6.22.0", 41 | "jest": "^18.1.0", 42 | "nock": "^9.0.2" 43 | }, 44 | "jest": { 45 | "rootDir": "src" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import meow from 'meow' 4 | import updateNotifier from 'update-notifier' 5 | import pkg from '../package.json' 6 | import PassandoNaTvCli from './passandoNaTv' 7 | 8 | const notifier = updateNotifier({pkg}) 9 | notifier.notify() 10 | 11 | const cli = meow(` 12 | Como usar 13 | $ passando-na-tv [canal] 14 | 15 | Opções 16 | --filmes, -f Apenas canais de filmes 17 | --series, -s Apenas canais de séries 18 | --esportes, -e Apenas canais de esportes 19 | --infantil, -i Apenas canais infantis 20 | --documentarios, -d Apenas canais de documentários 21 | --noticias, -n Apenas canais de notícias 22 | --abertos, -a Apenas canais abertos 23 | --entretenimento, -t Apenas canais de entretenimento 24 | --help, -h Apresentar ajuda 25 | 26 | Exemplos 27 | $ passando-na-tv --filmes 28 | ... lista de programas em apenas os canais de filmes 29 | $ passando-na-tv axn 30 | ... lista de programas nos canais AXN 31 | 32 | Dados fornecidos por meuguia.TV 33 | `, { 34 | alias: { 35 | f: 'filmes', 36 | s: 'series', 37 | e: 'esportes', 38 | i: 'infantil', 39 | d: 'documentarios', 40 | n: 'noticias', 41 | a: 'abertos', 42 | t: 'entretenimento', 43 | h: 'help' 44 | } 45 | }) 46 | 47 | const arg = Object.keys(cli.flags).filter(f => f.length > 1)[0] || 'todos' 48 | 49 | const passandoNaTvCli = new PassandoNaTvCli(cli) 50 | 51 | if (arg === 'help' || !passandoNaTvCli.isValidCategory(arg)) { 52 | cli.showHelp() 53 | } else { 54 | passandoNaTvCli.list(arg) 55 | } 56 | -------------------------------------------------------------------------------- /src/passandoNaTv.js: -------------------------------------------------------------------------------- 1 | import inquirer from 'inquirer' 2 | import chalk from 'chalk' 3 | import meuguia from 'meuguia' 4 | 5 | const requestByCategory = { 6 | 'todos': meuguia.getAll, 7 | 'filmes': meuguia.getMovies, 8 | 'series': meuguia.getTvSeries, 9 | 'esportes': meuguia.getSports, 10 | 'infantil': meuguia.getKids, 11 | 'documentarios': meuguia.getDocumentaries, 12 | 'noticias': meuguia.getNews, 13 | 'abertos': meuguia.getOpen, 14 | 'entretenimento': meuguia.getEntertainment 15 | } 16 | 17 | class PassandoNaTvCli { 18 | constructor (cli) { 19 | this._cli = cli 20 | } 21 | 22 | list (category) { 23 | requestByCategory[category]() 24 | .then(results => this._filterResultsByInput(results)) 25 | .then(results => this._checkResults(results)) 26 | .then(results => this._sortResultsByChannel(results)) 27 | .then(results => this._formatResults(results)) 28 | .then(results => this._createListFromResults(results)) 29 | .then(inquirer.prompt) 30 | .catch(this._handleError) 31 | } 32 | 33 | isValidCategory (category) { 34 | return (typeof requestByCategory[category]) === 'function' 35 | } 36 | 37 | _filterResultsByInput (results) { 38 | return results.filter(result => { 39 | if (this._cli.input.length > 0) { 40 | let channel = result.channel.description.toLowerCase() 41 | return this._cli.input.some(input => channel.indexOf(input) > -1) 42 | } 43 | return true 44 | }) 45 | } 46 | 47 | _checkResults (results) { 48 | if (results.length === 0) { 49 | if (this._cli.input.length > 0) { 50 | console.log(`Sem resultados para: ${chalk.red(this._cli.input.join(', '))}.`) 51 | } else { 52 | console.log(`Sem resultados.`) 53 | } 54 | throw new Error('No results.') 55 | } 56 | return results 57 | } 58 | 59 | _sortResultsByChannel (results) { 60 | let resultsSorted = [...results] 61 | resultsSorted.sort((a, b) => { 62 | if (a.channel.description > b.channel.description) { 63 | return 1 64 | } 65 | if (a.channel.description < b.channel.description) { 66 | return -1 67 | } 68 | return 0 69 | }) 70 | return resultsSorted 71 | } 72 | 73 | _formatResults (results) { 74 | return results.map(result => ({ 75 | name: `${chalk.blue('[' + result.channel.description + ']')} ${result.title} ${chalk.yellow('@')} ${chalk.green(result.time)}` 76 | })) 77 | } 78 | 79 | _createListFromResults (results) { 80 | return [{ 81 | name: 'show', 82 | message: 'Passando na TV...', 83 | type: 'list', 84 | choices: results 85 | }] 86 | } 87 | 88 | _handleError (err) { 89 | if (err.message !== 'No results.') { 90 | console.log('Algo deu errado.', chalk.red('Você tem internet?')) 91 | } 92 | } 93 | } 94 | 95 | export default PassandoNaTvCli 96 | --------------------------------------------------------------------------------