e582a46764cd875956b6a12ec66105b5367446b6
[noxon-gateway.git] / src / mediatomb.php
1 <?php
2 require_once 'Services/MediaTomb.php';
3
4 function handleRequestMediatomb($fullPath, $prefix)
5 {
6     global $mediatomb, $host1;
7
8     extract($mediatomb);
9     try {
10         $smt = new Services_MediaTomb($user, $pass, $host, $port);
11
12         $path = substr($fullPath, strlen($prefix));
13         $container = $smt->getContainerByPath($path);
14         $listItems = array();
15         addPreviousItem($listItems, $fullPath);
16
17         foreach ($container->getContainers() as $subContainer) {
18             $listItems[] = getDirItem(
19                 $subContainer->title,
20                 pathEncode($fullPath . $subContainer->title) . '/'
21             );
22         }
23
24         foreach ($container->getItemIterator(false) as $item) {
25             $di = $item->getDetailedItem();
26             $itemUrl = $item->url;
27             if ($di->mimetype !== 'audio/mpeg') {
28                 //noxon iRadio cube does not want to play .ogg files
29                 $itemUrl = $host1 . 'transcode-nocache.php'
30                     . '?url=' . urlencode($itemUrl);
31             }
32             $listItems[] = getEpisodeItem(
33                 $item->title,
34                 $itemUrl,
35                 '',
36                 'MP3'
37             );
38         }
39     } catch (Exception $e) {
40         sendMessage('Mediatomb error: ' . $e->getMessage());
41         return;
42     }
43
44     sendListItems($listItems);
45 }
46 ?>