summaryrefslogtreecommitdiffstats
path: root/lib/stream.lib.php
blob: 588f92519ebb4c6895d4a21066ce3efe1886ff2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/*

 Copyright 2001 - 2007 Ampache.org
 All Rights Reserved

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License v2
 as published by the Free Software Foundation.

 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 General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

/**
 * show_now_playing
 * shows the now playing template
 */
function show_now_playing() {

	// GC!
	Stream::gc_session(); 
	Stream::gc_now_playing();  

        $web_path = Config::get('web_path');
        $results = get_now_playing();
        require Config::get('prefix') . '/templates/show_now_playing.inc.php';

} // show_now_playing

/**
 * get_now_playing
 * gets the now playing information
 */
function get_now_playing($filter='') {

        $sql = "SELECT `session_stream`.`agent`,`now_playing`.`song_id`,`now_playing`.`user` FROM `now_playing` " . 
		"LEFT JOIN `session_stream` ON `session_stream`.`id`=`now_playing`.`id` " . 
		"ORDER BY `now_playing`.`expire` DESC";
        $db_results = Dba::query($sql);

        $results = array();

        /* While we've got stuff playing */
        while ($r = Dba::fetch_assoc($db_results)) {
                $song = new Song($r['song_id']);
                $song->format();
                $np_user = new User($r['user']);
                $results[] = array('song'=>$song,'user'=>$np_user,'agent'=>$r['agent']);
        } // end while

        return $results;

} // get_now_playing


/**
 * check_lock_songs
 * This checks to see if the song is already playing, if it is then it prevents the user
 * from streaming it
 */
function check_lock_songs($song_id) { 

	$sql = "SELECT `song_id` FROM `now_playing` " . 
		"WHERE `song_id` = '$song_id'";
	$db_results = Dba::query($sql);

	if (Dba::num_rows($db_results)) { 
		debug_event('lock_songs','Song Already Playing, skipping...','5'); 
		return false;
	}

	return true;

} // check_lock_songs

?>