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

index.php 2.68 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?php
/* GNUkebox -- a free software server for recording your listening habits

   Copyright (C) 2009 Free Software Foundation, Inc

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

19
 */
20

21 22
require_once($_SERVER['DOCUMENT_ROOT'] . '/config.php');
require_once($install_path . 'database.php');
23
require_once($install_path . 'scrobble-utils.php');
24
require_once($install_path . '1.x/auth-utils.php');
25 26 27 28 29 30 31

header('Content-Type: text/plain');

if (!isset($_POST['s']) || !isset($_POST['a']) || !isset($_POST['t'])) {
	die("FAILED Required POST parameters are not set\n");
}

32
$sessionid = trim($_POST['s']);
Jonas Haraldsson's avatar
Jonas Haraldsson committed
33
if (!check_session($sessionid)) {
34
	die("BADSESSION\n");
35 36
}

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
$t = array(
	'artist' => $_POST['a'],
	'track' => $_POST['t'],
	'album' => $_POST['b'],
	'tracknumber' => $_POST['n'],
	'mbid' => $_POST['m'],
	'duration' => $_POST['l'],
	'albumartist' => $albumartist
);

$t = prepareTrack($userid, $t, 'nowplaying');

// Delete last played track
$query = 'DELETE FROM Now_Playing WHERE sessionid = ?';
$params = array($sessionid);
try {
	$adodb->Execute($query, $params);
} catch (Exception $e) {}
55

56 57 58 59
// Calculate expiry time
if (!$t['duration'] || ($t['duration'] > 5400)) {
	// Default expiry time of 300 seconds if duration is false or above 5400 seconds
	$expires = time() + 300;
60
} else {
61
	$expires = time() + $t['duration'];
62 63
}

64 65 66 67 68 69 70 71 72
if ($t['ignored_code'] === 0) {
	// Clean up expired tracks in now_playing table
	$params = array(time());
	$query = 'DELETE FROM Now_Playing WHERE expires < ?';
	$adodb->Execute($query, $params);
		$adodb->StartTrans();
	try {
		// getTrackID will create the track in Track table if it doesnt exist
		getTrackID($t['artist'], $t['album'], $t['track'], $t['mbid'], $t['duration']);
Jonas Haraldsson's avatar
Jonas Haraldsson committed
73
		$params = array($sessionid, $t['track'], $t['artist'], $t['album'], $t['mbid'], $expires);
74 75
		$query = 'INSERT INTO Now_Playing(sessionid, track, artist, album, mbid, expires) VALUES (?,?,?,?,?,?)';
		$adodb->Execute($query, $params);
Jonas Haraldsson's avatar
Jonas Haraldsson committed
76
	} catch (Exception $e) {
77 78 79 80 81 82
		$adodb->FailTrans();
		$adodb->CompleteTrans();
		reportError($e->getMessage(), $e->getTraceAsString());
		die('FAILED');
	}
	$adodb->CompleteTrans();
83 84 85
}

die("OK\n");