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

musicbrainz.php 2.53 KB
Newer Older
1
<?php
2
/* GNUkebox -- a free software server for recording your listening habits
3

4
   Copyright (C) 2009 Free Software Foundation, Inc
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

   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/>.

*/

21 22 23
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
@ini_set('implicit_flush', 1);
24 25

header('Content-type: text/html; charset=utf-8');
clint's avatar
clint committed
26
require_once('database.php');
27 28
require_once('utils/human-time.php');

29
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
30
$res = $adodb->GetAll('SELECT artist, track from Scrobbles where album is null LIMIT 20;');
31

32
echo '<ul>';
33

34 35 36 37
if (!$res) {
	die('sql error');
}
foreach ($res as &$row) {
38

39
	echo '<li>' . $row['artist'] . '&mdash;' . $row['track'] . '</li>';
40

41
	echo 'Finding album...';
42

43
	echo doABunchOfShit($row['artist'], $row['track']);
44

45 46 47 48
	for ($i = 0; $i < ob_get_level(); $i++) {
		ob_end_flush();
	}
	ob_implicit_flush(1);
clint's avatar
clint committed
49

50
}
51

52
function doABunchOfShit($artist, $track) {
53 54 55

	 $album = ScrobbleLookup($artist, $track);

56 57
	 if ($album) {
		 return $album;
58
	 } else {
59 60 61
		 $album = BrainzLookup($artist, $track);
		 return $album;
	 }
clint's avatar
clint committed
62

63 64
}

65
function ScrobbleLookup($artist, $track) {
clint's avatar
clint committed
66
	global $adodb;
67

68
	$sql = 'SELECT album from Scrobbles where artist = ' . $adodb->qstr($artist) . ' and track = ' . $adodb->qstr($track) . ' LIMIT 1;';
69

clint's avatar
clint committed
70 71
	$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
	$album = $adodb->GetOne($sql);
72

73 74
	if (!$album) {
		die('sql error');
clint's avatar
clint committed
75
	}
76

clint's avatar
clint committed
77
	return $album;
78 79
}

80
function BrainzLookup($artist, $track) {
81

clint's avatar
clint committed
82
	global $adodb;
83

84
	$sql = 'select a.name as artist,l.name as album, t.name as track,t.gid as mbid from brainz.track t left join brainz.artist a on t.artist=a.id left join brainz.albumjoin j on j.track=t.id left join brainz.album l on l.id=j.album where lower(t.name) = lower(' . $adodb->qstr($track) . ') and lower(a.name) = lower(' . $adodb->qstr($artist) . ') LIMIT 1;';
clint's avatar
clint committed
85

clint's avatar
clint committed
86 87
	$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
	$albumData = $adodb->GetRow($sql);
88

89 90
	if (!$albumData)) {
		die('sql error');
clint's avatar
clint committed
91
	}
92

clint's avatar
clint committed
93
	return $albumData['album'];
94
}
95
?>
96
		</ul>