Commit 9f55b1dac7c7c8cf56ec35e32a009022203b4d45

Authored by Imanol-Mikel Barba Sabariego
1 parent 22367466

PARSER WORKINGsvn up :DDD

gen/com/upc/pbe/upcnews/R.java
1   -/* AUTO-GENERATED FILE. DO NOT MODIFY.
2   - *
3   - * This class was automatically generated by the
4   - * aapt tool from the resource data it found. It
5   - * should not be modified by hand.
6   - */
7   -
8   -package com.upc.pbe.upcnews;
9   -
10   -public final class R {
11   - public static final class attr {
12   - }
13   - public static final class drawable {
14   - public static final int ic_action_search=0x7f020000;
15   - public static final int ic_launcher=0x7f020001;
16   - public static final int ic_menu_name=0x7f020002;
17   - }
18   - public static final class id {
19   - public static final int AbsoluteLayout1=0x7f08000a;
20   - public static final int ImageView01=0x7f08000c;
21   - public static final int ImageView1=0x7f08000b;
22   - public static final int LinearLayout1=0x7f080001;
23   - public static final int button=0x7f08000f;
24   - public static final int button1=0x7f080003;
25   - public static final int button2=0x7f080004;
26   - public static final int button3=0x7f080005;
27   - public static final int button4=0x7f080006;
28   - public static final int button5=0x7f080007;
29   - public static final int itemhelp=0x7f080012;
30   - public static final int itemprefs=0x7f080011;
31   - public static final int menu_settings=0x7f080010;
32   - public static final int textView1=0x7f080008;
33   - public static final int textView2=0x7f080009;
34   - public static final int textViewRoute=0x7f08000d;
35   - public static final int textViewTitle=0x7f080002;
36   - public static final int textViewXml=0x7f08000e;
37   - public static final int videoView1=0x7f080000;
38   - }
39   - public static final class layout {
40   - public static final int activity_video=0x7f030000;
41   - public static final int dirs=0x7f030001;
42   - public static final int help=0x7f030002;
43   - public static final int main_activity=0x7f030003;
44   - }
45   - public static final class menu {
46   - public static final int activity_main=0x7f070000;
47   - public static final int activity_video=0x7f070001;
48   - public static final int menu=0x7f070002;
49   - }
50   - public static final class string {
51   - public static final int app_name=0x7f050000;
52   - public static final int button=0x7f05000c;
53   - public static final int button1=0x7f05000d;
54   - public static final int desc=0x7f050009;
55   - public static final int descarregar=0x7f050003;
56   - public static final int dir=0x7f05000a;
57   - public static final int directoris=0x7f05000b;
58   - public static final int hello_world=0x7f050010;
59   - public static final int help=0x7f050008;
60   - public static final int hint=0x7f050004;
61   - public static final int logodescription=0x7f05000f;
62   - public static final int menu_settings=0x7f050001;
63   - public static final int prefs=0x7f050007;
64   - public static final int title=0x7f05000e;
65   - public static final int title_activity_main=0x7f050002;
66   - public static final int title_activity_video=0x7f050011;
67   - public static final int url=0x7f050005;
68   - public static final int urlhint=0x7f050006;
69   - }
70   - public static final class style {
71   - public static final int AppTheme=0x7f060000;
72   - }
73   - public static final class xml {
74   - public static final int prefs=0x7f040000;
75   - }
76   -}
  1 +/* AUTO-GENERATED FILE. DO NOT MODIFY.
  2 + *
  3 + * This class was automatically generated by the
  4 + * aapt tool from the resource data it found. It
  5 + * should not be modified by hand.
  6 + */
  7 +
  8 +package com.upc.pbe.upcnews;
  9 +
  10 +public final class R {
  11 + public static final class attr {
  12 + }
  13 + public static final class drawable {
  14 + public static final int ic_action_search=0x7f020000;
  15 + public static final int ic_launcher=0x7f020001;
  16 + public static final int ic_menu_name=0x7f020002;
  17 + }
  18 + public static final class id {
  19 + public static final int AbsoluteLayout1=0x7f08000a;
  20 + public static final int ImageView01=0x7f08000c;
  21 + public static final int ImageView1=0x7f08000b;
  22 + public static final int LinearLayout1=0x7f080001;
  23 + public static final int button=0x7f08000f;
  24 + public static final int button1=0x7f080003;
  25 + public static final int button2=0x7f080004;
  26 + public static final int button3=0x7f080005;
  27 + public static final int button4=0x7f080006;
  28 + public static final int button5=0x7f080007;
  29 + public static final int itemhelp=0x7f080012;
  30 + public static final int itemprefs=0x7f080011;
  31 + public static final int menu_settings=0x7f080010;
  32 + public static final int textView1=0x7f080008;
  33 + public static final int textView2=0x7f080009;
  34 + public static final int textViewRoute=0x7f08000d;
  35 + public static final int textViewTitle=0x7f080002;
  36 + public static final int textViewXml=0x7f08000e;
  37 + public static final int videoView1=0x7f080000;
  38 + }
  39 + public static final class layout {
  40 + public static final int activity_video=0x7f030000;
  41 + public static final int dirs=0x7f030001;
  42 + public static final int help=0x7f030002;
  43 + public static final int main_activity=0x7f030003;
  44 + }
  45 + public static final class menu {
  46 + public static final int activity_main=0x7f070000;
  47 + public static final int activity_video=0x7f070001;
  48 + public static final int menu=0x7f070002;
  49 + }
  50 + public static final class string {
  51 + public static final int app_name=0x7f050000;
  52 + public static final int button=0x7f05000c;
  53 + public static final int button1=0x7f05000d;
  54 + public static final int desc=0x7f050009;
  55 + public static final int descarregar=0x7f050003;
  56 + public static final int dir=0x7f05000a;
  57 + public static final int directoris=0x7f05000b;
  58 + public static final int hello_world=0x7f050010;
  59 + public static final int help=0x7f050008;
  60 + public static final int hint=0x7f050004;
  61 + public static final int logodescription=0x7f05000f;
  62 + public static final int menu_settings=0x7f050001;
  63 + public static final int prefs=0x7f050007;
  64 + public static final int title=0x7f05000e;
  65 + public static final int title_activity_main=0x7f050002;
  66 + public static final int title_activity_video=0x7f050011;
  67 + public static final int url=0x7f050005;
  68 + public static final int urlhint=0x7f050006;
  69 + }
  70 + public static final class style {
  71 + public static final int AppTheme=0x7f060000;
  72 + }
  73 + public static final class xml {
  74 + public static final int prefs=0x7f040000;
  75 + }
  76 +}
... ...
res/values/strings.xml
... ... @@ -2,7 +2,7 @@
2 2  
3 3 <string name="app_name">UPC NEWS</string>
4 4 <string name="menu_settings">Settings</string>
5   - <string name="title_activity_main">MainActivity</string>
  5 + <string name="title_activity_main">UPC NEWS</string>
6 6 <string name="descarregar">Start Application</string>
7 7 <string name="hint">Click to Start or go to Settings for Help</string>
8 8 <string name="url">URL server</string>
... ...
src/com/upc/pbe/upcnews/Directoris.java
... ... @@ -102,7 +102,7 @@ public class Directoris extends Activity implements OnClickListener {
102 102  
103 103 public void buttonClicked(Button b) {
104 104  
105   - //Descarrega de la pàgina HTML del directori i busqueda d'un .m3u8 en ella
  105 + //Descarrega de la p�gina HTML del directori i busqueda d'un .m3u8 en ella
106 106 Log.d(TAG, "Click on " + b.getText());
107 107 d = new Descarrega();
108 108 String str = d.doInBackground(url + "/" + b.getText() + "/");
... ... @@ -117,8 +117,7 @@ public class Directoris extends Activity implements OnClickListener {
117 117 d = new Descarrega();
118 118 String m3u8 = d.doInBackground(urlvideo);
119 119 Log.d(TAG, m3u8);
120   - Parser p = new Parser();
121   -
  120 + Parser p = new Parser(urlvideo.substring(0,urlvideo.lastIndexOf("/")+1),this);
122 121 try {
123 122 ArrayList<ParentList> m3u8parsed = p.parseFile(m3u8);
124 123 Log.d(TAG, "parsed completed");
... ...
src/com/upc/pbe/upcnews/Parser.java
... ... @@ -3,12 +3,13 @@ package com.upc.pbe.upcnews;
3 3 import java.net.MalformedURLException;
4 4 import java.util.ArrayList;
5 5  
6   -import android.util.Log;
  6 +import android.app.Activity;
  7 +import android.widget.Toast;
7 8  
8 9 public class Parser
9 10 {
10 11 private static final String STARTWORD = "#EXTM3U";
11   - private static String TAG = "Parser";
  12 + private String path; //CWD, completes implicit paths such as "file.m3u8" appending the CWD in order to download the file
12 13 private int fileType; //indicates if segment list or media list
13 14 private int currentLine;
14 15 private int currentSegment; //Cada segmento de cada calidad distinta
... ... @@ -16,18 +17,12 @@ public class Parser
16 17 private boolean expectSegment = false;
17 18 private boolean expectList = false;
18 19 private Descarrega download;
  20 + private Activity caller; //Where to send notifications and warnings
19 21  
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   -
29   - public Parser()
  22 + public Parser(String p,Activity caller)
30 23 {
  24 + this.caller = caller;
  25 + path = p;
31 26 currentLine = 0;
32 27 currentSegment = 0;
33 28 currentList = 0;
... ... @@ -46,26 +41,26 @@ public class Parser
46 41 lists.add(new ParentList(""));
47 42 lists.get(0).getLists().add(new List(-1));
48 43 String[] lines = file.split("\n");
49   - Log.d(TAG, "" + lines.length);
50 44 for(int i = 0; i < lines.length; i++)
51 45 {
52 46 if(lines[i].endsWith("\\"))
53 47 {
54   - lines[++i] = lines[i-1].substring(0, lines[i-1].indexOf("\\")-1) + lines[i];
  48 + /*
  49 + * Merge multiline entries, which are those lines ending with backslash.
  50 + */
  51 + lines[++i] = lines[i-1].substring(0, lines[i-1].indexOf("\\")-1) + lines[i];
55 52 }
56 53 try
57 54 {
58   -
59   - Log.d(TAG, lines[i]);
60 55 parseLine(lines[i],lists);
61 56 }
62 57 catch(InfoException iE)
63 58 {
64   - //Toast.makeText(this, iE.getMessage(), Toast.LENGTH_SHORT).show();
  59 + Toast.makeText(caller, iE.getMessage(), Toast.LENGTH_SHORT).show();
65 60 }
66 61 catch(WarningException wE)
67 62 {
68   -
  63 + Toast.makeText(caller, wE.getMessage(), Toast.LENGTH_SHORT).show();
69 64 }
70 65 }
71 66 /*
... ... @@ -104,11 +99,11 @@ public class Parser
104 99 if(lists.get(0).getQuality() == -1)
105 100 {
106 101 /*
107   - * Se trata de ext-x-media's y estos no van por calidad
  102 + * That's the case of Media lists and Segment lists, they don't have distinct qualities.
108 103 */
109 104 return;
110 105 }
111   - //BUBBLE-SORT!! (Me da un poco de verguenza, pero no quiero ponerme con quicksort...
  106 + //Bubblesort
112 107 while(true)
113 108 {
114 109 boolean sorted = true;
... ... @@ -123,7 +118,7 @@ public class Parser
123 118 lists.set(i+1, aux);
124 119 }
125 120  
126   - }while(++i != lists.size());
  121 + }while(++i != lists.size()-1);
127 122 if(sorted)
128 123 {
129 124 break;
... ... @@ -141,8 +136,7 @@ public class Parser
141 136 }
142 137 else
143 138 {
144   - ParentList ppls = lists.get(currentList); //VIVA HONDURAS!!!
145   - int b = ppls.getLists().size();
  139 + ParentList ppls = lists.get(currentList);
146 140 List pls = ppls.getLists().get(ppls.getLists().size()-1);
147 141 if(!ppls.getValidated())
148 142 {
... ... @@ -161,7 +155,15 @@ public class Parser
161 155 {
162 156 if(line.substring(0,4).equals("#EXT"))
163 157 {
164   - String[] extTag = line.split(":");
  158 + if(expectSegment)
  159 + {
  160 + throw new ErrorException("Expected segment URI, got an EXT-TAG instead");
  161 + }
  162 + if(expectList)
  163 + {
  164 + throw new ErrorException("Expected List, got an EXT-TAG instead");
  165 + }
  166 + String[] extTag = line.split(":", 2);
165 167 if(extTag[0].equals("#EXT-X-MEDIA-SEQUENCE"))
166 168 {
167 169 pls.setSequence(Integer.parseInt(extTag[1]));
... ... @@ -181,16 +183,11 @@ public class Parser
181 183 throw new ErrorException("Invalid file, should contain Lists, " +
182 184 "but segments were found.");
183 185 }
184   - if(expectSegment)
185   - {
186   - throw new ErrorException("Expected segment URI, got a different" +
187   - "segment declaration");
188   - }
189 186 String[] args = extTag[1].split(",");
190 187 float duration = Float.parseFloat(args[0]);
191 188 if (duration > pls.getMaxDuration())
192 189 {
193   - throw new ErrorException("Segment " + currentSegment + " on line " + currentLine
  190 + throw new ErrorException("Segment " + currentSegment+1 + " on line " + currentLine
194 191 +" exceeds max duration");
195 192 }
196 193 Segment s = new Segment(duration);
... ... @@ -238,36 +235,38 @@ public class Parser
238 235 throw new ErrorException("Playlist on line " + currentLine +
239 236 " has missing arguments");
240 237 }
241   - if(!programID.equals(ppls.getID())) //Si el programID no coincide, crea o busca la parentlist que toca
  238 + if(!programID.equals(ppls.getID())) //If Program-ID doesn't match, search it or create a new one.
242 239 {
243 240 if(ppls.getID().equals(""))
244 241 {
245 242 /*
246   - * Este caso se da cuando no se ha creado ninguna lista.
247   - * Hay que sustituir la por defecto por una lista real.
  243 + * If working with the default ParentList, then modify it, don't create a new one.
248 244 */
249   - lists.get(0).setID(programID);
  245 + lists.get(0).setID(programID);
250 246 }
251 247 else
252 248 {
253 249 currentList = searchID(ppls.getID(), lists);
254 250 if(currentList == -1)
255 251 {
256   - lists.add(new ParentList(programID));
257 252 /*
258   - * ppls y pls se actualizan en la siguiente linea procesada
  253 + * ParentList not found, creating a new one.
259 254 */
  255 + lists.add(new ParentList(programID));
260 256 currentList = lists.size() + 1;
261 257 }
262 258 ppls = lists.get(currentList);
263 259 pls = ppls.getLists().get(ppls.getLists().size()-1);
264   -
265 260 }
266 261 }
267   - // Ahora crea la lista adecuada dentro de la parentlist
268   - int a = ppls.getLists().size();
  262 + /*
  263 + * Now we create a new List inside the correct ParentList.
  264 + */
269 265 if((ppls.getLists().size() == 1) && (pls.getQuality() == -1) && pls.getSegments().isEmpty())
270 266 {
  267 + /*
  268 + * If working with the default List, then modify it, don't create a new one.
  269 + */
271 270 pls.setQuality(bandwidth);
272 271 }
273 272 else
... ... @@ -297,7 +296,7 @@ public class Parser
297 296 String[] argument = arguments[i].split("=");
298 297 if(argument[0].equals("NAME"))
299 298 {
300   - Name = argument[1];
  299 + Name = argument[1].substring(1,argument[1].length()-1);
301 300 }
302 301 else if(argument[0].equals("TYPE"))
303 302 {
... ... @@ -305,7 +304,7 @@ public class Parser
305 304 }
306 305 else if(argument[0].equals("GROUP-ID"))
307 306 {
308   - GroupID = argument[1];
  307 + GroupID = argument[1].substring(1,argument[1].length()-1);
309 308 }
310 309 else if(argument[0].equals("DEFAULT"))
311 310 {
... ... @@ -325,7 +324,17 @@ public class Parser
325 324 }
326 325 else if(argument[0].equals("URI"))
327 326 {
328   - URI = argument[1];
  327 + if(!argument[1].contains("http://"))
  328 + {
  329 + /*
  330 + * In case the path read is RELATIVE
  331 + */
  332 + URI = path += argument[1].substring(1,argument[1].length()-1);
  333 + }
  334 + else
  335 + {
  336 + URI = argument[1].substring(1,argument[1].length()-1);
  337 + }
329 338 }
330 339 }
331 340 if(Type.equals("") || Name.equals("") || URI.equals("") || GroupID.equals(""))
... ... @@ -333,30 +342,20 @@ public class Parser
333 342 throw new ErrorException("Playlist on line " + currentLine +
334 343 " has missing arguments");
335 344 }
336   - ParentList pl = new ParentList(GroupID);
337   - pl.setDefault(Default);
338   - pl.setName(Name);
339   - pl.setType(Type);
340   - Parser p = new Parser();
341   - p.parseFile(download.doInBackground(URI));
342   - /*
343   - * Procesar URI y descargar listas recursivamente y añadir a la lista actual.
344   - *
345   - * TO-DO: Necesito la funcion de Marc
346   - */
347   - List l = new List(-1);
  345 + Parser p = new Parser(URI.substring(0, URI.lastIndexOf("/")+1),caller);
  346 + List newList = p.parseFile(download.doInBackground(URI)).get(0).getLists().get(0);
348 347 if(!GroupID.equals(ppls.getID()))
349 348 {
350 349 if(ppls.getID().equals(""))
351 350 {
352 351 /*
353   - * Este caso se da cuando no se ha creado ninguna lista.
354   - * Hay que sustituir la por defecto por una lista real.
  352 + * If working with the default ParentList, then modify it, don't create a new one.
355 353 */
356 354 ppls.setDefault(Default);
357 355 ppls.setName(Name);
358 356 ppls.setType(Type);
359   - lists.add(0,pl);
  357 + ppls.getLists().set(0, newList);
  358 + ppls.setID(GroupID);
360 359 }
361 360 else
362 361 {
... ... @@ -364,19 +363,20 @@ public class Parser
364 363 currentList = searchID(ppls.getID(), lists);
365 364 if(currentList == -1)
366 365 {
  366 + ParentList pl = new ParentList(GroupID);
  367 + pl.setDefault(Default);
  368 + pl.setName(Name);
  369 + pl.setType(Type);
367 370 lists.add(pl);
368 371 currentList = lists.size()+1;
369 372 }
370   - else
371   - {
372   - ppls = lists.get(currentList);
373   - ppls.getLists().add(l);
374   - }
  373 + ppls = lists.get(currentList);
  374 + ppls.getLists().add(newList);
375 375 }
376 376 }
377 377 else
378 378 {
379   - ppls.getLists().add(l);
  379 + ppls.getLists().add(newList);
380 380 }
381 381 }
382 382  
... ... @@ -385,8 +385,7 @@ public class Parser
385 385 if(expectSegment || expectList)
386 386 {
387 387 throw new ErrorException("Unexpected end of list!");
388   - }
389   - //END REACHED, IGNORE AND LET THE FILE REACH EOF
  388 + }
390 389 }
391 390  
392 391 else
... ... @@ -418,12 +417,17 @@ public class Parser
418 417 }
419 418 else if(expectList)
420 419 {
  420 + /*
  421 + * Download list and merge the entries with the current list
  422 + */
421 423 expectList = false;
422   - Parser p = new Parser();
423   - ArrayList<ParentList> newLists = p.parseFile(download.doInBackground(line));
424   - for(int i = 0; i < newLists.get(0).getLists().get(0).getSegments().size(); i++)
  424 + Parser p = new Parser(line.substring(0,line.lastIndexOf("/")+1),caller);
  425 + List newList = p.parseFile(download.doInBackground(line)).get(0).getLists().get(0);
  426 + pls.setMaxDuration(newList.getMaxDuration());
  427 + pls.setSequence(newList.getSequence());
  428 + for(int i = 0; i < newList.getSegments().size(); i++)
425 429 {
426   - pls.getSegments().add(newLists.get(0).getLists().get(0).getSegments().get(i));
  430 + pls.getSegments().add(newList.getSegments().get(i));
427 431 }
428 432 }
429 433 else
... ...