Commit 7db9ecc933478247f685a757c3582ec35828584b

Authored by Imanol-Mikel Barba Sabariego
1 parent ad11fa86

--no commit message

AndroidManifest.xml
... ... @@ -36,14 +36,7 @@
36 36 </activity>
37 37 <activity android:name=".Directoris" >
38 38 </activity>
39   - <activity
40   - android:name=".VideoActivity"
41   - android:label="@string/title_activity_video" >
42   - <intent-filter>
43   - <action android:name="android.intent.action.MAIN" />
44   -
45   - <category android:name="android.intent.category.LAUNCHER" />
46   - </intent-filter>
  39 + <activity android:name=".VideoActivity" >
47 40 </activity>
48 41 </application>
49 42  
... ...
src/com/upc/pbe/upcnews/Directoris.java
... ... @@ -118,7 +118,7 @@ public class Directoris extends Activity implements OnClickListener {
118 118 String m3u8 = d.doInBackground(urlvideo);
119 119 Log.d(TAG, m3u8);
120 120 Parser p = new Parser();
121   - /*
  121 +
122 122 try {
123 123 ArrayList<ParentList> m3u8parsed = p.parseFile(m3u8);
124 124  
... ... @@ -132,13 +132,14 @@ public class Directoris extends Activity implements OnClickListener {
132 132 } catch (InfoException e) {
133 133 Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
134 134 Log.d(TAG, e.getMessage());
135   - }*/
  135 + }
136 136 }
137 137  
138 138 //VideoPlayer
  139 + /*
139 140 String urlvid = null;
140 141 ((UpcApp) getApplication()).setDesc(urlvid);
141 142  
142   - startActivity(new Intent(this, VideoActivity.class));
  143 + startActivity(new Intent(this, VideoActivity.class));*/
143 144 }
144 145 }
145 146 \ No newline at end of file
... ...
src/com/upc/pbe/upcnews/Parser.java
... ... @@ -5,272 +5,216 @@ import java.util.ArrayList;
5 5  
6 6 import android.util.Log;
7 7  
8   -public class Parser
9   -{
  8 +public class Parser {
10 9 private static final String STARTWORD = "#EXTM3U";
11 10 private static String TAG = "Parser";
12   - private int fileType; //indicates if segment list or media list
  11 + private int fileType; // indicates if segment list or media list
13 12 private int currentLine;
14   - private int currentSegment; //Cada segmento de cada calidad distinta
15   - private int currentList; //Indice de cada recurso distinto
  13 + private int currentSegment; // Cada segmento de cada calidad distinta
  14 + private int currentList; // Indice de cada recurso distinto
16 15 private boolean expectSegment = false;
17 16 private boolean expectList = false;
18 17 private Descarrega download;
19   -
20   - public Parser()
21   - {
  18 +
  19 + public Parser() {
22 20 currentLine = 0;
23 21 currentSegment = 0;
24 22 currentList = 0;
25 23 fileType = -1;
26 24 /*
27   - * -1 indicates UNDETERMINED
28   - * 0 indicates SEGMENTS
29   - * 1 indicates MEDIA
  25 + * -1 indicates UNDETERMINED 0 indicates SEGMENTS 1 indicates MEDIA
30 26 */
31 27 download = new Descarrega();
32 28 }
33   -
34   - public ArrayList<ParentList> parseFile(String file) throws ErrorException, WarningException, InfoException
35   - {
  29 +
  30 + public ArrayList<ParentList> parseFile(String file) throws ErrorException,
  31 + WarningException, InfoException {
36 32 ArrayList<ParentList> lists = new ArrayList<ParentList>();
37 33 lists.add(new ParentList(""));
38 34 lists.get(0).getLists().add(new List(-1));
39 35 String[] lines = file.split("\n");
40   - Log.d(TAG, "" + lines.length);
41   - for(int i = 0; i < lines.length; i++) //la primera linea = null
  36 +
  37 + for (int i = 0; i < lines.length; i++) // la primera linea = null
42 38 {
43   - if(lines[i].endsWith("\\"))
44   - {
45   - lines[i] = lines[i].substring(0, lines[i].indexOf("\\")) + lines[++i];
  39 + if (lines[i].endsWith("\\")) {
  40 + lines[i] = lines[i].substring(0, lines[i].indexOf("\\"))
  41 + + lines[++i];
46 42 }
47   - try
48   - {
49   -
  43 + try {
  44 +
50 45 Log.d(TAG, lines[i]);
51   - parseLine(lines[i],lists);
52   - }
53   - catch(InfoException iE)
54   - {
55   - //Toast.makeText(this, iE.getMessage(), Toast.LENGTH_SHORT).show();
56   - }
57   - catch(WarningException wE)
58   - {
59   -
  46 + parseLine(lines[i], lists);
  47 + } catch (InfoException iE) {
  48 + // Toast.makeText(this, iE.getMessage(),
  49 + // Toast.LENGTH_SHORT).show();
  50 + } catch (WarningException wE) {
  51 +
60 52 }
61 53 }
62   - /*
63   - * Esto contiene una lista de RECURSOS,
64   - * que a su vez contiene una lista de CALIDADES.
65   - * Si no te gusta mis VERSOS,
66   - * te mando a la mierda sin SUTILIDADES.
  54 + /*
  55 + * Esto contiene una lista de RECURSOS, que a su vez contiene una lista
  56 + * de CALIDADES. Si no te gusta mis VERSOS, te mando a la mierda sin
  57 + * SUTILIDADES.
67 58 *
68 59 * -- Imanol, hasta las cejas de cafeรญna.
69 60 *
70   - * PD: En el รบltimo nivel de profundidad hay una lista de segmentos (debajo de calidades).
71   - * Allรญ estรก el autรฉntico tesoro de Narnia.
  61 + * PD: En el รบltimo nivel de profundidad hay una lista de segmentos
  62 + * (debajo de calidades). Allรญ estรก el autรฉntico tesoro de Narnia.
72 63 */
73   - for(int i = 0; i < lists.size(); i++)
74   - {
  64 + for (int i = 0; i < lists.size(); i++) {
75 65 sortQuality(lists.get(i));
76 66 }
77   - return lists;
  67 + return lists;
78 68 }
79   -
80   - private int searchID(String ID, ArrayList<ParentList> lists)
81   - {
82   - for(int i = 0; i < lists.size(); i++)
83   - {
84   - if(lists.get(i).getID().equals(ID))
85   - {
  69 +
  70 + private int searchID(String ID, ArrayList<ParentList> lists) {
  71 + for (int i = 0; i < lists.size(); i++) {
  72 + if (lists.get(i).getID().equals(ID)) {
86 73 return i;
87 74 }
88 75 }
89 76 return -1;
90 77 }
91   -
92   - private void sortQuality(ParentList ppls)
93   - {
  78 +
  79 + private void sortQuality(ParentList ppls) {
94 80 ArrayList<List> lists = ppls.getLists();
95   - if(lists.get(0).getQuality() == -1)
96   - {
  81 + if (lists.get(0).getQuality() == -1) {
97 82 /*
98 83 * Se trata de ext-x-media's y estos no van por calidad
99 84 */
100 85 return;
101 86 }
102   - //BUBBLE-SORT!! (Me da un poco de verguenza, pero no quiero ponerme con quicksort...
103   - while(true)
104   - {
  87 + // BUBBLE-SORT!! (Me da un poco de verguenza, pero no quiero ponerme con
  88 + // quicksort...
  89 + while (true) {
105 90 boolean sorted = true;
106 91 int i = 0;
107   - do
108   - {
109   - if(lists.get(i).getQuality() < lists.get(i+1).getQuality())
110   - {
  92 + do {
  93 + if (lists.get(i).getQuality() < lists.get(i + 1).getQuality()) {
111 94 sorted = false;
112 95 List aux = lists.get(i);
113   - lists.set(i, lists.get(i+1));
114   - lists.set(i+1, aux);
  96 + lists.set(i, lists.get(i + 1));
  97 + lists.set(i + 1, aux);
115 98 }
116   -
117   - }while(++i != lists.size());
118   - if(sorted)
119   - {
  99 +
  100 + } while (++i != lists.size());
  101 + if (sorted) {
120 102 break;
121 103 }
122 104 }
123 105  
124 106 }
125   -
126   - public void parseLine(String line, ArrayList<ParentList> lists) throws ErrorException, WarningException, InfoException
127   - {
128   - if(line.isEmpty())
129   - {
  107 +
  108 + public void parseLine(String line, ArrayList<ParentList> lists)
  109 + throws ErrorException, WarningException, InfoException {
  110 + if (line.isEmpty()) {
130 111 currentLine++;
131 112 return;
132   - }
133   - else
134   - {
135   - ParentList ppls = lists.get(currentList); //VIVA HONDURAS!!!
  113 + } else {
  114 + ParentList ppls = lists.get(currentList); // VIVA HONDURAS!!!
136 115 List pls = ppls.getLists().get(ppls.getCurrentQuality());
137   - if(!pls.getValidated())
138   - {
139   - if(line.equals(STARTWORD))
140   - {
  116 + if (!pls.getValidated()) {
  117 + if (line.equals(STARTWORD)) {
141 118 pls.setValidated(true);
142   - }
143   - else
144   - {
  119 + } else {
145 120 throw new ErrorException("Playlist is not valid");
146 121 }
147   - }
148   - else
149   - {
150   - if(line.charAt(0) == '#')
151   - {
152   - if(line.substring(0,4).equals("#EXT"))
153   - {
  122 + } else {
  123 + if (line.charAt(0) == '#') {
  124 + if (line.substring(0, 4).equals("#EXT")) {
154 125 String[] extTag = line.split(":");
155   - if(extTag[0].equals("#EXT-X-MEDIA-SEQUENCE"))
156   - {
  126 + if (extTag[0].equals("#EXT-X-MEDIA-SEQUENCE")) {
157 127 pls.setSequence(Integer.parseInt(extTag[1]));
158   - }
159   - else if(extTag[0].equals("#EXT-X-TARGETDURATION"))
160   - {
  128 + } else if (extTag[0].equals("#EXT-X-TARGETDURATION")) {
161 129 pls.setMaxDuration(Integer.parseInt(extTag[1]));
162   - }
163   - else if(extTag[0].equals("#EXTINF"))
164   - {
165   - if(fileType == -1)
166   - {
  130 + } else if (extTag[0].equals("#EXTINF")) {
  131 + if (fileType == -1) {
167 132 fileType = 0;
  133 + } else if (fileType == 1) {
  134 + throw new ErrorException(
  135 + "Invalid file, should contain Lists, "
  136 + + "but segments were found.");
168 137 }
169   - else if(fileType == 1)
170   - {
171   - throw new ErrorException("Invalid file, should contain Lists, " +
172   - "but segments were found.");
173   - }
174   - if(expectSegment)
175   - {
176   - throw new ErrorException("Expected segment URI, got a different" +
177   - "segment declaration");
  138 + if (expectSegment) {
  139 + throw new ErrorException(
  140 + "Expected segment URI, got a different"
  141 + + "segment declaration");
178 142 }
179 143 String[] args = extTag[1].split(",");
180 144 int duration = Integer.parseInt(args[0]);
181   - if (duration > pls.getMaxDuration())
182   - {
183   - throw new ErrorException("Segment " + currentSegment + " on line " + currentLine
184   - +" exceeds max duration");
  145 + if (duration > pls.getMaxDuration()) {
  146 + throw new ErrorException("Segment "
  147 + + currentSegment + " on line "
  148 + + currentLine + " exceeds max duration");
185 149 }
186 150 Segment s = new Segment(duration);
187   - if(args.length == 1)
188   - {
  151 + if (args.length == 1) {
189 152 s.setName("");
190   - }
191   - else
192   - {
  153 + } else {
193 154 s.setName(args[1]);
194 155 }
195 156 pls.getSegments().add(s);
196 157 expectSegment = true;
197 158 }
198   -
199   - else if(extTag[0].equals("#EXT-X-STREAM-INF"))
200   - {
201   - if(fileType == -1)
202   - {
  159 +
  160 + else if (extTag[0].equals("#EXT-X-STREAM-INF")) {
  161 + if (fileType == -1) {
203 162 fileType = 1;
204   - }
205   - else if(fileType == 0)
206   - {
207   - throw new ErrorException("Invalid file, should contain Segments, " +
208   - "but lists were found.");
  163 + } else if (fileType == 0) {
  164 + throw new ErrorException(
  165 + "Invalid file, should contain Segments, "
  166 + + "but lists were found.");
209 167 }
210 168 expectList = true;
211 169 String programID = "";
212 170 int bandwidth = -1;
213 171 String[] arguments = extTag[1].split(",");
214   - for(int i = 0; i < arguments.length; i++)
215   - {
  172 + for (int i = 0; i < arguments.length; i++) {
216 173 String[] argument = arguments[i].split("=");
217   - if(argument[0].equals("PROGRAM-ID"))
218   - {
  174 + if (argument[0].equals("PROGRAM-ID")) {
219 175 programID = argument[1];
220   - }
221   - else if(argument[0].equals("BANDWIDTH"))
222   - {
  176 + } else if (argument[0].equals("BANDWIDTH")) {
223 177 bandwidth = Integer.parseInt(argument[1]);
224 178 }
225 179 }
226   - if(programID.equals("")|| bandwidth == -1)
227   - {
228   - throw new ErrorException("Playlist on line " + currentLine +
229   - " has missing arguments");
  180 + if (programID.equals("") || bandwidth == -1) {
  181 + throw new ErrorException("Playlist on line "
  182 + + currentLine
  183 + + " has missing arguments");
230 184 }
231   - if(!programID.equals(ppls.getID()))
232   - {
233   - if(ppls.getID().equals(""))
234   - {
  185 + if (!programID.equals(ppls.getID())) {
  186 + if (ppls.getID().equals("")) {
235 187 /*
236   - * Este caso se da cuando no se ha creado ninguna lista.
237   - * Hay que sustituir la por defecto por una lista real.
  188 + * Este caso se da cuando no se ha creado
  189 + * ninguna lista. Hay que sustituir la por
  190 + * defecto por una lista real.
238 191 */
239   - lists.add(0,new ParentList(programID));
240   - }
241   - else
242   - {
  192 + lists.add(0, new ParentList(programID));
  193 + } else {
243 194 currentList = searchID(ppls.getID(), lists);
244   - if(currentList == -1)
245   - {
  195 + if (currentList == -1) {
246 196 lists.add(new ParentList(programID));
247   - currentList = lists.size()+1;
  197 + currentList = lists.size() + 1;
248 198 /*
249   - * ppls y pls se actualizan en la siguiente linea procesada
  199 + * ppls y pls se actualizan en la
  200 + * siguiente linea procesada
250 201 */
251   - }
252   - else
253   - {
  202 + } else {
254 203 ppls = lists.get(currentList);
255   - ppls.getLists().add(new List(bandwidth));
  204 + ppls.getLists()
  205 + .add(new List(bandwidth));
256 206 }
257 207 }
258   - }
259   - else
260   - {
  208 + } else {
261 209 ppls.getLists().add(new List(bandwidth));
262 210 }
263   - }
264   - else if(extTag[0].equals("#EXT-X-MEDIA"))
265   - {
266   - if(fileType == -1)
267   - {
  211 + } else if (extTag[0].equals("#EXT-X-MEDIA")) {
  212 + if (fileType == -1) {
268 213 fileType = 1;
269   - }
270   - else if(fileType == 0)
271   - {
272   - throw new ErrorException("Invalid file, should contain Segments, " +
273   - "but lists were found.");
  214 + } else if (fileType == 0) {
  215 + throw new ErrorException(
  216 + "Invalid file, should contain Segments, "
  217 + + "but lists were found.");
274 218 }
275 219 String Type = "";
276 220 String Name = "";
... ... @@ -278,46 +222,33 @@ public class Parser
278 222 String URI = "";
279 223 boolean Default = false;
280 224 String[] arguments = extTag[1].split(",");
281   - for(int i = 0; i < arguments.length; i++)
282   - {
  225 + for (int i = 0; i < arguments.length; i++) {
283 226 String[] argument = arguments[i].split("=");
284   - if(argument[0].equals("NAME"))
285   - {
  227 + if (argument[0].equals("NAME")) {
286 228 Name = argument[1];
287   - }
288   - else if(argument[0].equals("TYPE"))
289   - {
  229 + } else if (argument[0].equals("TYPE")) {
290 230 Type = argument[1];
291   - }
292   - else if(argument[0].equals("GROUP-ID"))
293   - {
  231 + } else if (argument[0].equals("GROUP-ID")) {
294 232 GroupID = argument[1];
295   - }
296   - else if(argument[0].equals("DEFAULT"))
297   - {
298   - if(argument[1].equals("YES"))
299   - {
  233 + } else if (argument[0].equals("DEFAULT")) {
  234 + if (argument[1].equals("YES")) {
300 235 Default = true;
301   - }
302   - else if(argument[1].equals("NO"))
303   - {
  236 + } else if (argument[1].equals("NO")) {
304 237 Default = true;
  238 + } else {
  239 + throw new ErrorException(
  240 + "Invalid value for argument DEFAULT on line "
  241 + + currentLine);
305 242 }
306   - else
307   - {
308   - throw new ErrorException("Invalid value for argument DEFAULT on line " +
309   - currentLine);
310   - }
311   - }
312   - else if(argument[0].equals("URI"))
313   - {
  243 + } else if (argument[0].equals("URI")) {
314 244 URI = argument[1];
315 245 }
316 246 }
317   - if(Type.equals("") || Name.equals("") || URI.equals("") || GroupID.equals(""))
318   - {
319   - throw new ErrorException("Playlist on line " + currentLine +
320   - " has missing arguments");
  247 + if (Type.equals("") || Name.equals("")
  248 + || URI.equals("") || GroupID.equals("")) {
  249 + throw new ErrorException("Playlist on line "
  250 + + currentLine
  251 + + " has missing arguments");
321 252 }
322 253 ParentList pl = new ParentList(GroupID);
323 254 pl.setDefault(Default);
... ... @@ -326,92 +257,74 @@ public class Parser
326 257 Parser p = new Parser();
327 258 p.parseFile(download.doInBackground(URI));
328 259 /*
329   - * Procesar URI y descargar listas recursivamente y aรฑadir a la lista actual.
  260 + * Procesar URI y descargar listas recursivamente y
  261 + * aรฑadir a la lista actual.
330 262 *
331 263 * TO-DO: Necesito la funcion de Marc
332 264 */
333 265 List l = new List(-1);
334   - if(!GroupID.equals(ppls.getID()))
335   - {
336   - if(ppls.getID().equals(""))
337   - {
  266 + if (!GroupID.equals(ppls.getID())) {
  267 + if (ppls.getID().equals("")) {
338 268 /*
339   - * Este caso se da cuando no se ha creado ninguna lista.
340   - * Hay que sustituir la por defecto por una lista real.
  269 + * Este caso se da cuando no se ha creado
  270 + * ninguna lista. Hay que sustituir la por
  271 + * defecto por una lista real.
341 272 */
342   - lists.add(0,pl);
343   - }
344   - else
345   - {
  273 + lists.add(0, pl);
  274 + } else {
346 275  
347 276 currentList = searchID(ppls.getID(), lists);
348   - if(currentList == -1)
349   - {
  277 + if (currentList == -1) {
350 278 lists.add(pl);
351   - currentList = lists.size()+1;
352   - }
353   - else
354   - {
  279 + currentList = lists.size() + 1;
  280 + } else {
355 281 ppls = lists.get(currentList);
356 282 ppls.getLists().add(l);
357 283 }
358 284 }
359   - }
360   - else
361   - {
  285 + } else {
362 286 ppls.getLists().add(l);
363 287 }
364 288 }
365   -
366   - else if(extTag[0].equals("#EXT-X-ENDLIST"))
367   - {
368   - if(expectSegment || expectList)
369   - {
370   - throw new ErrorException("Unexpected end of list!");
  289 +
  290 + else if (extTag[0].equals("#EXT-X-ENDLIST")) {
  291 + if (expectSegment || expectList) {
  292 + throw new ErrorException(
  293 + "Unexpected end of list!");
371 294 }
372   - //END REACHED, IGNORE AND LET THE FILE REACH EOF
  295 + // END REACHED, IGNORE AND LET THE FILE REACH EOF
373 296 }
374   -
375   - else
376   - {
  297 +
  298 + else {
377 299 currentLine++;
378   - throw new WarningException("Tag not implemented: " + extTag[0]);
  300 + throw new WarningException("Tag not implemented: "
  301 + + extTag[0]);
379 302 }
380   - }
381   - else
382   - {
  303 + } else {
383 304 String comment = line.substring(1);
384   - throw new InfoException("Comment on line " + currentLine++ + " " + comment);
  305 + throw new InfoException("Comment on line "
  306 + + currentLine++ + " " + comment);
385 307 }
386   - }
387   - else
388   - {
389   - if(expectSegment)
390   - {
  308 + } else {
  309 + if (expectSegment) {
391 310 expectSegment = false;
392   - try
393   - {
  311 + try {
394 312 pls.getSegments().get(currentSegment).setURL(line);
395   - }
396   - catch (MalformedURLException e)
397   - {
  313 + } catch (MalformedURLException e) {
398 314 throw new ErrorException(e.getMessage());
399 315 }
400 316 currentSegment++;
401   - }
402   - else if(expectList)
403   - {
  317 + } else if (expectList) {
404 318 expectList = false;
405 319 Parser p = new Parser();
406 320 p.parseFile(download.doInBackground(line));
407   - }
408   - else
409   - {
410   - throw new ErrorException("ERROR: Unexpected string " + line);
  321 + } else {
  322 + throw new ErrorException("ERROR: Unexpected string "
  323 + + line);
411 324 }
412 325 }
413 326 }
414 327 currentLine++;
415   - }
  328 + }
416 329 }
417 330 }
418 331 \ No newline at end of file
... ...