diff --git a/src/com/upc/pbe/upcnews/ParentList.java b/src/com/upc/pbe/upcnews/ParentList.java index 72ebb27..dbef870 100644 --- a/src/com/upc/pbe/upcnews/ParentList.java +++ b/src/com/upc/pbe/upcnews/ParentList.java @@ -9,11 +9,10 @@ public class ParentList private String Type, Name; private boolean Default; //Estos 3 Ășltimos son para los ext-x-media, los ext-x-stream lo IGNORAN private ArrayList lists; //per cada qualitat - private boolean validated; + public ParentList(String ID) { - validated = false; this.ID = ID; currentQuality = 0; Type = ""; @@ -21,17 +20,7 @@ public class ParentList Default = false; lists = new ArrayList(); //Lista de CALIDADES } - - public void setValidated(boolean val) - { - validated = val; - } - - public boolean getValidated() - { - return validated; - } - + public String getID() { return ID; diff --git a/src/com/upc/pbe/upcnews/Parser.java b/src/com/upc/pbe/upcnews/Parser.java index 8a242db..2d1622b 100644 --- a/src/com/upc/pbe/upcnews/Parser.java +++ b/src/com/upc/pbe/upcnews/Parser.java @@ -18,6 +18,7 @@ public class Parser private boolean expectList = false; private Descarrega download; private Activity caller; //Where to send notifications and warnings + private boolean validated; //Wether if list starts with #EXTM3U or not public Parser(String p,Activity caller) { @@ -33,6 +34,7 @@ public class Parser * 1 indicates MEDIA */ download = new Descarrega(); + validated = false; } public ArrayList parseFile(String file) throws ErrorException, WarningException, InfoException @@ -138,11 +140,11 @@ public class Parser { ParentList ppls = lists.get(currentList); List pls = ppls.getLists().get(ppls.getLists().size()-1); - if(!ppls.getValidated()) + if(!validated) { if(line.equals(STARTWORD)) { - ppls.setValidated(true); + validated = true; } else { @@ -221,6 +223,31 @@ public class Parser for(int i = 0; i < arguments.length; i++) { String[] argument = arguments[i].split("="); + /* + * In case current argument contains several values like "val1,val2,val3" + * detect the " character and merge them all in one single string + */ + if(argument[1].startsWith("\"") && !argument[1].endsWith("\"")) + { + int j = i; + while(true) + { + if(i == arguments.length-1) + { + throw new ErrorException("Malformed argument on line " + currentLine); + } + if(arguments[++i].endsWith("\"")) + { + String end = arguments[i]; + for(int k = j+1; k < i; k++) + { + argument[1] += arguments[k]; + } + argument[1] += end; + break; + } + } + } if(argument[0].equals("PROGRAM-ID")) { programID = argument[1]; @@ -246,14 +273,14 @@ public class Parser } else { - currentList = searchID(ppls.getID(), lists); + currentList = searchID(programID, lists); if(currentList == -1) { /* * ParentList not found, creating a new one. */ lists.add(new ParentList(programID)); - currentList = lists.size() + 1; + currentList = lists.size() -1; } ppls = lists.get(currentList); pls = ppls.getLists().get(ppls.getLists().size()-1); @@ -294,6 +321,31 @@ public class Parser for(int i = 0; i < arguments.length; i++) { String[] argument = arguments[i].split("="); + /* + * In case current argument contains several values like "val1,val2,val3" + * detect the " character and merge them all in one single string + */ + if(argument[1].startsWith("\"") && !argument[1].endsWith("\"")) + { + int j = i; + while(true) + { + if(i == arguments.length-1) + { + throw new ErrorException("Malformed argument on line " + currentLine); + } + if(arguments[++i].endsWith("\"")) + { + String end = arguments[i]; + for(int k = j+1; k < i; k++) + { + argument[1] += arguments[k]; + } + argument[1] += end; + break; + } + } + } if(argument[0].equals("NAME")) { Name = argument[1].substring(1,argument[1].length()-1); @@ -329,7 +381,7 @@ public class Parser /* * In case the path read is RELATIVE */ - URI = path += argument[1].substring(1,argument[1].length()-1); + URI = path + argument[1].substring(1,argument[1].length()-1); } else { @@ -360,7 +412,7 @@ public class Parser else { - currentList = searchID(ppls.getID(), lists); + currentList = searchID(GroupID, lists); if(currentList == -1) { ParentList pl = new ParentList(GroupID); @@ -368,7 +420,7 @@ public class Parser pl.setName(Name); pl.setType(Type); lists.add(pl); - currentList = lists.size()+1; + currentList = lists.size()-1; } ppls = lists.get(currentList); ppls.getLists().add(newList); @@ -387,6 +439,16 @@ public class Parser throw new ErrorException("Unexpected end of list!"); } } + + else if(extTag[0].equals("#EXT-X-VERSION")) + { + //IGNORE + } + + else if(extTag[0].equals("#EXT-X-PLAYLIST-TYPE")) + { + //IGNORE + } else {