|
@@ -31,6 +31,7 @@ import com.dmdirc.ui.interfaces.PreferencesPanel;
|
31
|
31
|
import com.dmdirc.util.Downloader;
|
32
|
32
|
|
33
|
33
|
import java.io.IOException;
|
|
34
|
+import java.io.File;
|
34
|
35
|
import java.net.MalformedURLException;
|
35
|
36
|
import java.util.HashMap;
|
36
|
37
|
import java.util.List;
|
|
@@ -70,15 +71,60 @@ public class VlcMediaSourcePlugin extends Plugin implements MediaSource, Prefere
|
70
|
71
|
/** {@inheritDoc} */
|
71
|
72
|
@Override
|
72
|
73
|
public String getArtist() {
|
73
|
|
- return information.containsKey("artist") ? information.get("artist")
|
|
74
|
+ String result = information.containsKey("artist") ? information.get("artist")
|
74
|
75
|
: "unknown";
|
|
76
|
+
|
|
77
|
+ // Artist is unknown, lets guess using the filename
|
|
78
|
+ if (result.equals("unknown") && information.containsKey("playlist_current")) {
|
|
79
|
+ try {
|
|
80
|
+ final int item = Integer.parseInt(information.get("playlist_current"));
|
|
81
|
+ String[] bits = information.get("playlist_item_"+item).split(File.separator);
|
|
82
|
+ result = bits[bits.length-1];
|
|
83
|
+ bits = result.split("-");
|
|
84
|
+ if (bits.length > 1) {
|
|
85
|
+ result = bits[0];
|
|
86
|
+ } else {
|
|
87
|
+ // Whole filename is the title, so no artist is known.
|
|
88
|
+ result = "";
|
|
89
|
+ }
|
|
90
|
+ } catch (NumberFormatException nfe) {
|
|
91
|
+ }
|
|
92
|
+ }
|
|
93
|
+ return result;
|
75
|
94
|
}
|
76
|
95
|
|
77
|
96
|
/** {@inheritDoc} */
|
78
|
97
|
@Override
|
79
|
98
|
public String getTitle() {
|
80
|
|
- return information.containsKey("title") ? information.get("title")
|
|
99
|
+ String result = information.containsKey("title") ? information.get("title")
|
81
|
100
|
: "unknown";
|
|
101
|
+
|
|
102
|
+ // Title is unknown, lets guess using the filename
|
|
103
|
+ if (result.equals("unknown") && information.containsKey("playlist_current")) {
|
|
104
|
+ try {
|
|
105
|
+ final int item = Integer.parseInt(information.get("playlist_current"));
|
|
106
|
+ String[] bits = information.get("playlist_item_"+item).split(File.separator);
|
|
107
|
+ result = bits[bits.length-1];
|
|
108
|
+ bits = result.split("-");
|
|
109
|
+ if (bits.length > 1) {
|
|
110
|
+ result = bits[1];
|
|
111
|
+ } else {
|
|
112
|
+ // Whole filename is the title, so result is already correct
|
|
113
|
+ }
|
|
114
|
+ // Now to remove the file extension
|
|
115
|
+ bits = result.split("\\.");
|
|
116
|
+ StringBuilder res = new StringBuilder();
|
|
117
|
+ for (int i = 0; i < bits.length-1; i++) {
|
|
118
|
+ if (res.length() > 0) {
|
|
119
|
+ res.append(".");
|
|
120
|
+ }
|
|
121
|
+ res.append(bits[i]);
|
|
122
|
+ }
|
|
123
|
+ result = res.toString();
|
|
124
|
+ } catch (NumberFormatException nfe) {
|
|
125
|
+ }
|
|
126
|
+ }
|
|
127
|
+ return result;
|
82
|
128
|
}
|
83
|
129
|
|
84
|
130
|
/** {@inheritDoc} */
|
|
@@ -197,10 +243,39 @@ public class VlcMediaSourcePlugin extends Plugin implements MediaSource, Prefere
|
197
|
243
|
}
|
198
|
244
|
}
|
199
|
245
|
|
|
246
|
+ boolean isPlaylist = false;
|
|
247
|
+ boolean isCurrent = false;
|
|
248
|
+ boolean isItem = false;
|
|
249
|
+ int playlistItem = 0;
|
200
|
250
|
for (String line : res2) {
|
201
|
251
|
final String tline = line.trim();
|
202
|
252
|
|
203
|
|
- if (tline.startsWith("State:")) {
|
|
253
|
+ if (isPlaylist) {
|
|
254
|
+ if (tline.startsWith("</ul>")) {
|
|
255
|
+ isPlaylist = false;
|
|
256
|
+ information.put("playlist_items", Integer.toString(playlistItem));
|
|
257
|
+ } else if (tline.equalsIgnoreCase("<strong>")) {
|
|
258
|
+ isCurrent = true;
|
|
259
|
+ } else if (tline.equalsIgnoreCase("</strong>")) {
|
|
260
|
+ isCurrent = false;
|
|
261
|
+ } else if (tline.startsWith("<a href=\"?control=play&")) {
|
|
262
|
+ isItem = true;
|
|
263
|
+ } else if (isItem) {
|
|
264
|
+ String itemname = tline;
|
|
265
|
+ if (itemname.endsWith("</a>")) {
|
|
266
|
+ itemname = itemname.substring(0, itemname.length()-4);
|
|
267
|
+ }
|
|
268
|
+ if (!itemname.equals("")) {
|
|
269
|
+ if (isCurrent) {
|
|
270
|
+ information.put("playlist_current", Integer.toString(playlistItem));
|
|
271
|
+ }
|
|
272
|
+ information.put("playlist_item_"+Integer.toString(playlistItem++), itemname);
|
|
273
|
+ }
|
|
274
|
+ isItem = false;
|
|
275
|
+ }
|
|
276
|
+ } else if (tline.equalsIgnoreCase("<!-- Playlist -->")) {
|
|
277
|
+ isPlaylist = true;
|
|
278
|
+ } else if (tline.startsWith("State:")) {
|
204
|
279
|
information.put("state", tline.substring(6, tline.indexOf('<')).trim());
|
205
|
280
|
} else if (tline.startsWith("got_")) {
|
206
|
281
|
final int equals = tline.indexOf('=');
|