Commit f496e3d8bec45029a741ac02a8ded902d574abbc
1 parent
9f55b1da
Bugs arreglados, mayor estabilidad y mas robustez
Showing
2 changed files
with
71 additions
and
20 deletions
src/com/upc/pbe/upcnews/ParentList.java
... | ... | @@ -9,11 +9,10 @@ public class ParentList |
9 | 9 | private String Type, Name; |
10 | 10 | private boolean Default; //Estos 3 últimos son para los ext-x-media, los ext-x-stream lo IGNORAN |
11 | 11 | private ArrayList<List> lists; //per cada qualitat |
12 | - private boolean validated; | |
12 | + | |
13 | 13 | |
14 | 14 | public ParentList(String ID) |
15 | 15 | { |
16 | - validated = false; | |
17 | 16 | this.ID = ID; |
18 | 17 | currentQuality = 0; |
19 | 18 | Type = ""; |
... | ... | @@ -21,17 +20,7 @@ public class ParentList |
21 | 20 | Default = false; |
22 | 21 | lists = new ArrayList<List>(); //Lista de CALIDADES |
23 | 22 | } |
24 | - | |
25 | - public void setValidated(boolean val) | |
26 | - { | |
27 | - validated = val; | |
28 | - } | |
29 | - | |
30 | - public boolean getValidated() | |
31 | - { | |
32 | - return validated; | |
33 | - } | |
34 | - | |
23 | + | |
35 | 24 | public String getID() |
36 | 25 | { |
37 | 26 | return ID; | ... | ... |
src/com/upc/pbe/upcnews/Parser.java
... | ... | @@ -18,6 +18,7 @@ public class Parser |
18 | 18 | private boolean expectList = false; |
19 | 19 | private Descarrega download; |
20 | 20 | private Activity caller; //Where to send notifications and warnings |
21 | + private boolean validated; //Wether if list starts with #EXTM3U or not | |
21 | 22 | |
22 | 23 | public Parser(String p,Activity caller) |
23 | 24 | { |
... | ... | @@ -33,6 +34,7 @@ public class Parser |
33 | 34 | * 1 indicates MEDIA |
34 | 35 | */ |
35 | 36 | download = new Descarrega(); |
37 | + validated = false; | |
36 | 38 | } |
37 | 39 | |
38 | 40 | public ArrayList<ParentList> parseFile(String file) throws ErrorException, WarningException, InfoException |
... | ... | @@ -138,11 +140,11 @@ public class Parser |
138 | 140 | { |
139 | 141 | ParentList ppls = lists.get(currentList); |
140 | 142 | List pls = ppls.getLists().get(ppls.getLists().size()-1); |
141 | - if(!ppls.getValidated()) | |
143 | + if(!validated) | |
142 | 144 | { |
143 | 145 | if(line.equals(STARTWORD)) |
144 | 146 | { |
145 | - ppls.setValidated(true); | |
147 | + validated = true; | |
146 | 148 | } |
147 | 149 | else |
148 | 150 | { |
... | ... | @@ -221,6 +223,31 @@ public class Parser |
221 | 223 | for(int i = 0; i < arguments.length; i++) |
222 | 224 | { |
223 | 225 | String[] argument = arguments[i].split("="); |
226 | + /* | |
227 | + * In case current argument contains several values like "val1,val2,val3" | |
228 | + * detect the " character and merge them all in one single string | |
229 | + */ | |
230 | + if(argument[1].startsWith("\"") && !argument[1].endsWith("\"")) | |
231 | + { | |
232 | + int j = i; | |
233 | + while(true) | |
234 | + { | |
235 | + if(i == arguments.length-1) | |
236 | + { | |
237 | + throw new ErrorException("Malformed argument on line " + currentLine); | |
238 | + } | |
239 | + if(arguments[++i].endsWith("\"")) | |
240 | + { | |
241 | + String end = arguments[i]; | |
242 | + for(int k = j+1; k < i; k++) | |
243 | + { | |
244 | + argument[1] += arguments[k]; | |
245 | + } | |
246 | + argument[1] += end; | |
247 | + break; | |
248 | + } | |
249 | + } | |
250 | + } | |
224 | 251 | if(argument[0].equals("PROGRAM-ID")) |
225 | 252 | { |
226 | 253 | programID = argument[1]; |
... | ... | @@ -246,14 +273,14 @@ public class Parser |
246 | 273 | } |
247 | 274 | else |
248 | 275 | { |
249 | - currentList = searchID(ppls.getID(), lists); | |
276 | + currentList = searchID(programID, lists); | |
250 | 277 | if(currentList == -1) |
251 | 278 | { |
252 | 279 | /* |
253 | 280 | * ParentList not found, creating a new one. |
254 | 281 | */ |
255 | 282 | lists.add(new ParentList(programID)); |
256 | - currentList = lists.size() + 1; | |
283 | + currentList = lists.size() -1; | |
257 | 284 | } |
258 | 285 | ppls = lists.get(currentList); |
259 | 286 | pls = ppls.getLists().get(ppls.getLists().size()-1); |
... | ... | @@ -294,6 +321,31 @@ public class Parser |
294 | 321 | for(int i = 0; i < arguments.length; i++) |
295 | 322 | { |
296 | 323 | String[] argument = arguments[i].split("="); |
324 | + /* | |
325 | + * In case current argument contains several values like "val1,val2,val3" | |
326 | + * detect the " character and merge them all in one single string | |
327 | + */ | |
328 | + if(argument[1].startsWith("\"") && !argument[1].endsWith("\"")) | |
329 | + { | |
330 | + int j = i; | |
331 | + while(true) | |
332 | + { | |
333 | + if(i == arguments.length-1) | |
334 | + { | |
335 | + throw new ErrorException("Malformed argument on line " + currentLine); | |
336 | + } | |
337 | + if(arguments[++i].endsWith("\"")) | |
338 | + { | |
339 | + String end = arguments[i]; | |
340 | + for(int k = j+1; k < i; k++) | |
341 | + { | |
342 | + argument[1] += arguments[k]; | |
343 | + } | |
344 | + argument[1] += end; | |
345 | + break; | |
346 | + } | |
347 | + } | |
348 | + } | |
297 | 349 | if(argument[0].equals("NAME")) |
298 | 350 | { |
299 | 351 | Name = argument[1].substring(1,argument[1].length()-1); |
... | ... | @@ -329,7 +381,7 @@ public class Parser |
329 | 381 | /* |
330 | 382 | * In case the path read is RELATIVE |
331 | 383 | */ |
332 | - URI = path += argument[1].substring(1,argument[1].length()-1); | |
384 | + URI = path + argument[1].substring(1,argument[1].length()-1); | |
333 | 385 | } |
334 | 386 | else |
335 | 387 | { |
... | ... | @@ -360,7 +412,7 @@ public class Parser |
360 | 412 | else |
361 | 413 | { |
362 | 414 | |
363 | - currentList = searchID(ppls.getID(), lists); | |
415 | + currentList = searchID(GroupID, lists); | |
364 | 416 | if(currentList == -1) |
365 | 417 | { |
366 | 418 | ParentList pl = new ParentList(GroupID); |
... | ... | @@ -368,7 +420,7 @@ public class Parser |
368 | 420 | pl.setName(Name); |
369 | 421 | pl.setType(Type); |
370 | 422 | lists.add(pl); |
371 | - currentList = lists.size()+1; | |
423 | + currentList = lists.size()-1; | |
372 | 424 | } |
373 | 425 | ppls = lists.get(currentList); |
374 | 426 | ppls.getLists().add(newList); |
... | ... | @@ -387,6 +439,16 @@ public class Parser |
387 | 439 | throw new ErrorException("Unexpected end of list!"); |
388 | 440 | } |
389 | 441 | } |
442 | + | |
443 | + else if(extTag[0].equals("#EXT-X-VERSION")) | |
444 | + { | |
445 | + //IGNORE | |
446 | + } | |
447 | + | |
448 | + else if(extTag[0].equals("#EXT-X-PLAYLIST-TYPE")) | |
449 | + { | |
450 | + //IGNORE | |
451 | + } | |
390 | 452 | |
391 | 453 | else |
392 | 454 | { | ... | ... |