Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Init commit

  • Loading branch information...
commit e7499936a881901b6e1228dc7e04363ea445eb79 0 parents
@smithamax authored
Showing with 85 additions and 0 deletions.
  1. +2 −0  .gitignore
  2. +66 −0 index.js
  3. +17 −0 package.json
2  .gitignore
@@ -0,0 +1,2 @@
+.DS_Store
+node_modules
66 index.js
@@ -0,0 +1,66 @@
+#!/usr/bin/env node
+
+var client = require('spotify-node-applescript');
+var cli = require('cli').enable('version');
+
+cli.setApp('./package.json');
+
+cli.parse(null, ['play', 'pause', 'next', 'previous', 'status']);
+
+function nowPlaying() {
+ client.getTrack(function(err, track) {
+ if (err || !track) cli.error(err);
+ cli.info(track.name + " - " + track.artist);
+ });
+}
+
+
+cli.main(function (args, options) {
+ if (cli.command == 'play') {
+ if (cli.args.length) {
+
+ client.playTrack(cli.args.shift(), function () {
+ nowPlaying();
+ });
+
+ } else {
+
+ client.play(function () {
+ nowPlaying();
+ });
+
+ }
+ }
+
+ if (cli.command == 'pause') {
+ client.pause(function () {
+ cli.ok('paused');
+ });
+ }
+
+ if (cli.command == 'next') {
+ client.next(function () {
+ nowPlaying();
+ });
+ }
+
+ if (cli.command == 'previous') {
+ client.previous(function () {
+ nowPlaying();
+ });
+ }
+
+ if (cli.command == 'status') {
+ client.getState(function (err, state) {
+ if (err) return cli.error(err);
+ cli.info(state.state);
+
+ client.getTrack(function(err, track) {
+ if (err) return cli.error(err);
+ cli.info(track.name + " - " + track.artist);
+ cli.progress(state.position / track.duration);
+ });
+ });
+ }
+
+});
17 package.json
@@ -0,0 +1,17 @@
+{
+ "name": "spotify-cli",
+ "version": "0.0.0",
+ "description": "ERROR: No README.md file found!",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "bin": { "spotify" : "./index.js" },
+ "repository": "",
+ "author": "Dominic Smith",
+ "license": "BSD",
+ "dependencies": {
+ "spotify-node-applescript": "~0.1.0",
+ "cli": "~0.4.4-1"
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.