2 require_once 'Services/MediaTomb.php';
4 function handleMediatomb($action, $fullPath, $prefix)
10 $smt = new Services_MediaTomb($user, $pass, $host, $port);
11 if ($action == 'browse') {
12 mediatombBrowse($smt, $fullPath, $prefix);
13 } else if ($action == 'single') {
14 mediatombSingle($smt, $fullPath, $prefix);
16 } catch (Exception $e) {
17 sendMessage('Mediatomb error: ' . $e->getMessage());
22 function mediatombBrowse(Services_MediaTomb $smt, $fullPath, $prefix)
26 $path = substr($fullPath, strlen($prefix));
27 $container = $smt->getContainerByPath($path);
28 if ($container === null) {
29 sendMessage('Error accessing ' . $fullPath);
35 $it = $container->getItemIterator(false);
37 $hasFiles = $it->valid();
38 if ($hasFiles && is_array($mediatomb['singleFileDirectories'])) {
39 $enableSingle = false;
40 foreach ($mediatomb['singleFileDirectories'] as $dir) {
41 if (substr($fullPath, 0, strlen($dir)) == $dir) {
46 $listItems[] = getDirItem(
48 pathEncode('.mt-single/' . $path)
53 foreach ($container->getContainers() as $subContainer) {
54 $listItems[] = getDirItem(
56 pathEncode($fullPath . $subContainer->title) . '/'
60 foreach ($container->getItemIterator(false) as $item) {
61 mediatombAddFile($listItems, $item);
64 sendListItems($listItems, buildPreviousItem($fullPath));
67 function mediatombAddFile(&$listItems, $item)
71 $di = $item->getDetailedItem();
72 $itemUrl = $item->url;
73 if (!clientSupportsType($di->mimetype)) {
74 //client wants transcoded file
75 //noxon iRadio cube does not want to play .ogg files
76 if (isset($GLOBALS['cacheDir']) && $GLOBALS['cacheDir'] != '') {
77 $itemUrl = $host1 . 'transcode-cache.php'
78 . '?url=' . urlencode($itemUrl);
80 $itemUrl = $host1 . 'transcode-nocache.php'
81 . '?url=' . urlencode($itemUrl);
84 $listItems[] = getEpisodeItem(
92 function clientSupportsType($mimetype)
94 if ($mimetype === 'audio/mpeg') {
97 $ip = $_SERVER['REMOTE_ADDR'];
98 if (isset($GLOBALS['clientSupport'][$ip][$mimetype])
99 && $GLOBALS['clientSupport'][$ip][$mimetype] === true
107 * Single file mode - shows directories that only have a single file in them.
108 * Each audio file gets its own virtual directory, containing only the
111 * Useful children who want to listen a single story before sleeping,
112 * but the noxon's auto switch-off timer is not exactly at the end of
113 * the story. So the next story starts already, and the kid complains
114 * that it wanted to listen to that as well...
116 function mediatombSingle(Services_MediaTomb $smt, $fullPath, $prefix)
118 $path = substr($fullPath, strlen($prefix));
120 $parts = explode('/', $path);
122 if (substr(end($parts), 0, 5) == 'file-') {
124 $fileTitle = substr(end($parts), 5);
125 $path = substr($path, 0, -strlen($fileTitle) - 5);
128 $container = $smt->getContainerByPath($path);
129 $listItems = array();
133 //show single file to play
134 $previous = buildPreviousItem(pathEncode($fullPath));
135 $item = $smt->getSingleItem($container, $fileTitle, false);
136 mediatombAddFile($listItems, $item);
138 $previous = buildPreviousItem(pathEncode('internetradio/' . $path . '/dummy'));
141 foreach ($container->getItemIterator(false) as $item) {
142 $listItems[] = getDirItem(
144 pathEncode($fullPath . 'file-' . $item->title)
149 sendListItems($listItems, $previous);