forked from bjdodson/jinzora
-
Notifications
You must be signed in to change notification settings - Fork 14
/
mediabroadcast.php
191 lines (167 loc) · 5.6 KB
/
mediabroadcast.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php define('JZ_SECURE_ACCESS','true');
/**
* - JINZORA | Web-based Media Streamer -
*
* Jinzora is a Web-based media streamer, primarily desgined to stream MP3s
* (but can be used for any media file that can stream from HTTP).
* Jinzora can be integrated into a CMS site, run as a standalone application,
* or integrated into any PHP website. It is released under the GNU GPL.
*
* - Resources -
* - Jinzora Author: Ross Carlson <ross@jasbone.com>
* - Web: http://www.jinzora.org
* - Documentation: http://www.jinzora.org/docs
* - Support: http://www.jinzora.org/forum
* - Downloads: http://www.jinzora.org/downloads
* - License: GNU GPL <http://www.gnu.org/copyleft/gpl.html>
*
* - Contributors -
* Please see http://www.jinzora.org/team.html
*
* - Code Purpose -
* - This page handles requests to stream all types of files (images,media,zip)
*
* @since 01.11.05
* @author Ross Carlson <ross@jinzora.org>
* @author Ben Dodson <ben@jinzora.org>
* @author Chris Hescott
*/
$include_path = '';
/* Session name separate from one used in index.php
* This one is embedded in the URL sent in the playlist
*/
session_name('jza');
session_start();
// Let's set the error reporting level
@error_reporting(E_ERROR);
include_once('system.php');
@include_once('settings.php');
include_once('backend/backend.php');
include_once('playlists/playlists.php');
include_once('lib/general.lib.php');
include_once('lib/jzcomp.lib.php');
include_once('services/class.php');
$ssid = strip_tags(SID);
writeLogData("as_debug","mediabroadcast: SID = ". $ssid);
// Let's setup the services
$jzSERVICES = new jzServices();
$jzSERVICES->loadStandardServices();
// Now let's see if we need to split the URL apart
if (isset($_SERVER['PATH_INFO'])){
// Ok, now we need to get the variables
$vars = substr($_SERVER['PATH_INFO'],1);
$vArr = explode("&",$vars);
foreach($vArr as $item){
// Now let's split that out
$iArr = explode("=",$item);
// Now let's set the variables
$_GET[$iArr[0]] = $iArr[1];
}
}
// Let's clean up the get vars
$_GET = unurlize($_GET);
// Let's get the user ID
$uid = (isset($_GET['jz_user'])) ? $_GET['jz_user'] : false;
if (false === $uid || $uid == ""){ exit(); }
// Let's setup the new user
$jzUSER = new jzUser(false,$uid);
// ACTIONS:
// play [for on-the-fly, basic playlist generation]
// -path
// -limit (default max_playlist_length)
// -type (specify the type of the path: track|node|playlist; default is to assume node.)
// -resample (NOT IMPLEMENTED)
//
// download [downloading tracks/nodes/playlist] (NOT IMPLEMENTED)
// -path
// -type (is this a track or a node? default: assume node.)
// -playlist (if this is set, ignore path)
//
// image [for displaying images; this makes it possible for images to not be in the webroot]
// -path (image path)
//
// The following are for GD-based resizing, NOT HTML tag resizing:
// -width (resize the width)
// -height (resize the height)
// -constrain (constrained resize)
if (!isset($_GET['action'])) $_GET['action'] = "play";
// Handle $resample
$resample = (isset($_GET['resample'])) ? $_GET['resample'] : false;
if ($jzUSER->getSetting('resample_lock')){
$resample = $jzUSER->getSetting('resample_rate');
}
if (isset($no_resample_subnets) && $no_resample_subnets <> "" && preg_match("/^${no_resample_subnets}$/", $_SERVER['REMOTE_ADDR'])) {
$resample = false;
}
switch ($_GET['action']) {
// play a track:
case "play":
if (!(isset($_GET['jz_path']) || isset($_GET['file'])))
exit();
// send file directly, not with path:
if (isset($_GET['file'])) {
if (preg_match("/\.($audio_types)$/i", $_GET['fname'])) {
sendMedia($_GET['file'],$_GET['fname'],$resample);
}
exit();
} else {
$be = new jzBackend();
$el = &new jzMediaTrack($_GET['jz_path'],"id");
if ($jzUSER->getSetting('force_clips')){
$_GET['cl'] = true;
}
if (isset($_GET['cl'])) {
// Send a clip
$meta = $el->getMeta();
$title = $meta['artist'] . " - " . $el->getName();
sendClip($el);
exit();
}
// Is the track locked/do they have permission?
if (!canPlay($el,$jzUSER)) {
sendMedia("playlists/messages/media-locked.mp3",word("Track Locked"));
exit();
}
// Have they reached their limit?
if (!checkStreamLimit($el)){
sendMedia("playlists/messages/streaming-limit-exceeded.mp3",word("Limit Reached"));
exit();
}
if (!isset($_GET['sid'])) {
$_GET['sid'] = "none";
}
if (!isset($_SERVER['HTTP_RANGE'])) {
// Now let's update the playcount
if ($be->allowPlaycountIncrease($_GET['jz_user'],$el,$_GET['sid']) !== false) {
$el->increasePlayCount();
}
// Now let's update audioscrobbler
$el->setStartTime(time());
if ($enable_audioscrobbler == "true"){
$jzSERVICES->loadService("reporting","audioscrobbler");
$jzSERVICES->updatePlayCountReporting($el);
}
}
$meta = $el->getMeta();
if ($meta['artist'] <> "" and $meta['artist'] <> "-"){
$title = $meta['artist'] . " - " . $el->getName();
} else {
$title = $el->getName();
}
if (isset($_GET['jz_user'])) {
$be->setPlaying($_GET['jz_user'],$el,$_GET['sid']);
}
session_write_close(); // Close session while file is streaming
sendMedia($el->getFileName("host"),$title, $resample);
}
exit();
break;
// download a collection of media:
case "image":
if (preg_match("/\.($ext_graphic)$/i", $_GET['jz_path'])) {
showImage($_GET['jz_path']);
}
exit();
break;
}
?>