Browse Source

removed a bunch of duplicated songs

master
Julio Biason 11 years ago
parent
commit
e6d655261d
  1. 5
      db/db.py
  2. 130
      lyrics.yaml
  3. 144
      lyricsnode/routes/round.js
  4. 1
      lyricsnode/views/index.html

5
db/db.py

@ -36,8 +36,9 @@ print '\tSongs...'
cursor.execute('''CREATE TABLE songs ( cursor.execute('''CREATE TABLE songs (
id INTEGER PRIMARY KEY, id INTEGER PRIMARY KEY,
title TEXT, title TEXT,
artist INTEGER CONSTRAINT aritst_song REFERENCES artists (id), artist INTEGER CONSTRAINT artist_song REFERENCES artists (id),
done_in TEXT done_in TEXT,
CONSTRAINT no_repeats UNIQUE (artist, title) ON CONFLICT ABORT
)''') )''')
print '\tLyrics...' print '\tLyrics...'

130
lyrics.yaml

@ -209,22 +209,6 @@
Nothing ever lasts forever Nothing ever lasts forever
<song title> <song title>
-
artist: Technotronic
song: Pump Up the Jam
done: true
lyrics: >
Yo Come On Move This
Shake That Body
Shake That Body
People dont you know, dont you know
its about time
- -
artist: Cazuza artist: Cazuza
song: Exagerado song: Exagerado
@ -1122,13 +1106,6 @@
If you feel like letting go (hold on) If you feel like letting go (hold on)
When you think you've had too much of this life, well hang on When you think you've had too much of this life, well hang on
-
artist: cazuza
song: exagerado
done: true
lyrics: >
- -
artist: survivor artist: survivor
song: eye of the tiger song: eye of the tiger
@ -1317,13 +1294,6 @@
song: in the end song: in the end
done: true done: true
lyrics: > lyrics: >
-
artist: culture club
song: karma chameleon
done: true
lyrics: >
- -
artist: bon jovi artist: bon jovi
song: livin' on a prayer song: livin' on a prayer
@ -1832,18 +1802,11 @@
Leave the real one far behind Leave the real one far behind
And we can dance And we can dance
-
artist: natalie imbruglia
song: torn
done: true
lyrics: >
- -
artist: spin doctors artist: spin doctors
song: two princes song: two princes
done: true done: true
lyrics: > lyrics: >
- -
artist: chico buarque artist: chico buarque
song: vai passar song: vai passar
@ -6081,11 +6044,6 @@
song: divida song: divida
done: true done: true
lyrics: > lyrics: >
-
artist: billy idol
song: eyes without a face
done: true
lyrics: >
- -
artist: leona lewis artist: leona lewis
song: bleeding love song: bleeding love
@ -7246,7 +7204,7 @@
- -
artist: natalie imbruglia artist: natalie imbruglia
song: torn song: torn
done: false done: true
lyrics: > lyrics: >
I thought I saw a man brought to life I thought I saw a man brought to life
@ -7331,92 +7289,6 @@
Of the cross I bear that you gave to me Of the cross I bear that you gave to me
<tip>, <tip>, <song title> <tip>, <tip>, <song title>
-
artist: bon jovi
song: livin' on a prayer
done: false
lyrics: >
Once upon a time
Not so long ago
Tommy used to work on the docks
Union's been on strike
Hes down on his luck...it's tough, so tough
Gina works the diner all day
Working for her man, she brings home her pay
For love - for love
She says: We've got to hold on to what we've got
'Cause it doesn't make a difference
If we make it or not
We've got each other and that's a lot
For love - we'll give it a shot
Oh, we're half way there
Whoah, <song title>
Take my hand, we'll make it, I swear
Whoah, <song title>
-
artist: europe
song: the final countdown
done: false
lyrics: >
We're leaving together
But still it's farewell
And maybe we'll come back,
To earth, who can tell?
I guess there is no one to blame
We're leaving ground (leaving ground)
Will things ever be the same again?
It's <song title>.
<song title>.
Oh, We're heading for Venus (Venus)
And still we stand tall
Cause maybe they've seen us
And welcome us all, yeah
With so many light years to go
And things to be found (to be found)
I'm sure that we'll all miss her so
It's <song title>.
- -
artist: gotye artist: gotye
song: somebody that i used to know song: somebody that i used to know

144
lyricsnode/routes/round.js

@ -4,18 +4,18 @@
var sqlite3 = require('sqlite3'); var sqlite3 = require('sqlite3');
var path = require('path'); var path = require('path');
var db; // make it global var db = null; // make it global
/** /**********************************************************************
* db name * Helper functions
*/ *********************************************************************/
/** db name */
function dbName() { function dbName() {
return path.join(__dirname, '../../db/lyrics.sq3'); return path.join(__dirname, '../../db/lyrics.sq3');
} }
/** /** turn a phrase into a list of acronyms */
* turn a phrase into a list of acronyms
*/
function acronymize(phrase) { function acronymize(phrase) {
var letters = []; var letters = [];
phrase.split(' ').forEach(function (elem, idx, array) { phrase.split(' ').forEach(function (elem, idx, array) {
@ -25,31 +25,44 @@ function acronymize(phrase) {
return letters.join(''); return letters.join('');
} }
/*********************************************************************** /**********************************************************************
* Main page * Open the database
**********************************************************************/ *********************************************************************/
console.log('Opening the database ' + dbName() + '...');
/** db = new sqlite3.Database(dbName(), sqlite3.OPEN_READWRITE, function (error) {
* Pick a song if (error) {
db = null; // keep it null, to point that it is broken
}
});
/** small note: the db structure:
* artists:
* id int primary key
* name text unique
*
* songs:
* id int primary key
* title text
* artist int
* done_in text
*
* lyrics:
* id int primary key
* song int
* lyrics text
*/ */
function getSong(res) {
var name = dbName(); /**********************************************************************
var db = null; * Select a song and display it
*********************************************************************/
exports.index = function (req, res) {
var song = null; var song = null;
var artist = null; var artist = null;
var lyrics = null; var lyrics = null;
function pickSong() {
console.log('Picking song...');
db.get('SELECT * FROM songs WHERE done_in IS NULL ORDER BY random() LIMIT 1', function (err, selectSong) {
if (err) {
throw err;
}
song = selectSong; if (!db) {
console.log(song); res.render('db-error');
pickArtist(); return;
});
} }
function pickArtist() { function pickArtist() {
@ -91,25 +104,78 @@ function getSong(res) {
res.render('index', params); res.render('index', params);
} }
console.log('Opening the database ' + name + '...'); console.log('Picking song...');
db = new sqlite3.Database(name, sqlite3.OPEN_READWRITE, function (error) { db.get('SELECT * FROM songs WHERE done_in IS NULL ORDER BY random() LIMIT 1', function (err, selectSong) {
if (error) { if (err) {
throw error; throw err;
} }
pickSong(); song = selectSong;
console.log(song);
pickArtist();
}); });
} }
exports.index = function (req, res) {
getSong(res);
};
/*********************************************************************** /***********************************************************************
* Support for the small box with the "others" picks * Support for the small box with the "others" picks
**********************************************************************/ **********************************************************************/
exports.others = function (req, res) { exports.others = function (req, res) {
console.log('Artist: ' + req.body.artist); var posted_artist = req.body.artist.toLowerCase();
console.log('Song: ' + req.body.song); var posted_song = req.body.song.toLowerCase();
console.log('Artist: ' + posted_artist);
console.log('Song: ' + posted_song);
var result = {status: '', message: ''}
function insertSong(artist) {
var now = new Date();
console.log('Adding song as played in ' + now.toJSON() + '...');
var stmt = db.run('INSERT INTO songs (id, title, artist, done_in) VALUES (NULL, ?, ?, ?)', [
posted_song,
artist,
now.toJSON()
], function (error) {
if (error) {
// expected: artist AND song already picked
console.log('Insert failed, possible duplicate');
result.status = 'ERROR';
result.message = 'Song already picked';
} else {
console.log('Insert succeded');
// things went alright
result.status = 'OK'
}
console.log(JSON.stringify(result));
res.writeHead(200, {'Content-Type': 'application/json'});
res.write(JSON.stringify(result));
res.end();
}
);
}
var stmt = db.run('INSERT INTO artists (id, name) VALUES (NULL, ?)', [
posted_artist
],
function (error) {
if (error) {
// expected error: artist already exists
console.log('Artist exists, trying to find id...');
db.get('SELECT id FROM artists WHERE name = ?', [posted_artist], function (err, artist) {
if (err) {
throw err;
}
console.log('Artist id = ' + artist.id);
insertSong(artist.id);
});
} else {
console.log('New artist id = ' + this.lastID);
insertSong(this.lastID);
}
}
);
}; };

1
lyricsnode/views/index.html

@ -110,6 +110,7 @@ $('#others').on('submit', function() {
url: '/round/others/', url: '/round/others/',
type: 'POST', type: 'POST',
data: $(this).serialize(), data: $(this).serialize(),
dataType: 'json',
success: function (response) { success: function (response) {
console.log(response); console.log(response);
} }

Loading…
Cancel
Save