Skip to content

Commit

Permalink
search function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sequoia committed Apr 15, 2015
1 parent 061d036 commit 94cb172
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rado-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var inquirer = require('inquirer');
var superenv = require('superenv');
var path = require('path-extra');
var _ = require('lodash');
var download = require('./scraper.js');
var download = require('./scraper.js').download;

program
.option('-o, --out <path>','where to create show directory')
Expand Down
18 changes: 18 additions & 0 deletions rado-search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env node
var program = require('commander');
var _ = require('lodash');
var search = require('./scraper.js').search;
var chalk = require('chalk');

program
.parse(process.argv);

search(program.args[0])
.then(function(shows){
shows.forEach(function(show){
console.log(chalk.blue.bold(show.title));
console.log('slug: %s', show.slug);
console.log('genre: %s', show.genre);
console.log('number of episodes available: %s', show.episodes);
});
});
3 changes: 2 additions & 1 deletion rado.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
var program = require('commander');

program
.command('download <name>', 'download some shows')
.command('download <slug>', 'download some shows (by url part or "slug")')
.command('search [string]', 'search for a show by title or word')
.parse(process.argv);
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ See `.radorc.example`

:information_source: `skip` & `get` will be requested if not passed as switches

## `search`
Search for shows by title & output info about those shows

### Arguments
* search string: word/term to search for. show title is searched, case insensitive

## Examples
Download the first 10 Burkiss Ways
```sh
Expand All @@ -38,6 +44,14 @@ Download episodes 11-20 of The Six Shooter
```sh
$ ./rado.js download the-six-shooter -s 10 -n 10
```
Search for shows with "shoot" in the title
```sh
$ ./rado.js search shoot
```
Search for "space patrol"
```sh
$ ./rado.js search "space patrol"
```

## License
GPL 3
Expand Down
34 changes: 33 additions & 1 deletion scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var Promise = require('bluebird');
var cheerio = require('cheerio');
var async = require('async');
var fs = require('fs');
var _ = require('lodash');
var url = require('url');
var path = require('path');
var mkdirp = require('mkdirp');
Expand All @@ -15,7 +16,38 @@ var request = Promise.promisifyAll(require('request'));
var baseUrl = 'http://www.radioechoes.com';
var outputPath = null;

module.exports = download;
module.exports = {
download : download,
search : search
};

/**
* get array of shows with titles that contain the search term
* @param string
* @return Promise resolves with the array of shows
*/
function search(term){
return request.getAsync(baseUrl)
.then(function(args){
var $ = cheerio.load(args[1]);
var shows = [];
$('.seriesItem').each(function(i, el){
$el = $(el);
//array of ALL shows
shows.push({
title : $el.find('.seriesName').text(),
slug : $el.attr('series'),
genre : $el.attr('genre'),
episodes: $el.find('.episodeCount').text()
});
});
//filter to just matching shows
var matches = _.filter(shows,function(show){
return _.contains(show.title.toLowerCase(), term.toLowerCase());
});
return matches;
});
}

/**
* gets listing of MP3s & downloads them
Expand Down

0 comments on commit 94cb172

Please sign in to comment.