File: xmms2_audacious2.ru_RU.UTF-8.php

package info (click to toggle)
eiskaltdcpp 2.2.9-4~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 20,676 kB
  • sloc: cpp: 94,106; ansic: 8,832; perl: 1,523; xml: 1,378; sh: 685; php: 661; makefile: 101
file content (164 lines) | stat: -rwxr-xr-x 4,295 bytes parent folder | download | duplicates (7)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/php5
<?php
/**
*
* @copyright (c) 2010 nE0sIghT
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @version 14.03.2010
*
* Depends: php5, xmms2 | audacious2
*
* Launching:
* /usr/share/eiskaltdcpp/examples/xmms2_audacious2.ru_RU.UTF-8.php audacious2
*
* Examples:
*
* output when playing local file:
* отрывается под Madonna - The Power of Good-Bye; Длина песни: 4:12; Уже прослушал: 2%
| <320kbps:44.1kHz> [Powered by Audacious 2.3-beta3 | GNU/Linux]
*
* output when playing radio:
* отрывается под WINTER, MARKUS - Electro Love Song @ recordradio.spb.ru |
<192kbps:44.1kHz> Радио: Record 192k MP3 | Адрес: http://radio.san.ru:8000/record
[Powered by Audacious 2.3-beta3 | GNU/Linux]
*
*/

$me = false; // Использовать +me

if($argc > 1)
	$player = $argv[1];
else
	$player = 'audacious2';

$status = 1;

switch($player)
{
	case 'xmms2':
		$player = 'XMMS2 0.5 DrLecter';

		$out = explode("\n", shell_exec('xmms2 info'));
		$data = array();
		foreach($out as $line)
		{
			$line = trim($line);
			if(empty($line))
				continue;
			list($param, $value) = explode(' = ', $line);
			list($category, $param) = explode(' ', $param);
			$category = explode('/', trim($category, "[] \n"));

			if(count($category) > 1)
				$data[$category[0]][$category[1]][$param] = $value;
			else
				$data[$category[0]][$param] = $value;
		}
		if(isset($data['plugin']['id3v2']['title']))
			$title = $data['plugin']['id3v2']['title'];
		else if(isset($data['plugin']['icymetaint']['title']))
			$title = $data['plugin']['icymetaint']['title'];
		else
			$title = basename($data['server']['url']);

		if(isset($data['plugin']['id3v2']['artist']))
			$title = $data['plugin']['id3v2']['artist'] . ' - ' . $title;

		if(isset($data['plugin']['mad']['duration']))
		{
			$duration = $data['plugin']['mad']['duration'] / 1000 / 60;
			$mins = floor($duration);
			$secs = $duration - $mins;
			$secs = sprintf('%02.0f', round($secs*60));
			$duration = $mins . ':' . $secs;

			$pass = round($data['plugin']['mad']['duration'] / 1000) - (time() - $data['server']['laststarted']);
		}
		else
			$duration = $pass = '';

		if(isset($data['plugin']['mad']))
		{
			$bitrate = round($data['plugin']['mad']['bitrate'] / 1000);
			$sample = $data['plugin']['mad']['samplerate'] / 1000;
		}
		else
			$bitrate = $sample = '';

		if(isset($data['plugin']['curl']['channel']))
		{
			$channel = $data['plugin']['curl']['channel'];
		}
		else
			$channel = '';
		break;
	case 'audacious2':
	default:
		switch(trim(shell_exec('audtool2 playback-status')))
		{
			case 'playing':
				$status = 1;
				break;
			case 'paused':
			case 'stoped':
				$status = 2;
				break;
			default:
				$status = 0;
				break;
		}

		$player = trim(preg_replace('/\[UNS.+\]/iuU', '', shell_exec('audacious2 --version')));

		$title = trim(shell_exec('audtool2 current-song'));
		$bitrate = trim(shell_exec('audtool2 current-song-bitrate-kbps'));
		$sample = trim(shell_exec('audtool2 current-song-frequency-khz'));

		$filename = trim(shell_exec('audtool2 current-song-filename'));
		if(strpos($filename, 'http') === 0)
		{
			$duration = $pass = '';
			$channel = trim(shell_exec('audtool2 current-song-tuple-data album'));
			$data['server']['url'] = $filename;
		}
		else
		{
			$duration = trim(shell_exec('audtool2 current-song-length'));
			$pass =  round((trim(shell_exec('audtool2 current-song-output-length-seconds') / trim(shell_exec('audtool2 current-song-length-seconds')))) * 100);
		}
		break;
}

if($status == 1)
{
	$return = $me ? '+me ' : '';
	$return .= 'отрывается под ' . $title;
	if(!empty($duration))
		$return .= '; Длина песни: ' . $duration;
	if(!empty($pass))
		$return .= '; Уже прослушал: ' . $pass . '%';

	if(!empty($bitrate))
		$return .= ' | <' . $bitrate . 'kbps:' . $sample . 'kHz>';

	if(!empty($channel))
		$return .= ' Радио: ' . $channel . ' | Адрес: ' . $data['server']['url'];

	$return .= " [Powered by $player | GNU/Linux]\n\n";
}
else
{
	switch($status)
	{
		case 2:
			$return = 'Проигрывание остановлено';
			break;
		case 0:
		default:
			$return = 'Аудиоплеер не запущен';
			break;
	}
}

echo $return;
?>