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);
30 $it = $container->getItemIterator(false);
32 $hasFiles = $it->valid();
33 if ($hasFiles && is_array($mediatomb['singleFileDirectories'])) {
34 $enableSingle = false;
35 foreach ($mediatomb['singleFileDirectories'] as $dir) {
36 if (substr($fullPath, 0, strlen($dir)) == $dir) {
41 $listItems[] = getDirItem(
43 pathEncode('.mt-single/' . $path)
48 foreach ($container->getContainers() as $subContainer) {
49 $listItems[] = getDirItem(
51 pathEncode($fullPath . $subContainer->title) . '/'
55 foreach ($container->getItemIterator(false) as $item) {
56 mediatombAddFile($listItems, $item);
59 sendListItems($listItems, buildPreviousItem($fullPath));
62 function mediatombAddFile(&$listItems, $item)
66 $di = $item->getDetailedItem();
67 $itemUrl = $item->url;
68 if (!clientSupportsType($di->mimetype)) {
69 //client wants transcoded file
70 //noxon iRadio cube does not want to play .ogg files
71 $itemUrl = $host1 . 'transcode-nocache.php'
72 . '?url=' . urlencode($itemUrl);
74 $listItems[] = getEpisodeItem(
82 function clientSupportsType($mimetype)
84 if ($mimetype === 'audio/mpeg') {
87 $ip = $_SERVER['REMOTE_ADDR'];
88 if (isset($GLOBALS['clientSupport'][$ip][$mimetype])
89 && $GLOBALS['clientSupport'][$ip][$mimetype] === true
97 * Single file mode - shows directories that only have a single file in them.
98 * Each audio file gets its own virtual directory, containing only the
101 * Useful children who want to listen a single story before sleeping,
102 * but the noxon's auto switch-off timer is not exactly at the end of
103 * the story. So the next story starts already, and the kid complains
104 * that it wanted to listen to that as well...
106 function mediatombSingle(Services_MediaTomb $smt, $fullPath, $prefix)
108 $path = substr($fullPath, strlen($prefix));
110 $parts = explode('/', $path);
112 if (substr(end($parts), 0, 5) == 'file-') {
114 $fileTitle = substr(end($parts), 5);
115 $path = substr($path, 0, -strlen($fileTitle) - 5);
118 $container = $smt->getContainerByPath($path);
119 $listItems = array();
123 //show single file to play
124 $previous = buildPreviousItem(pathEncode($fullPath));
125 $item = $smt->getSingleItem($container, $fileTitle, false);
126 mediatombAddFile($listItems, $item);
128 $previous = buildPreviousItem(pathEncode('internetradio/' . $path . '/dummy'));
131 foreach ($container->getItemIterator(false) as $item) {
132 $listItems[] = getDirItem(
134 pathEncode($fullPath . 'file-' . $item->title)
139 sendListItems($listItems, $previous);