2 require_once 'Services/MediaTomb.php';
4 function handleRequestMediatomb($fullPath, $prefix)
6 global $mediatomb, $host1;
10 $smt = new Services_MediaTomb($user, $pass, $host, $port);
12 $path = substr($fullPath, strlen($prefix));
13 $container = $smt->getContainerByPath($path);
15 addPreviousItem($listItems, $fullPath);
17 foreach ($container->getContainers() as $subContainer) {
18 $listItems[] = getDirItem(
20 pathEncode($fullPath . $subContainer->title) . '/'
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'
30 . '?mtParentId=' . $container->id
31 . '&mtItemTitle=' . urlencode($item->title);
33 $listItems[] = getEpisodeItem(
40 } catch (Exception $e) {
41 sendMessage('Mediatomb error: ' . $e->getMessage());
45 sendListItems($listItems);
48 function transcodeMediatombItem($parentId, $title)
50 global $mediatomb, $host1, $cacheDir, $cacheDirUrl;
52 if (!is_writable($cacheDir)) {
53 sendMessage('Cache dir not writable');
59 $smt = new Services_MediaTomb($user, $pass, $host, $port);
60 $item = $smt->getSingleItem((int) $parentId, $title, false);
62 $filename = $item->id . '.mp3';
63 $cacheFilePath = $cacheDir . $filename;
64 if (!file_exists($cacheFilePath)) {
65 transcodeUrlToMp3($item->url, $cacheFilePath);
67 if (!file_exists($cacheFilePath)) {
68 sendMessage('Error: No mp3 file found');
71 $cacheFileUrl = $cacheDirUrl . $filename;
72 header('Location: ' . $cacheFileUrl);
73 } catch (Exception $e) {
74 sendMessage('Mediatomb error: ' . $e->getMessage());
78 function transcodeUrlToMp3($url, $mp3CacheFilePath)
80 $tmpfile = tempnam(sys_get_temp_dir(), 'transcode');
83 . escapeshellarg($url)
84 . ' -O ' . escapeshellarg($tmpfile),
89 throw new Exception('Error downloading URL');
94 . ' -i ' . escapeshellarg($tmpfile)
95 . ' ' . escapeshellarg($mp3CacheFilePath)
102 if (file_exists($mp3CacheFilePath)) {
103 unlink($mp3CacheFilePath);
105 //var_dump($tmpfile, $output);
106 throw new Exception('Error transcoding file');