Skip to content

Instantly share code, notes, and snippets.

@bmpvieira
Created October 2, 2012 16:49
Show Gist options
  • Save bmpvieira/3821033 to your computer and use it in GitHub Desktop.
Save bmpvieira/3821033 to your computer and use it in GitHub Desktop.
Simple Youtube playlist parser using JSONStream
/*
author: bmpvieira
license: WTFPL
description: Simple Youtube playlist parser using https://github.com/dominictarr/JSONStream
usage example: node youtubePlaylistParser.js PLt4dwg5cC5TSqHR44YK0UQ_8TSG8YtZtI | cclive -f best -c
*/
var request = require('request');
var JSONStream = require('JSONStream');
var playlistID = process.argv[2];
var url = "https://gdata.youtube.com/feeds/api/playlists/" + playlistID + "?v=2&alt=jsonc"
var parser = JSONStream.parse(['data', 'items', true, 'video', 'id']);
parser.on("data", function(data) {
console.log("http://www.youtube.com/watch?v=" + data);
});
parser.on("root", function(root, count) {
if (!count) {
console.log('no matches found:', root);
}
});
request(url).pipe(parser);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment