diff --git a/src/com/upc/pbe/upcnews/Directoris.java b/src/com/upc/pbe/upcnews/Directoris.java index 30b7137..198ebaa 100644 --- a/src/com/upc/pbe/upcnews/Directoris.java +++ b/src/com/upc/pbe/upcnews/Directoris.java @@ -126,7 +126,9 @@ public class Directoris extends Activity implements OnClickListener { Parser p = new Parser(); try { ArrayList m3u8parsed = p.parseFile(m3u8); - + /* + * Imanol: Recorda'm que et comenti una cosa sobre les excepcions! + */ } catch (ErrorException e) { e.printStackTrace(); } catch (WarningException e) { diff --git a/src/com/upc/pbe/upcnews/Parser.java b/src/com/upc/pbe/upcnews/Parser.java index 9c65b87..84b1725 100644 --- a/src/com/upc/pbe/upcnews/Parser.java +++ b/src/com/upc/pbe/upcnews/Parser.java @@ -1,5 +1,6 @@ package com.upc.pbe.upcnews; +import java.net.MalformedURLException; import java.util.ArrayList; public class Parser @@ -35,7 +36,8 @@ public class Parser { parseLine(lines[i],lists); } - /* Esto contiene una lista de RECURSOS, + /* + * Esto contiene una lista de RECURSOS, * que a su vez contiene una lista de CALIDADES. * Si no te gusta mis VERSOS, * te mando a la mierda sin SUTILIDADES. @@ -109,6 +111,11 @@ public class Parser throw new ErrorException("Invalid file, should contain Lists, " + "but segments were found."); } + if(expectSegment) + { + throw new ErrorException("Expected segment URI, got a different" + + "segment declaration"); + } String[] args = extTag[1].split(","); int duration = Integer.parseInt(args[0]); if (duration > pls.getMaxDuration()) @@ -203,29 +210,33 @@ public class Parser { if(expectSegment) { - + expectSegment = false; + try + { + pls.getSegments().get(currentSegment).setURL(line); + } + catch (MalformedURLException e) + { + throw new ErrorException(e.getMessage()); + } + currentSegment++; } else if(expectList) { - + expectList = false; + /* + * Aquí hay que bajarse la playlist que hay en la url contenida en line + * primero se baja el file, se pillan las lineas en un string enorme + * y se crea una nueva instancia de parser (pa no mezclar los argumentos) + * y se parsea con arte y gracia, luego se recogen los frutos + * + * TO-DO: Necesito la función de Marc + */ } - - /*if [[ $EXTINF -eq 1 ]]; then - echo -n "SEGMENT $CURRENT_SEGMENT: \"$NAME\" - $DURATION seconds ($line)" - EXTINF=0 - if [[ $CURRENT_SEGMENT -eq $SEQUENCE_FIRST ]]; then - echo " (first element)" else - echo "" - fi; - ((CURRENT_SEGMENT++)) - elif [[ $EXTXSTREAM -eq 1 ]]; then - echo "PLAYLIST: $line [PROGRAM-ID=$PROGRAMID,BANDWIDTH=$BANDWIDTH,RESOLUTION=$RESOLUTION,CODECS=$CODECS]" - EXTXSTREAM=0 - else - echo "ERROR: Unexpected string \"$line\"" - exit 1 - */ + { + throw new ErrorException("ERROR: Unexpected string " + line); + } } } currentLine++;