Skip to content

Instantly share code, notes, and snippets.

@cnandreu
Created November 27, 2012 20:39
Show Gist options
  • Save cnandreu/4156857 to your computer and use it in GitHub Desktop.
Save cnandreu/4156857 to your computer and use it in GitHub Desktop.
Get youtube comments

##Install

  1. Get Node.js.
  2. Copy yt.js and package.json to your computer.
  3. Run npm install to download dependencies.
  4. chmod +x yt.js so you can execute it.

##Usage Example

./yt.js --id=xDj7gvc_dsA --max=3

--id is the youtube video id.

--max is the maximum number of comments to display.

##Example Output

2 'well actually when rose saves her father [...]
1 'H.P Lovecraft vs Edgar Allan Poe!!!'
0 'PATTON vs ERWIN ROMMEL'
{
"name": "yt",
"version": "0.0.1",
"description": "Get youtube comments for a specific video",
"author": "Carlos Andreu",
"dependencies": {
"optimist": ">=0.3.5",
"youtube-feeds": ">=1.0.3"
},
"engines": {
"node": ">=0.8"
}
}
#!/usr/bin/env node
/*
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <carlos.andreu[at]upr.edu> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.
# ----------------------------------------------------------------------------
*/
var argv = require('optimist').argv,
youtube = require('youtube-feeds'),
max = argv.max || 10,
videoid = argv.id || 'EINpkcphsPQ';
youtube.feeds.comments(videoid, {"max-results" : max}, function (data) {
if(Array.isArray(data) && data.length > 0) {
var len = data.length;
while (len--) {
console.log(len, data[len].content['$t']);
}
} else {
console.log('Error');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment