|
@@ -0,0 +1,159 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
|
|
3
|
+ *
|
|
4
|
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+ * of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+ * in the Software without restriction, including without limitation the rights
|
|
7
|
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+ * copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+ * furnished to do so, subject to the following conditions:
|
|
10
|
+ *
|
|
11
|
+ * The above copyright notice and this permission notice shall be included in
|
|
12
|
+ * all copies or substantial portions of the Software.
|
|
13
|
+ *
|
|
14
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+ * SOFTWARE.
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+package com.dmdirc.addons.mediasource_mplayer;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.addons.nowplaying.MediaSource;
|
|
26
|
+import com.dmdirc.addons.nowplaying.MediaSourceState;
|
|
27
|
+import com.dmdirc.plugins.Plugin;
|
|
28
|
+
|
|
29
|
+import java.io.BufferedReader;
|
|
30
|
+import java.io.IOException;
|
|
31
|
+import java.io.InputStreamReader;
|
|
32
|
+import java.util.ArrayList;
|
|
33
|
+import java.util.List;
|
|
34
|
+
|
|
35
|
+/**
|
|
36
|
+ * Provides a media source for mplayer which uses lsof to hackily see what
|
|
37
|
+ * mplayer is currently accessing.
|
|
38
|
+ *
|
|
39
|
+ * @author chris
|
|
40
|
+ */
|
|
41
|
+public class MplayerMediaSourcePlugin extends Plugin implements MediaSource {
|
|
42
|
+
|
|
43
|
+ /**
|
|
44
|
+ * Creates a new instance of MplayerMediaSourcePlugin.
|
|
45
|
+ */
|
|
46
|
+ public MplayerMediaSourcePlugin() {
|
|
47
|
+ super();
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ /** {@inheritDoc} */
|
|
51
|
+ @Override
|
|
52
|
+ public void onLoad() {
|
|
53
|
+ // Nothing to do
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ /** {@inheritDoc} */
|
|
57
|
+ @Override
|
|
58
|
+ public void onUnload() {
|
|
59
|
+ // Nothing to do
|
|
60
|
+ }
|
|
61
|
+
|
|
62
|
+ /** {@inheritDoc} */
|
|
63
|
+ @Override
|
|
64
|
+ public MediaSourceState getState() {
|
|
65
|
+ if (getInfo().isEmpty()) {
|
|
66
|
+ return MediaSourceState.CLOSED;
|
|
67
|
+ } else {
|
|
68
|
+ return MediaSourceState.PLAYING;
|
|
69
|
+ }
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ /** {@inheritDoc} */
|
|
73
|
+ @Override
|
|
74
|
+ public String getAppName() {
|
|
75
|
+ return "MPlayer";
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ /** {@inheritDoc} */
|
|
79
|
+ @Override
|
|
80
|
+ public String getArtist() {
|
|
81
|
+ return "";
|
|
82
|
+ }
|
|
83
|
+
|
|
84
|
+ /** {@inheritDoc} */
|
|
85
|
+ @Override
|
|
86
|
+ public String getTitle() {
|
|
87
|
+ return getInfo().get(0);
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ /** {@inheritDoc} */
|
|
91
|
+ @Override
|
|
92
|
+ public String getAlbum() {
|
|
93
|
+ return "";
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ /** {@inheritDoc} */
|
|
97
|
+ @Override
|
|
98
|
+ public String getLength() {
|
|
99
|
+ return "";
|
|
100
|
+ }
|
|
101
|
+
|
|
102
|
+ /** {@inheritDoc} */
|
|
103
|
+ @Override
|
|
104
|
+ public String getTime() {
|
|
105
|
+ return "";
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ /** {@inheritDoc} */
|
|
109
|
+ @Override
|
|
110
|
+ public String getFormat() {
|
|
111
|
+ return "";
|
|
112
|
+ }
|
|
113
|
+
|
|
114
|
+ /** {@inheritDoc} */
|
|
115
|
+ @Override
|
|
116
|
+ public String getBitrate() {
|
|
117
|
+ return "";
|
|
118
|
+ }
|
|
119
|
+
|
|
120
|
+ /**
|
|
121
|
+ * Retrieves information about the currently playing track.
|
|
122
|
+ *
|
|
123
|
+ * @return Information about the currently playing track
|
|
124
|
+ */
|
|
125
|
+ public static List<String> getInfo() {
|
|
126
|
+ final ArrayList<String> result = new ArrayList<String>();
|
|
127
|
+
|
|
128
|
+ InputStreamReader reader;
|
|
129
|
+ BufferedReader input;
|
|
130
|
+ Process process;
|
|
131
|
+
|
|
132
|
+ try {
|
|
133
|
+ final String[] command = new String[]{"/bin/bash", "-c",
|
|
134
|
+ "/usr/bin/lsof -c gmplayer |" +
|
|
135
|
+ " grep -Ev '/dev|/lib|/var|/usr|/SYS|DIR|/tmp|pipe|socket|" +
|
|
136
|
+ "\\.xession|fontconfig' | tail -n 1 | sed -r 's/ +/ /g' |" +
|
|
137
|
+ " cut -d ' ' -f 9- | sed -r 's/^.*\\/(.*?)$/\\1/'"};
|
|
138
|
+ process = Runtime.getRuntime().exec(command);
|
|
139
|
+
|
|
140
|
+ reader = new InputStreamReader(process.getInputStream());
|
|
141
|
+ input = new BufferedReader(reader);
|
|
142
|
+
|
|
143
|
+ String line = "";
|
|
144
|
+
|
|
145
|
+ while ((line = input.readLine()) != null) {
|
|
146
|
+ result.add(line);
|
|
147
|
+ }
|
|
148
|
+
|
|
149
|
+ reader.close();
|
|
150
|
+ input.close();
|
|
151
|
+ process.destroy();
|
|
152
|
+ } catch (IOException ex) {
|
|
153
|
+ ex.printStackTrace();
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ return result;
|
|
157
|
+ }
|
|
158
|
+
|
|
159
|
+}
|