diff --git a/gen/com/upc/pbe/upcnews/R.java b/gen/com/upc/pbe/upcnews/R.java
index 7054edd..cebd22e 100644
--- a/gen/com/upc/pbe/upcnews/R.java
+++ b/gen/com/upc/pbe/upcnews/R.java
@@ -1,76 +1,76 @@
-/* AUTO-GENERATED FILE. DO NOT MODIFY.
- *
- * This class was automatically generated by the
- * aapt tool from the resource data it found. It
- * should not be modified by hand.
- */
-
-package com.upc.pbe.upcnews;
-
-public final class R {
- public static final class attr {
- }
- public static final class drawable {
- public static final int ic_action_search=0x7f020000;
- public static final int ic_launcher=0x7f020001;
- public static final int ic_menu_name=0x7f020002;
- }
- public static final class id {
- public static final int AbsoluteLayout1=0x7f08000a;
- public static final int ImageView01=0x7f08000c;
- public static final int ImageView1=0x7f08000b;
- public static final int LinearLayout1=0x7f080001;
- public static final int button=0x7f08000f;
- public static final int button1=0x7f080003;
- public static final int button2=0x7f080004;
- public static final int button3=0x7f080005;
- public static final int button4=0x7f080006;
- public static final int button5=0x7f080007;
- public static final int itemhelp=0x7f080012;
- public static final int itemprefs=0x7f080011;
- public static final int menu_settings=0x7f080010;
- public static final int textView1=0x7f080008;
- public static final int textView2=0x7f080009;
- public static final int textViewRoute=0x7f08000d;
- public static final int textViewTitle=0x7f080002;
- public static final int textViewXml=0x7f08000e;
- public static final int videoView1=0x7f080000;
- }
- public static final class layout {
- public static final int activity_video=0x7f030000;
- public static final int dirs=0x7f030001;
- public static final int help=0x7f030002;
- public static final int main_activity=0x7f030003;
- }
- public static final class menu {
- public static final int activity_main=0x7f070000;
- public static final int activity_video=0x7f070001;
- public static final int menu=0x7f070002;
- }
- public static final class string {
- public static final int app_name=0x7f050000;
- public static final int button=0x7f05000c;
- public static final int button1=0x7f05000d;
- public static final int desc=0x7f050009;
- public static final int descarregar=0x7f050003;
- public static final int dir=0x7f05000a;
- public static final int directoris=0x7f05000b;
- public static final int hello_world=0x7f050010;
- public static final int help=0x7f050008;
- public static final int hint=0x7f050004;
- public static final int logodescription=0x7f05000f;
- public static final int menu_settings=0x7f050001;
- public static final int prefs=0x7f050007;
- public static final int title=0x7f05000e;
- public static final int title_activity_main=0x7f050002;
- public static final int title_activity_video=0x7f050011;
- public static final int url=0x7f050005;
- public static final int urlhint=0x7f050006;
- }
- public static final class style {
- public static final int AppTheme=0x7f060000;
- }
- public static final class xml {
- public static final int prefs=0x7f040000;
- }
-}
+/* AUTO-GENERATED FILE. DO NOT MODIFY.
+ *
+ * This class was automatically generated by the
+ * aapt tool from the resource data it found. It
+ * should not be modified by hand.
+ */
+
+package com.upc.pbe.upcnews;
+
+public final class R {
+ public static final class attr {
+ }
+ public static final class drawable {
+ public static final int ic_action_search=0x7f020000;
+ public static final int ic_launcher=0x7f020001;
+ public static final int ic_menu_name=0x7f020002;
+ }
+ public static final class id {
+ public static final int AbsoluteLayout1=0x7f08000a;
+ public static final int ImageView01=0x7f08000c;
+ public static final int ImageView1=0x7f08000b;
+ public static final int LinearLayout1=0x7f080001;
+ public static final int button=0x7f08000f;
+ public static final int button1=0x7f080003;
+ public static final int button2=0x7f080004;
+ public static final int button3=0x7f080005;
+ public static final int button4=0x7f080006;
+ public static final int button5=0x7f080007;
+ public static final int itemhelp=0x7f080012;
+ public static final int itemprefs=0x7f080011;
+ public static final int menu_settings=0x7f080010;
+ public static final int textView1=0x7f080008;
+ public static final int textView2=0x7f080009;
+ public static final int textViewRoute=0x7f08000d;
+ public static final int textViewTitle=0x7f080002;
+ public static final int textViewXml=0x7f08000e;
+ public static final int videoView1=0x7f080000;
+ }
+ public static final class layout {
+ public static final int activity_video=0x7f030000;
+ public static final int dirs=0x7f030001;
+ public static final int help=0x7f030002;
+ public static final int main_activity=0x7f030003;
+ }
+ public static final class menu {
+ public static final int activity_main=0x7f070000;
+ public static final int activity_video=0x7f070001;
+ public static final int menu=0x7f070002;
+ }
+ public static final class string {
+ public static final int app_name=0x7f050000;
+ public static final int button=0x7f05000c;
+ public static final int button1=0x7f05000d;
+ public static final int desc=0x7f050009;
+ public static final int descarregar=0x7f050003;
+ public static final int dir=0x7f05000a;
+ public static final int directoris=0x7f05000b;
+ public static final int hello_world=0x7f050010;
+ public static final int help=0x7f050008;
+ public static final int hint=0x7f050004;
+ public static final int logodescription=0x7f05000f;
+ public static final int menu_settings=0x7f050001;
+ public static final int prefs=0x7f050007;
+ public static final int title=0x7f05000e;
+ public static final int title_activity_main=0x7f050002;
+ public static final int title_activity_video=0x7f050011;
+ public static final int url=0x7f050005;
+ public static final int urlhint=0x7f050006;
+ }
+ public static final class style {
+ public static final int AppTheme=0x7f060000;
+ }
+ public static final class xml {
+ public static final int prefs=0x7f040000;
+ }
+}
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f68c8b2..3ce9d79 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2,7 +2,7 @@
UPC NEWS
Settings
- MainActivity
+ UPC NEWS
Start Application
Click to Start or go to Settings for Help
URL server
diff --git a/src/com/upc/pbe/upcnews/Directoris.java b/src/com/upc/pbe/upcnews/Directoris.java
index 8687523..7a2a634 100644
--- a/src/com/upc/pbe/upcnews/Directoris.java
+++ b/src/com/upc/pbe/upcnews/Directoris.java
@@ -102,7 +102,7 @@ public class Directoris extends Activity implements OnClickListener {
public void buttonClicked(Button b) {
- //Descarrega de la pàgina HTML del directori i busqueda d'un .m3u8 en ella
+ //Descarrega de la p�gina HTML del directori i busqueda d'un .m3u8 en ella
Log.d(TAG, "Click on " + b.getText());
d = new Descarrega();
String str = d.doInBackground(url + "/" + b.getText() + "/");
@@ -117,8 +117,7 @@ public class Directoris extends Activity implements OnClickListener {
d = new Descarrega();
String m3u8 = d.doInBackground(urlvideo);
Log.d(TAG, m3u8);
- Parser p = new Parser();
-
+ Parser p = new Parser(urlvideo.substring(0,urlvideo.lastIndexOf("/")+1),this);
try {
ArrayList m3u8parsed = p.parseFile(m3u8);
Log.d(TAG, "parsed completed");
diff --git a/src/com/upc/pbe/upcnews/Parser.java b/src/com/upc/pbe/upcnews/Parser.java
index 8b43707..8a242db 100644
--- a/src/com/upc/pbe/upcnews/Parser.java
+++ b/src/com/upc/pbe/upcnews/Parser.java
@@ -3,12 +3,13 @@ package com.upc.pbe.upcnews;
import java.net.MalformedURLException;
import java.util.ArrayList;
-import android.util.Log;
+import android.app.Activity;
+import android.widget.Toast;
public class Parser
{
private static final String STARTWORD = "#EXTM3U";
- private static String TAG = "Parser";
+ private String path; //CWD, completes implicit paths such as "file.m3u8" appending the CWD in order to download the file
private int fileType; //indicates if segment list or media list
private int currentLine;
private int currentSegment; //Cada segmento de cada calidad distinta
@@ -16,18 +17,12 @@ public class Parser
private boolean expectSegment = false;
private boolean expectList = false;
private Descarrega download;
+ private Activity caller; //Where to send notifications and warnings
- /*
- * TO-DO:
- * RECICLAR ZILLONES DE CÓDIGO REPETIDO
- * LIMPIAR Y DOCUMENTAR
- * DOWNLOAD REPEATED
- * MEDIA'S NOT WORKING
- */
-
-
- public Parser()
+ public Parser(String p,Activity caller)
{
+ this.caller = caller;
+ path = p;
currentLine = 0;
currentSegment = 0;
currentList = 0;
@@ -46,26 +41,26 @@ public class Parser
lists.add(new ParentList(""));
lists.get(0).getLists().add(new List(-1));
String[] lines = file.split("\n");
- Log.d(TAG, "" + lines.length);
for(int i = 0; i < lines.length; i++)
{
if(lines[i].endsWith("\\"))
{
- lines[++i] = lines[i-1].substring(0, lines[i-1].indexOf("\\")-1) + lines[i];
+ /*
+ * Merge multiline entries, which are those lines ending with backslash.
+ */
+ lines[++i] = lines[i-1].substring(0, lines[i-1].indexOf("\\")-1) + lines[i];
}
try
{
-
- Log.d(TAG, lines[i]);
parseLine(lines[i],lists);
}
catch(InfoException iE)
{
- //Toast.makeText(this, iE.getMessage(), Toast.LENGTH_SHORT).show();
+ Toast.makeText(caller, iE.getMessage(), Toast.LENGTH_SHORT).show();
}
catch(WarningException wE)
{
-
+ Toast.makeText(caller, wE.getMessage(), Toast.LENGTH_SHORT).show();
}
}
/*
@@ -104,11 +99,11 @@ public class Parser
if(lists.get(0).getQuality() == -1)
{
/*
- * Se trata de ext-x-media's y estos no van por calidad
+ * That's the case of Media lists and Segment lists, they don't have distinct qualities.
*/
return;
}
- //BUBBLE-SORT!! (Me da un poco de verguenza, pero no quiero ponerme con quicksort...
+ //Bubblesort
while(true)
{
boolean sorted = true;
@@ -123,7 +118,7 @@ public class Parser
lists.set(i+1, aux);
}
- }while(++i != lists.size());
+ }while(++i != lists.size()-1);
if(sorted)
{
break;
@@ -141,8 +136,7 @@ public class Parser
}
else
{
- ParentList ppls = lists.get(currentList); //VIVA HONDURAS!!!
- int b = ppls.getLists().size();
+ ParentList ppls = lists.get(currentList);
List pls = ppls.getLists().get(ppls.getLists().size()-1);
if(!ppls.getValidated())
{
@@ -161,7 +155,15 @@ public class Parser
{
if(line.substring(0,4).equals("#EXT"))
{
- String[] extTag = line.split(":");
+ if(expectSegment)
+ {
+ throw new ErrorException("Expected segment URI, got an EXT-TAG instead");
+ }
+ if(expectList)
+ {
+ throw new ErrorException("Expected List, got an EXT-TAG instead");
+ }
+ String[] extTag = line.split(":", 2);
if(extTag[0].equals("#EXT-X-MEDIA-SEQUENCE"))
{
pls.setSequence(Integer.parseInt(extTag[1]));
@@ -181,16 +183,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(",");
float duration = Float.parseFloat(args[0]);
if (duration > pls.getMaxDuration())
{
- throw new ErrorException("Segment " + currentSegment + " on line " + currentLine
+ throw new ErrorException("Segment " + currentSegment+1 + " on line " + currentLine
+" exceeds max duration");
}
Segment s = new Segment(duration);
@@ -238,36 +235,38 @@ public class Parser
throw new ErrorException("Playlist on line " + currentLine +
" has missing arguments");
}
- if(!programID.equals(ppls.getID())) //Si el programID no coincide, crea o busca la parentlist que toca
+ if(!programID.equals(ppls.getID())) //If Program-ID doesn't match, search it or create a new one.
{
if(ppls.getID().equals(""))
{
/*
- * Este caso se da cuando no se ha creado ninguna lista.
- * Hay que sustituir la por defecto por una lista real.
+ * If working with the default ParentList, then modify it, don't create a new one.
*/
- lists.get(0).setID(programID);
+ lists.get(0).setID(programID);
}
else
{
currentList = searchID(ppls.getID(), lists);
if(currentList == -1)
{
- lists.add(new ParentList(programID));
/*
- * ppls y pls se actualizan en la siguiente linea procesada
+ * ParentList not found, creating a new one.
*/
+ lists.add(new ParentList(programID));
currentList = lists.size() + 1;
}
ppls = lists.get(currentList);
pls = ppls.getLists().get(ppls.getLists().size()-1);
-
}
}
- // Ahora crea la lista adecuada dentro de la parentlist
- int a = ppls.getLists().size();
+ /*
+ * Now we create a new List inside the correct ParentList.
+ */
if((ppls.getLists().size() == 1) && (pls.getQuality() == -1) && pls.getSegments().isEmpty())
{
+ /*
+ * If working with the default List, then modify it, don't create a new one.
+ */
pls.setQuality(bandwidth);
}
else
@@ -297,7 +296,7 @@ public class Parser
String[] argument = arguments[i].split("=");
if(argument[0].equals("NAME"))
{
- Name = argument[1];
+ Name = argument[1].substring(1,argument[1].length()-1);
}
else if(argument[0].equals("TYPE"))
{
@@ -305,7 +304,7 @@ public class Parser
}
else if(argument[0].equals("GROUP-ID"))
{
- GroupID = argument[1];
+ GroupID = argument[1].substring(1,argument[1].length()-1);
}
else if(argument[0].equals("DEFAULT"))
{
@@ -325,7 +324,17 @@ public class Parser
}
else if(argument[0].equals("URI"))
{
- URI = argument[1];
+ if(!argument[1].contains("http://"))
+ {
+ /*
+ * In case the path read is RELATIVE
+ */
+ URI = path += argument[1].substring(1,argument[1].length()-1);
+ }
+ else
+ {
+ URI = argument[1].substring(1,argument[1].length()-1);
+ }
}
}
if(Type.equals("") || Name.equals("") || URI.equals("") || GroupID.equals(""))
@@ -333,30 +342,20 @@ public class Parser
throw new ErrorException("Playlist on line " + currentLine +
" has missing arguments");
}
- ParentList pl = new ParentList(GroupID);
- pl.setDefault(Default);
- pl.setName(Name);
- pl.setType(Type);
- Parser p = new Parser();
- p.parseFile(download.doInBackground(URI));
- /*
- * Procesar URI y descargar listas recursivamente y añadir a la lista actual.
- *
- * TO-DO: Necesito la funcion de Marc
- */
- List l = new List(-1);
+ Parser p = new Parser(URI.substring(0, URI.lastIndexOf("/")+1),caller);
+ List newList = p.parseFile(download.doInBackground(URI)).get(0).getLists().get(0);
if(!GroupID.equals(ppls.getID()))
{
if(ppls.getID().equals(""))
{
/*
- * Este caso se da cuando no se ha creado ninguna lista.
- * Hay que sustituir la por defecto por una lista real.
+ * If working with the default ParentList, then modify it, don't create a new one.
*/
ppls.setDefault(Default);
ppls.setName(Name);
ppls.setType(Type);
- lists.add(0,pl);
+ ppls.getLists().set(0, newList);
+ ppls.setID(GroupID);
}
else
{
@@ -364,19 +363,20 @@ public class Parser
currentList = searchID(ppls.getID(), lists);
if(currentList == -1)
{
+ ParentList pl = new ParentList(GroupID);
+ pl.setDefault(Default);
+ pl.setName(Name);
+ pl.setType(Type);
lists.add(pl);
currentList = lists.size()+1;
}
- else
- {
- ppls = lists.get(currentList);
- ppls.getLists().add(l);
- }
+ ppls = lists.get(currentList);
+ ppls.getLists().add(newList);
}
}
else
{
- ppls.getLists().add(l);
+ ppls.getLists().add(newList);
}
}
@@ -385,8 +385,7 @@ public class Parser
if(expectSegment || expectList)
{
throw new ErrorException("Unexpected end of list!");
- }
- //END REACHED, IGNORE AND LET THE FILE REACH EOF
+ }
}
else
@@ -418,12 +417,17 @@ public class Parser
}
else if(expectList)
{
+ /*
+ * Download list and merge the entries with the current list
+ */
expectList = false;
- Parser p = new Parser();
- ArrayList newLists = p.parseFile(download.doInBackground(line));
- for(int i = 0; i < newLists.get(0).getLists().get(0).getSegments().size(); i++)
+ Parser p = new Parser(line.substring(0,line.lastIndexOf("/")+1),caller);
+ List newList = p.parseFile(download.doInBackground(line)).get(0).getLists().get(0);
+ pls.setMaxDuration(newList.getMaxDuration());
+ pls.setSequence(newList.getSequence());
+ for(int i = 0; i < newList.getSegments().size(); i++)
{
- pls.getSegments().add(newLists.get(0).getLists().get(0).getSegments().get(i));
+ pls.getSegments().add(newList.getSegments().get(i));
}
}
else