We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit 85f47603 authored by jurgbohn's avatar jurgbohn

Add mbid in Scrobbles / Now Playing.

Expanded tests to include mbid.
parent 0c18118f
...@@ -78,6 +78,7 @@ if (isset($_POST['install'])) { ...@@ -78,6 +78,7 @@ if (isset($_POST['install'])) {
track VARCHAR(255) REFERENCES Track(name), track VARCHAR(255) REFERENCES Track(name),
artist VARCHAR(255) REFERENCES Artist(name), artist VARCHAR(255) REFERENCES Artist(name),
time int, time int,
mbid VARCHAR(36),
PRIMARY KEY(username, track, artist, time))"); PRIMARY KEY(username, track, artist, time))");
$mdb2->query("CREATE TABLE Scrobble_Sessions( $mdb2->query("CREATE TABLE Scrobble_Sessions(
...@@ -90,6 +91,7 @@ if (isset($_POST['install'])) { ...@@ -90,6 +91,7 @@ if (isset($_POST['install'])) {
username VARCHAR(64) PRIMARY KEY REFERENCES Users(username), username VARCHAR(64) PRIMARY KEY REFERENCES Users(username),
track VARCHAR(255) REFERENCES Track(name), track VARCHAR(255) REFERENCES Track(name),
artist VARCHAR(255) REFERENCES Artist(name), artist VARCHAR(255) REFERENCES Artist(name),
mbid VARCHAR(36),
expires int)"); expires int)");
// Test user configuration // Test user configuration
......
...@@ -41,11 +41,12 @@ $mdb2->query("DELETE FROM Now_Playing WHERE expires < " . time()); ...@@ -41,11 +41,12 @@ $mdb2->query("DELETE FROM Now_Playing WHERE expires < " . time());
//Delete this user's last playing song (if any) //Delete this user's last playing song (if any)
$mdb2->query("DELETE FROM Now_Playing WHERE username = " . $username); $mdb2->query("DELETE FROM Now_Playing WHERE username = " . $username);
$mdb2->query("INSERT INTO Now_Playing (username, artist, track, expires) VALUES (" $mdb2->query("INSERT INTO Now_Playing (username, artist, track, expires, mbid) VALUES ("
. $username . ", " . $username . ", "
. $artist . ", " . $artist . ", "
. $track . ", " . $track . ", "
. $expires . ")"); . $expires . ", "
. $mbid . ")");
die("OK\n"); die("OK\n");
......
...@@ -44,11 +44,12 @@ for($i = 0; $i < count($_POST['a']); $i++) { ...@@ -44,11 +44,12 @@ for($i = 0; $i < count($_POST['a']); $i++) {
createTrackIfNew($artist, $album, $track, $mbid); createTrackIfNew($artist, $album, $track, $mbid);
// Scrobble! // Scrobble!
$mdb2->query("INSERT INTO Scrobbles (username, artist, track, time) VALUES (" $mdb2->query("INSERT INTO Scrobbles (username, artist, track, time, mbid) VALUES ("
. $username . ", " . $username . ", "
. $artist . ", " . $artist . ", "
. $track . ", " . $track . ", "
. $time . ")"); . $time . ", "
. $mbid . ")");
// Destroy now_playing since it is almost certainly obsolescent // Destroy now_playing since it is almost certainly obsolescent
$mdb2->query("DELETE FROM Now_Playing WHERE username = " . $username); $mdb2->query("DELETE FROM Now_Playing WHERE username = " . $username);
......
...@@ -26,7 +26,8 @@ class SubmissionsTest extends PHPUnit_Framework_TestCase ...@@ -26,7 +26,8 @@ class SubmissionsTest extends PHPUnit_Framework_TestCase
$session_id = trim($result[1]); $session_id = trim($result[1]);
$scrobble_server = trim($result[3]); $scrobble_server = trim($result[3]);
$result = $this->scrobble($scrobble_server, $session_id, "Richard Stallman", "The Free Software Song"); $result = $this->scrobble($scrobble_server, $session_id, "Richard Stallman",
"The Free Software Song", "b25b9595-54ed-7605-8ac2-20b7b2e0a026");
$this->assertEquals("OK", trim($result)); $this->assertEquals("OK", trim($result));
sleep(1); sleep(1);
} }
...@@ -38,7 +39,8 @@ class SubmissionsTest extends PHPUnit_Framework_TestCase ...@@ -38,7 +39,8 @@ class SubmissionsTest extends PHPUnit_Framework_TestCase
$session_id = trim($result[1]); $session_id = trim($result[1]);
$nowplaying_server = trim($result[2]); $nowplaying_server = trim($result[2]);
$result = $this->nowPlaying($nowplaying_server, $session_id, "The Libre.fm Players", "Let Freedom Ring"); $result = $this->nowPlaying($nowplaying_server, $session_id, "The Libre.fm Players", "Let Freedom Ring",
"b25b9595-54ed-7605-8ac2-20b7b2e0a026");
$this->assertEquals("OK", trim($result)); $this->assertEquals("OK", trim($result));
sleep(1); sleep(1);
} }
...@@ -61,13 +63,14 @@ class SubmissionsTest extends PHPUnit_Framework_TestCase ...@@ -61,13 +63,14 @@ class SubmissionsTest extends PHPUnit_Framework_TestCase
$r->addPostData('a[0]', $artist); $r->addPostData('a[0]', $artist);
$r->addPostData('t[0]', $track); $r->addPostData('t[0]', $track);
$r->addPostData('i[0]', time()); $r->addPostData('i[0]', time());
$r->addPostData('m[0]', $mbid);
$r->addPostData('o[0]', 'U'); $r->addPostData('o[0]', 'U');
$r->sendRequest(); $r->sendRequest();
return $r->getResponseBody(); return $r->getResponseBody();
} }
private function nowPlaying($server, $session_id, $artist, $track) { private function nowPlaying($server, $session_id, $artist, $track, $mbid) {
$r = new HTTP_Request($server); $r = new HTTP_Request($server);
$r->setMethod(HTTP_REQUEST_METHOD_POST); $r->setMethod(HTTP_REQUEST_METHOD_POST);
$r->addPostData('s', $session_id); $r->addPostData('s', $session_id);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment