summaryrefslogtreecommitdiff
path: root/includes/inc_files.php
blob: c3cda85775bbed5fa166e39427f9df43b76614bc (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php

$audiotypes='mp3 aac wav ';

function mediagetinfostream($stream = "")
{
	global $ffmpegpath;

	// Get info
	$getid3 = new getID3;
	$fileinfo = $getid3->analyze($stream);

	$title = "Media:";
	$info = "Duration: <i>" .sec2hms($fileinfo['playtime_seconds']) ."</i><br>";
	if ($fileinfo['fileformat'])
		$info .= "Format: <i>" .$fileinfo['fileformat'] ."</i><br>";
	if ($fileinfo['video']['codec'])
		$info .= "Video: <i>" .$fileinfo['video']['codec'] ."</i><br>";
	if ($fileinfo['audio']['codec'])
		$info .= "Audio: <i>" .$fileinfo['audio']['codec'] ."</i><br>";
	if ($fileinfo['video']['resolution_x'])
		$info .= "Resolution: <i>" .$fileinfo['video']['resolution_x'] ."x" .$fileinfo['video']['resolution_y'] ."</i><br>";

	// Extract a thumbnail
	exec("rm ram/stream-tb.*");
	$path = dirname($stream);

	if (file_exists(substr($stream, 0, -4) .".tbn"))
		$file = substr($stream, 0, -4) .".tbn";
	else if (file_exists($path ."/poster.jpg"))
		$file = $path ."/poster.jpg";
	else if (file_exists($path ."/folder.jpg"))
		$file = $path ."/folder.jpg";
	else
		$file = "";

	$resx = 180;
	$resy = 100;

	if ($file)
	{
                $getid3 = new getID3;
		$fileinfo = $getid3->analyze($file);
	}
	
	if ($fileinfo['video']['resolution_y'] && $fileinfo['video']['resolution_x'])
	{
		if ($fileinfo['video']['resolution_y'] < $fileinfo['video']['resolution_x'])
		{
			$resx = 180;
			$resy = round(($fileinfo['video']['resolution_y'] * 180) / $fileinfo['video']['resolution_x']);
		}
		else
		{
			$resx = round (($fileinfo['video']['resolution_x'] * 100) / $fileinfo['video']['resolution_y']);
			$resy = 100;
		}
	}


	if ($file)
		exec("cp \"" .$file ."\" ram/stream-tb-tmp.jpg;  " .$ffmpegpath ." -y -i ram/stream-tb-tmp.jpg -s " .$resx ."x" .$resy ." ram/stream-tb.jpg");
	else
	        exec($ffmpegpath ." -y -i \"" .$stream ."\" -an -ss 00:00:05.00 -r 1 -vframes 1 -s " .$resx ."x" .$resy ." -f mjpeg ram/stream-tb.png");
	
	return array($title, $info);
}

function mediagetwidth($file)
{

	$getid3 = new getID3;
	$fileinfo = $getid3->analyze($file);

	return $fileinfo['video']['resolution_x'];
}

function mediagettype($file)
{
	global $videotypes, $audiotypes;

	// Get file extension
	$fileext = end(explode(".", $file));

	if (is_dir($file))
		return 3;
	if (preg_match("/" .$fileext ." /", $videotypes))
		return 1;
	else if (preg_match("/" .$fileext ." /", $audiotypes))
		return 2;
	else
		return 0;
}

function mediadirhasaudio($dir)
{
	global $audiotypes;

	$audioextarray = explode(' ', $audiotypes);

	foreach ($audioextarray as $num => $audioext)
	{
        	if (glob($dir .'*.' .$audioext))
			return 1;
	}

	return 0;
}

function mediagetmusicinfo($file ="")
{
	// Get info
	$getid3 = new getID3;
	$fileinfo = $getid3->analyze($file);

	$name = $fileinfo['tags']['id3v2']['title'][0];
	if ($name == "")
	{
		$name = $fileinfo['tags']['id3v1']['title'][0];
		if ($name == "")
		{
			$name = $fileinfo['filename'];
			if ($name == "")
				$name = "unknown";
		}
	}

	if (!is_utf8($name))
		$name = utf8_encode($name);

	$duration = $fileinfo['playtime_string'];

	return array ($name, $duration);
}