Commit 22367466c9985ee737e1f8cdaad9470ed9608413

Authored by Imanol-Mikel Barba Sabariego
1 parent a9c963b2

--no commit message

src/com/upc/pbe/upcnews/List.java
... ... @@ -4,7 +4,7 @@ import java.util.ArrayList;
4 4  
5 5 public class List
6 6 {
7   - private boolean validated;
  7 +
8 8 private int quality;
9 9 private int sequenceFirst;
10 10 private int maxDuration;
... ... @@ -13,20 +13,9 @@ public class List
13 13 public List(int q)
14 14 {
15 15 quality = q;
16   - validated = false;
17 16 segments = new ArrayList<Segment>();
18 17 }
19 18  
20   - public void setValidated(boolean val)
21   - {
22   - validated = val;
23   - }
24   -
25   - public boolean getValidated()
26   - {
27   - return validated;
28   - }
29   -
30 19 public void setSequence(int seq)
31 20 {
32 21 sequenceFirst = seq;
... ... @@ -52,6 +41,11 @@ public class List
52 41 return quality;
53 42 }
54 43  
  44 + public void setQuality(int q)
  45 + {
  46 + quality = q;
  47 + }
  48 +
55 49 public ArrayList<Segment> getSegments()
56 50 {
57 51 return segments;
... ...
src/com/upc/pbe/upcnews/ParentList.java
... ... @@ -9,9 +9,11 @@ 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 public ParentList(String ID)
14 15 {
  16 + validated = false;
15 17 this.ID = ID;
16 18 currentQuality = 0;
17 19 Type = "";
... ... @@ -20,6 +22,16 @@ public class ParentList
20 22 lists = new ArrayList<List>(); //Lista de CALIDADES
21 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 36 {
25 37 return ID;
... ...
src/com/upc/pbe/upcnews/Parser.java
... ... @@ -17,6 +17,15 @@ public class Parser
17 17 private boolean expectList = false;
18 18 private Descarrega download;
19 19  
  20 + /*
  21 + * TO-DO:
  22 + * RECICLAR ZILLONES DE CÓDIGO REPETIDO
  23 + * LIMPIAR Y DOCUMENTAR
  24 + * DOWNLOAD REPEATED
  25 + * MEDIA'S NOT WORKING
  26 + */
  27 +
  28 +
20 29 public Parser()
21 30 {
22 31 currentLine = 0;
... ... @@ -42,7 +51,7 @@ public class Parser
42 51 {
43 52 if(lines[i].endsWith("\\"))
44 53 {
45   - lines[i] = lines[i].substring(0, lines[i].indexOf("\\")-1) + lines[++i];
  54 + lines[++i] = lines[i-1].substring(0, lines[i-1].indexOf("\\")-1) + lines[i];
46 55 }
47 56 try
48 57 {
... ... @@ -133,12 +142,13 @@ public class Parser
133 142 else
134 143 {
135 144 ParentList ppls = lists.get(currentList); //VIVA HONDURAS!!!
136   - List pls = ppls.getLists().get(ppls.getCurrentQuality());
137   - if(!pls.getValidated())
  145 + int b = ppls.getLists().size();
  146 + List pls = ppls.getLists().get(ppls.getLists().size()-1);
  147 + if(!ppls.getValidated())
138 148 {
139 149 if(line.equals(STARTWORD))
140 150 {
141   - pls.setValidated(true);
  151 + ppls.setValidated(true);
142 152 }
143 153 else
144 154 {
... ... @@ -228,7 +238,7 @@ public class Parser
228 238 throw new ErrorException("Playlist on line " + currentLine +
229 239 " has missing arguments");
230 240 }
231   - if(!programID.equals(ppls.getID()))
  241 + if(!programID.equals(ppls.getID())) //Si el programID no coincide, crea o busca la parentlist que toca
232 242 {
233 243 if(ppls.getID().equals(""))
234 244 {
... ... @@ -236,7 +246,7 @@ public class Parser
236 246 * Este caso se da cuando no se ha creado ninguna lista.
237 247 * Hay que sustituir la por defecto por una lista real.
238 248 */
239   - lists.get(0).setID(programID);
  249 + lists.get(0).setID(programID);
240 250 }
241 251 else
242 252 {
... ... @@ -244,18 +254,22 @@ public class Parser
244 254 if(currentList == -1)
245 255 {
246 256 lists.add(new ParentList(programID));
247   - currentList = lists.size()+1;
248 257 /*
249 258 * ppls y pls se actualizan en la siguiente linea procesada
250 259 */
  260 + currentList = lists.size() + 1;
251 261 }
252   - else
253   - {
254   - ppls = lists.get(currentList);
255   - ppls.getLists().add(new List(bandwidth));
256   - }
  262 + ppls = lists.get(currentList);
  263 + pls = ppls.getLists().get(ppls.getLists().size()-1);
  264 +
257 265 }
258 266 }
  267 + // Ahora crea la lista adecuada dentro de la parentlist
  268 + int a = ppls.getLists().size();
  269 + if((ppls.getLists().size() == 1) && (pls.getQuality() == -1) && pls.getSegments().isEmpty())
  270 + {
  271 + pls.setQuality(bandwidth);
  272 + }
259 273 else
260 274 {
261 275 ppls.getLists().add(new List(bandwidth));
... ... @@ -339,6 +353,9 @@ public class Parser
339 353 * Este caso se da cuando no se ha creado ninguna lista.
340 354 * Hay que sustituir la por defecto por una lista real.
341 355 */
  356 + ppls.setDefault(Default);
  357 + ppls.setName(Name);
  358 + ppls.setType(Type);
342 359 lists.add(0,pl);
343 360 }
344 361 else
... ... @@ -403,7 +420,11 @@ public class Parser
403 420 {
404 421 expectList = false;
405 422 Parser p = new Parser();
406   - p.parseFile(download.doInBackground(line));
  423 + ArrayList<ParentList> newLists = p.parseFile(download.doInBackground(line));
  424 + for(int i = 0; i < newLists.get(0).getLists().get(0).getSegments().size(); i++)
  425 + {
  426 + pls.getSegments().add(newLists.get(0).getLists().get(0).getSegments().get(i));
  427 + }
407 428 }
408 429 else
409 430 {
... ...