Commit f496e3d8bec45029a741ac02a8ded902d574abbc

Authored by Imanol-Mikel Barba Sabariego
1 parent 9f55b1da

Bugs arreglados, mayor estabilidad y mas robustez

src/com/upc/pbe/upcnews/ParentList.java
@@ -9,11 +9,10 @@ public class ParentList @@ -9,11 +9,10 @@ public class ParentList
9 private String Type, Name; 9 private String Type, Name;
10 private boolean Default; //Estos 3 últimos son para los ext-x-media, los ext-x-stream lo IGNORAN 10 private boolean Default; //Estos 3 últimos son para los ext-x-media, los ext-x-stream lo IGNORAN
11 private ArrayList<List> lists; //per cada qualitat 11 private ArrayList<List> lists; //per cada qualitat
12 - private boolean validated; 12 +
13 13
14 public ParentList(String ID) 14 public ParentList(String ID)
15 { 15 {
16 - validated = false;  
17 this.ID = ID; 16 this.ID = ID;
18 currentQuality = 0; 17 currentQuality = 0;
19 Type = ""; 18 Type = "";
@@ -21,17 +20,7 @@ public class ParentList @@ -21,17 +20,7 @@ public class ParentList
21 Default = false; 20 Default = false;
22 lists = new ArrayList<List>(); //Lista de CALIDADES 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 public String getID() 24 public String getID()
36 { 25 {
37 return ID; 26 return ID;
src/com/upc/pbe/upcnews/Parser.java
@@ -18,6 +18,7 @@ public class Parser @@ -18,6 +18,7 @@ public class Parser
18 private boolean expectList = false; 18 private boolean expectList = false;
19 private Descarrega download; 19 private Descarrega download;
20 private Activity caller; //Where to send notifications and warnings 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 public Parser(String p,Activity caller) 23 public Parser(String p,Activity caller)
23 { 24 {
@@ -33,6 +34,7 @@ public class Parser @@ -33,6 +34,7 @@ public class Parser
33 * 1 indicates MEDIA 34 * 1 indicates MEDIA
34 */ 35 */
35 download = new Descarrega(); 36 download = new Descarrega();
  37 + validated = false;
36 } 38 }
37 39
38 public ArrayList<ParentList> parseFile(String file) throws ErrorException, WarningException, InfoException 40 public ArrayList<ParentList> parseFile(String file) throws ErrorException, WarningException, InfoException
@@ -138,11 +140,11 @@ public class Parser @@ -138,11 +140,11 @@ public class Parser
138 { 140 {
139 ParentList ppls = lists.get(currentList); 141 ParentList ppls = lists.get(currentList);
140 List pls = ppls.getLists().get(ppls.getLists().size()-1); 142 List pls = ppls.getLists().get(ppls.getLists().size()-1);
141 - if(!ppls.getValidated()) 143 + if(!validated)
142 { 144 {
143 if(line.equals(STARTWORD)) 145 if(line.equals(STARTWORD))
144 { 146 {
145 - ppls.setValidated(true); 147 + validated = true;
146 } 148 }
147 else 149 else
148 { 150 {
@@ -221,6 +223,31 @@ public class Parser @@ -221,6 +223,31 @@ public class Parser
221 for(int i = 0; i < arguments.length; i++) 223 for(int i = 0; i < arguments.length; i++)
222 { 224 {
223 String[] argument = arguments[i].split("="); 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 if(argument[0].equals("PROGRAM-ID")) 251 if(argument[0].equals("PROGRAM-ID"))
225 { 252 {
226 programID = argument[1]; 253 programID = argument[1];
@@ -246,14 +273,14 @@ public class Parser @@ -246,14 +273,14 @@ public class Parser
246 } 273 }
247 else 274 else
248 { 275 {
249 - currentList = searchID(ppls.getID(), lists); 276 + currentList = searchID(programID, lists);
250 if(currentList == -1) 277 if(currentList == -1)
251 { 278 {
252 /* 279 /*
253 * ParentList not found, creating a new one. 280 * ParentList not found, creating a new one.
254 */ 281 */
255 lists.add(new ParentList(programID)); 282 lists.add(new ParentList(programID));
256 - currentList = lists.size() + 1; 283 + currentList = lists.size() -1;
257 } 284 }
258 ppls = lists.get(currentList); 285 ppls = lists.get(currentList);
259 pls = ppls.getLists().get(ppls.getLists().size()-1); 286 pls = ppls.getLists().get(ppls.getLists().size()-1);
@@ -294,6 +321,31 @@ public class Parser @@ -294,6 +321,31 @@ public class Parser
294 for(int i = 0; i < arguments.length; i++) 321 for(int i = 0; i < arguments.length; i++)
295 { 322 {
296 String[] argument = arguments[i].split("="); 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 if(argument[0].equals("NAME")) 349 if(argument[0].equals("NAME"))
298 { 350 {
299 Name = argument[1].substring(1,argument[1].length()-1); 351 Name = argument[1].substring(1,argument[1].length()-1);
@@ -329,7 +381,7 @@ public class Parser @@ -329,7 +381,7 @@ public class Parser
329 /* 381 /*
330 * In case the path read is RELATIVE 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 else 386 else
335 { 387 {
@@ -360,7 +412,7 @@ public class Parser @@ -360,7 +412,7 @@ public class Parser
360 else 412 else
361 { 413 {
362 414
363 - currentList = searchID(ppls.getID(), lists); 415 + currentList = searchID(GroupID, lists);
364 if(currentList == -1) 416 if(currentList == -1)
365 { 417 {
366 ParentList pl = new ParentList(GroupID); 418 ParentList pl = new ParentList(GroupID);
@@ -368,7 +420,7 @@ public class Parser @@ -368,7 +420,7 @@ public class Parser
368 pl.setName(Name); 420 pl.setName(Name);
369 pl.setType(Type); 421 pl.setType(Type);
370 lists.add(pl); 422 lists.add(pl);
371 - currentList = lists.size()+1; 423 + currentList = lists.size()-1;
372 } 424 }
373 ppls = lists.get(currentList); 425 ppls = lists.get(currentList);
374 ppls.getLists().add(newList); 426 ppls.getLists().add(newList);
@@ -387,6 +439,16 @@ public class Parser @@ -387,6 +439,16 @@ public class Parser
387 throw new ErrorException("Unexpected end of list!"); 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 else 453 else
392 { 454 {