Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm_debug.log
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Building portify
* Make sure you have installed a usable build enviroment (gcc, make & co.)
* Install Node.js (using your favourite package manager, but make sure it's newer than 0.8)
* Clone the git repo (master branch)
* Go into the ./data/ directory and run npm install (This will fetch and compile all depenencies of portify)
* Try running the daemon by executing node app.js in the ./data/ folder
* `npm install` Install dependencies
* `npm start` Start the server
* Open your favourite browser and go to localhost:3132

[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mauimauer/portify/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
Expand Down
68 changes: 61 additions & 7 deletions data/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ var app,
server,
postField,
appjs = false,
env = process.env,
http = require('http'),
GoogleClientLogin = require('googleclientlogin').GoogleClientLogin,
googleapis = require('googleapis'),
googleapisOAuth = googleapis.OAuth2Client,
Spotify = require('spotify-web'),
events = require('events'),
googleMusic = require('./gmusic.js'),
io = require('socket.io'),
TimeQueue = require('timequeue');

console.log("portify 0.51");
console.log("portify, version: " + process.env.npm_package_version);

if (typeof Proxy !== 'object' || typeof WeakMap !== 'function') {
console.log("Starting without harmony");
express = require('express');
postField = "body";
app = express();
server = http.createServer(app)
server = http.createServer(app);
router = app;
app.use(express.static(__dirname + '/content'));
app.use (function(req, res, next) {
Expand All @@ -33,6 +36,30 @@ if (typeof Proxy !== 'object' || typeof WeakMap !== 'function') {
next();
});
});
app.get("/generateoauth", function (req, res) {
var uri = getAccessToken();
res.redirect(301,uri);
});
app.get("/oauthcallback", function (req, res) {
var code = req.query.code;
res.cookie(
'token',
req.query.code
);
if (code) {
res.redirect(301, "/#/spotify/login");
} else {
res.send(
500,
{
error: 'Please authorize with one Google ' +
'account.'
}
);

}
});

app.use(app.router);

server.listen(3132);
Expand Down Expand Up @@ -276,7 +303,7 @@ router.post('/spotify/login', function(request, response, next){
response.send({ status: 400, message: "login failed.", error: err });
return;
}

console.log("Spotify Login success");
spotifySession = spotify;
response.send({ status: 200, message: "login successful." });
Expand Down Expand Up @@ -448,8 +475,10 @@ if(appjs) {
window.process = process;
window.module = module;

function F12(e){ return e.keyIdentifier === 'F12' }
function Command_Option_J(e){ return e.keyCode === 74 && e.metaKey && e.altKey }
function F12(e){ return e.keyIdentifier === 'F12'; }
function Command_Option_J(e){
return e.keyCode === 74 && e.metaKey && e.altKey;
}

window.addEventListener('keydown', function(e){
if (F12(e) || Command_Option_J(e)) {
Expand All @@ -461,4 +490,29 @@ if(appjs) {
window.on('close', function(){
console.log("Window Closed");
});
}
}

function getAccessToken(oauth2Client) {
return function () {
// generate consent page url
var url = oauth2Client.generateAuthUrl({
access_type: 'offline', // will return a refresh token
scope: 'https://www.googleapis.com/auth/plus.me'
});
return url;
};
}


// load google plus v1 API resources and methods
googleapis
.execute(function(err, client) {

var oauth2Client =
new googleapisOAuth(
env.npm_package_config_gapi_client_id,
env.npm_package_config_gapi_client_secret,
env.npm_package_config_gapi_redirect_uri
);
getAccessToken = getAccessToken(oauth2Client);
});
8 changes: 2 additions & 6 deletions data/content/partials/google_login.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
</div>
<div class="row">
<div class="span3">
<label>E-Mail:</label>
<input type="text" ng-model="loginData.email" required placeholder="E-Mail">
<label>Password</label>
<input type="password" ng-model="loginData.password" required placeholder="Password">
<button type="submit" class="btn btn-info">Submit</button>
<a href="/generateoauth" type="submit" class="btn btn-info">Login with Google OAuth2</a>
</div>
<div class="span5 pull-right">
<div class="alert alert-info fade in">
Expand All @@ -21,4 +17,4 @@
</div>
</fieldset>
</form>
</div>
</div>
15 changes: 0 additions & 15 deletions data/package.json

This file was deleted.

20 changes: 20 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "portify",
"description": "Moves your Spotify playlists to Google",
"version": "0.0.6",
"private": true,
"dependencies": {
"spotify-web": "https://github.com/adammw/node-spotify-web/tarball/api-redesign/",
"socket.io": "~0.9.16",
"express": "~3.4.8",
"superagent": "~0.16.0",
"levenshtein": "~1.0.4",
"timequeue": "~0.2.2",
"googleapis": "~0.6.1"
},
"config": {
"gapi_client_id": "your_client_id",
"gapi_client_secret": "your_client_secret",
"gapi_redirect_uri": "your_redirect_url"
}
}
1 change: 1 addition & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./data/app')