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

xspf.php 4.35 KB
Newer Older
1
<?php
2
/* GNU FM -- a free network service for sharing your music 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
require_once('../database.php');
22
require_once('../templating.php');
23
require_once('../data/Track.php');
24
require_once('../data/Server.php');
25
require_once('../utils/resolve-external.php');
26
require_once('radio-utils.php');
27

clint's avatar
clint committed
28 29
// These deaths should probably just return an empty playlist

30
if(!isset($_GET['sk']) || !isset($_GET['desktop'])) {
clint's avatar
clint committed
31
	die("BADSESSION\n"); // this should return a blank dummy playlist instead
32 33
}

34
$session = $_GET['sk'];
35

Mike Sheldon's avatar
Mike Sheldon committed
36
$row = $adodb->GetRow('SELECT username, url FROM Radio_Sessions WHERE session = ' . $adodb->qstr($session));
37

Mike Sheldon's avatar
Mike Sheldon committed
38
if(!$row) {
clint's avatar
clint committed
39
	die("BADSESSION\n"); // this should return a blank dummy playlist instead
40 41
}

42
$user = new User($row['username']);
43

44
$url = $row['url'];
45 46

$title = radio_title_from_url($url);
47
$smarty->assign('title', $title);
48

49
if(ereg('l(ast|ibre)fm://globaltags/(.*)', $url, $regs)) {
clint's avatar
clint committed
50
	$tag = $regs[2];
51
	$res = $adodb->Execute('SELECT Track.name, Track.artist_name, Track.album_name, Track.duration, Track.streamurl FROM Track INNER JOIN Tags ON Track.name=Tags.track AND Track.artist_name=Tags.artist AND Track.album_name=Tags.album WHERE streamurl<>\'\' AND streamable=1 AND lower(tag) = ' . $adodb->qstr(mb_strtolower($tag, 'UTF-8')));
52
} elseif(ereg('l(ast|ibre)fm://artist/(.*)/similarartists', $url, $regs)) {
clint's avatar
clint committed
53
	$artist = $regs[2];
54
	$res = $adodb->Execute('SELECT name, artist_name, album_name, duration, streamurl FROM Track WHERE streamurl<>\'\' AND streamable=1 AND lower(artist_name) = ' . $adodb->qstr(mb_strtolower($artist, 'UTF-8')));
55
} elseif(ereg('l(ast|ibre)fm://user/(.*)/loved', $url, $regs)) {
56 57
	$requser = new User($regs[2]);
	$res = $adodb->Execute('SELECT Track.name, Track.artist_name, Track.album_name, Track.duration, Track.streamurl FROM Track INNER JOIN Loved_Tracks ON Track.artist_name=Loved_Tracks.artist AND Track.name=Loved_Tracks.track WHERE Loved_Tracks.userid=' . $requser->uniqueid . ' AND Track.streamurl<>\'\' AND Track.streamable=1');
clint's avatar
clint committed
58
} else {
clint's avatar
clint committed
59
	die("FAILED\n"); // this should return a blank dummy playlist instead
clint's avatar
clint committed
60 61
}

clint's avatar
clint committed
62
$avail = $res->RecordCount();
clint's avatar
clint committed
63

clint's avatar
clint committed
64 65 66 67 68
$tr[0] = rand(0,$avail-1);
$tr[1] = rand(0,$avail-1);
$tr[2] = rand(0,$avail-1);
$tr[3] = rand(0,$avail-1);
$tr[4] = rand(0,$avail-1);
69
$tr = array_unique($tr);
clint's avatar
clint committed
70
// we should probably shuffle these here
clint's avatar
clint committed
71

72
$radiotracks = array();
clint's avatar
clint committed
73
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
74

75
for($i=0; $i<count($tr); $i++) {
clint's avatar
clint committed
76

clint's avatar
clint committed
77
	$res->Move($tr[$i]);
clint's avatar
clint committed
78
	$row = $res->FetchRow();
79

80 81 82 83 84 85 86 87 88 89
	$banres = $adodb->Execute('SELECT COUNT(*) FROM Banned_Tracks WHERE '
		. 'artist = ' . $adodb->qstr($row['artist_name'])
		. 'AND track = ' . $adodb->qstr($row['name'])
		. 'AND userid = ' . $user->uniqueid);
	if ($banres->RecordCount() > 0) {
		// This track has been banned by the user, so select another one
		$i--;
		continue;
	}

90
	$album = new Album($row['album_name'], $row['artist_name']);
91

92
	if($row['duration'] == 0) {
clint's avatar
clint committed
93 94
		$duration = 180000;
	} else {
95
		$duration = $row['duration'] * 1000;
96 97
	}

98
	$radiotracks[$i]['location'] = resolve_external_url($row['streamurl']);
99
	$radiotracks[$i]['title'] = $row['name'];
100 101
	$radiotracks[$i]['id'] = "0000";
	$radiotracks[$i]['album'] = $album->name;
102
	$radiotracks[$i]['creator'] = $row['artist_name'];
103 104
	$radiotracks[$i]['duration'] = $duration;
	$radiotracks[$i]['image'] = $album->image;
105
	$radiotracks[$i]['artisturl'] = Server::getArtistURL($row['artist_name']);
106
	$radiotracks[$i]['albumurl'] = $album->getURL();
107 108
	$radiotracks[$i]['trackurl'] = Server::getTrackURL($row['artist_name'], $album->name, $row['track_name']);
	$radiotracks[$i]['downloadurl'] = Server::getTrackURL($row['artist_name'], $album->name, $row['track_name']);
109

110
}
111

112 113
$smarty->assign('radiotracks', $radiotracks);

114
$smarty->display('radio_oldxspf.tpl');
115

116
?>