summaryrefslogtreecommitdiff
path: root/genplaylist.php
blob: a30333d648cf27912156eeecd1b1b3cbcf39dba9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
	header('Content-Type: text/xml'); 
	echo "<?xml version=\"1.0\"?>\n";
	echo "<status>\n";

	$path = $_REQUEST['path'];
	$name = $_REQUEST['name'];

        exec('rm playlist/*');
        exec('ln -s ' .addcslashes(quotemeta($path), " &") .'* playlist');

	$dir_handle = @opendir($path);
	if (!$dir_handle)
		echo "<m3u>error</m3u>";
	else
	{
		$found = 0;
		while ($medianame = readdir($dir_handle))
		{
			if (mediagettype($path .$medianame) == 2)
			{
				if ($medianame == $name)
					$found = 1;		
		
				if ($found)
				        $medianame_array[] = $medianame;
			}
		}

		if ($medianame_array[0])
		{
	
			// Alphabetical sorting
			sort($medianame_array);

			$plfile = fopen("playlist/playlist.m3u", 'w');
			if (!$plfile)
				echo "<m3u>error</m3u>";
			else
			{
				$count = count($medianame_array);
				for ($cnt=0; $cnt < $count; $cnt++)
        				fwrite($plfile, "playlist/" .$medianame_array[$cnt] ."\n");

			        fclose($plfile);
	
				echo "<m3u>ok</m3u>\n";
			}
		}
		else
			echo "<m3u>error</m3u>";
	}

	echo "</status>\n";

?>