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);
29 addPreviousItem($listItems, $fullPath);
31 $it = $container->getItemIterator(false);
33 $hasFiles = $it->valid();
34 if ($hasFiles && is_array($mediatomb['singleFileDirectories'])) {
35 $enableSingle = false;
36 foreach ($mediatomb['singleFileDirectories'] as $dir) {
37 if (substr($fullPath, 0, strlen($dir)) == $dir) {
42 $listItems[] = getDirItem(
44 pathEncode('.mt-single/' . $path)
49 foreach ($container->getContainers() as $subContainer) {
50 $listItems[] = getDirItem(
52 pathEncode($fullPath . $subContainer->title) . '/'
56 foreach ($container->getItemIterator(false) as $item) {
57 mediatombAddFile($listItems, $item);
60 sendListItems($listItems);
63 function mediatombAddFile(&$listItems, $item)
67 $di = $item->getDetailedItem();
68 $itemUrl = $item->url;
69 if ($di->mimetype !== 'audio/mpeg') {
70 //noxon iRadio cube does not want to play .ogg files
71 $itemUrl = $host1 . 'transcode-nocache.php'
72 . '?url=' . urlencode($itemUrl);
74 $listItems[] = getEpisodeItem(
83 * Single file mode - shows directories that only have a single file in them.
84 * Each audio file gets its own virtual directory, containing only the
87 * Useful children who want to listen a single story before sleeping,
88 * but the noxon's auto switch-off timer is not exactly at the end of
89 * the story. So the next story starts already, and the kid complains
90 * that it wanted to listen to that as well...
92 function mediatombSingle(Services_MediaTomb $smt, $fullPath, $prefix)
94 $path = substr($fullPath, strlen($prefix));
96 $parts = explode('/', $path);
98 if (substr(end($parts), 0, 5) == 'file-') {
100 $fileTitle = substr(end($parts), 5);
101 $path = substr($path, 0, -strlen($fileTitle) - 5);
104 $container = $smt->getContainerByPath($path);
105 $listItems = array();
108 //show single file to play
109 addPreviousItem($listItems, pathEncode($fullPath));
110 $item = $smt->getSingleItem($container, $fileTitle, false);
111 mediatombAddFile($listItems, $item);
113 addPreviousItem($listItems, pathEncode('internetradio/' . $path . '/dummy'));
116 foreach ($container->getItemIterator(false) as $item) {
117 $listItems[] = getDirItem(
119 pathEncode($fullPath . 'file-' . $item->title)
124 sendListItems($listItems);