diff --git a/gen/com/upc/pbe/upcnews/R.java b/gen/com/upc/pbe/upcnews/R.java
index cebd22e..381271a 100644
--- a/gen/com/upc/pbe/upcnews/R.java
+++ b/gen/com/upc/pbe/upcnews/R.java
@@ -16,24 +16,21 @@ public final class R {
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 AbsoluteLayout1=0x7f080006;
+ public static final int ImageView01=0x7f080008;
+ public static final int ImageView1=0x7f080007;
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 button=0x7f08000b;
+ public static final int itemhelp=0x7f08000f;
+ public static final int itemprefs=0x7f08000e;
+ public static final int listView1=0x7f080003;
+ public static final int menu_settings=0x7f08000d;
+ public static final int rowTextView=0x7f08000c;
+ public static final int textView1=0x7f080004;
+ public static final int textView2=0x7f080005;
+ public static final int textViewRoute=0x7f080009;
public static final int textViewTitle=0x7f080002;
- public static final int textViewXml=0x7f08000e;
+ public static final int textViewXml=0x7f08000a;
public static final int videoView1=0x7f080000;
}
public static final class layout {
@@ -41,6 +38,7 @@ public final class R {
public static final int dirs=0x7f030001;
public static final int help=0x7f030002;
public static final int main_activity=0x7f030003;
+ public static final int rowlayout=0x7f030004;
}
public static final class menu {
public static final int activity_main=0x7f070000;
diff --git a/res/layout/dirs.xml b/res/layout/dirs.xml
index 620d798..362de1b 100644
--- a/res/layout/dirs.xml
+++ b/res/layout/dirs.xml
@@ -15,35 +15,14 @@
android:layout_marginLeft="14dp"
android:text="@string/title"
android:textAppearance="?android:attr/textAppearanceMedium" />
-
-
-
-
-
-
-
-
+ android:clickable="true"
+ android:visibility="visible" >
-
+
\ No newline at end of file
diff --git a/res/layout/rowlayout.xml b/res/layout/rowlayout.xml
new file mode 100644
index 0000000..b158315
--- /dev/null
+++ b/res/layout/rowlayout.xml
@@ -0,0 +1,7 @@
+
+
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 3ce9d79..bade7a9 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -14,7 +14,7 @@
Directoris
Button
Play
- Directories found:
+ Resource List
Logo Image
Hello world!
VideoActivity
diff --git a/src/com/upc/pbe/upcnews/Directoris.java b/src/com/upc/pbe/upcnews/Directoris.java
index 957204a..8223850 100644
--- a/src/com/upc/pbe/upcnews/Directoris.java
+++ b/src/com/upc/pbe/upcnews/Directoris.java
@@ -6,59 +6,52 @@ import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
+import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-import android.widget.Toast;
-
-public class Directoris extends Activity implements OnClickListener {
-
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.AdapterView.OnItemClickListener;
+
+public class Directoris extends Activity implements OnItemClickListener
+{
final static String TAG = "Directoris";
- String s;
- Descarrega d;
- String url;
-
- ArrayList buttons = new ArrayList();
-
- public void onCreate(Bundle savedInstanceState) {
+ private Descarrega d = new Descarrega();
+ private String URL;
+ private String currentFolder;
+ private HTMLParser parser;
+ public void onCreate(Bundle savedInstanceState)
+ {
Log.d(TAG, "onCreated");
- url = ((UpcApp) getApplication()).getUrl();
+
+
super.onCreate(savedInstanceState);
setContentView(R.layout.dirs);
-
- //Descarrega del HTML de l'index, busqueda de directoris i creacio dels botons
- this.crearButtons();
- s = ((UpcApp) getApplication()).getDesc();
-
- HTMLParser pars = new HTMLParser();
- ArrayList dirs = pars.parse(s);
-
- for (int i = 0; i < dirs.size(); i++) {
- Log.d(TAG, "Directori " + dirs.get(i).toString());
- buttons.get(i).setVisibility(View.VISIBLE);
- if(dirs.get(i).equals(""))
- {
- buttons.get(i).setText("");
- }
- else
- {
- buttons.get(i).setText(dirs.get(i));
- }
- }
+ currentFolder = ((UpcApp) getApplication()).getUrl() + "/";
+ URL = currentFolder;
+ parser = new HTMLParser(URL);
+
+ ((ListView)findViewById(R.id.listView1)).setOnItemClickListener(this);
+
+ this.showResources();
}
- public boolean onCreateOptionsMenu(Menu menu) {
+ public boolean onCreateOptionsMenu(Menu menu)
+ {
getMenuInflater().inflate(R.menu.menu, menu);
Log.d(TAG, "Menu");
return true;
}
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
+ public boolean onOptionsItemSelected(MenuItem item)
+ {
+ switch (item.getItemId())
+ {
case R.id.itemprefs:
startActivity(new Intent(this, Prefs.class));
Log.d(TAG, "Preferences");
@@ -71,48 +64,44 @@ public class Directoris extends Activity implements OnClickListener {
return false;
}
}
-
- public void onClick(View c) {
- switch (c.getId()) {
- case R.id.button1: {
- this.buttonClicked(buttons.get(0));
- break;
-
- }
- case R.id.button2: {
- this.buttonClicked(buttons.get(1));
- break;
- }
- case R.id.button3: {
- this.buttonClicked(buttons.get(2));
- break;
- }
- case R.id.button4: {
- this.buttonClicked(buttons.get(3));
- break;
+
+ public void createEntries(ArrayList directories)
+ {
+ String[] entries = directories.toArray(new String[directories.size()]);
+ ListView listView = (ListView) findViewById(R.id.listView1);
+ listView.setAdapter(null);
+ ArrayAdapter adapter = new ArrayAdapter(this, R.layout.rowlayout, entries);
+ listView.setAdapter(adapter);
+ }
+
+ public void onItemClick(AdapterView> parent, View view, int position, long id)
+ {
+ String path = ((TextView)view).getText().toString();
+ if(!path.startsWith("http://"))
+ {
+ currentFolder += path;
}
+ else
+ {
+ currentFolder = path;
}
+ showResources();
+ }
+
+ public void showResources()
+ {
+ ArrayList entries = parser.parse(d.doInBackground(currentFolder));
+ this.createEntries(entries);
}
- public void crearButtons() {
- buttons.add((Button) findViewById(R.id.button1));
- buttons.add((Button) findViewById(R.id.button2));
- buttons.add((Button) findViewById(R.id.button3));
- buttons.add((Button) findViewById(R.id.button4));
- buttons.add((Button) findViewById(R.id.button5));
-
- for (int i = 0; i < buttons.size(); i++) {
- buttons.get(i).setOnClickListener(this);
- buttons.get(i).setVisibility(View.GONE);
- }
- }
+ /*public void buttonClicked(Button b)
+ {
- 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());
String path = b.getText().toString();
- if(path.equals(""))
+ if (path.equals(""))
{
path = "";
}
@@ -120,43 +109,68 @@ public class Directoris extends Activity implements OnClickListener {
d = new Descarrega();
String str = d.doInBackground(url + "/" + path);
HTMLParser pars = new HTMLParser();
+
String urlvideo = pars.findvideo(str, url + "/" + path);
Log.d(TAG, urlvideo);
-
- //Descarrega de l'arxiu .m3u8 (si existeix) i parseig
- if (urlvideo.equalsIgnoreCase("No s'ha trobat")) {
- Toast.makeText(this, "The directory " + b.getText() + " does not contain any '.m3u8' file", Toast.LENGTH_LONG).show();
- } else {
+
+ // Descarrega de l'arxiu .m3u8 (si existeix) i parseig
+ if (urlvideo.equalsIgnoreCase("No s'ha trobat"))
+ {
+ Toast.makeText(this, "The directory " + b.getText()
+ + " does not contain any '.m3u8' file", Toast.LENGTH_LONG).show();
+ }
+ else
+ {
d = new Descarrega();
String m3u8 = d.doInBackground(urlvideo);
Log.d(TAG, m3u8);
- Parser p = new Parser(urlvideo.substring(0,urlvideo.lastIndexOf("/")+1),this);
- try {
+ Parser p = new Parser(urlvideo.substring(0, urlvideo.lastIndexOf("/") + 1), this);
+ try
+ {
ArrayList m3u8parsed = p.parseFile(m3u8);
Log.d(TAG, "parsed completed");
HLS h = new HLS(m3u8parsed);
h.start();
-
- } catch (ErrorException e) {
+
+ }
+ catch (ErrorException e)
+ {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d(TAG, e.getMessage());
- } catch (WarningException e) {
+ }
+ catch (WarningException e)
+ {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d(TAG, e.getMessage());
- } catch (InfoException e) {
+ }
+ catch (InfoException e)
+ {
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
Log.d(TAG, e.getMessage());
}
-
- }
-
-
-
- //VideoPlayer
+
+ }*/
+
/*
- String urlvid = null;
- ((UpcApp) getApplication()).setDesc(urlvid);
-
- startActivity(new Intent(this, VideoActivity.class));*/
+ * String urlvid = null; ((UpcApp) getApplication()).setDesc(urlvid);
+ *
+ * startActivity(new Intent(this, VideoActivity.class));
+
+ }*/
+
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
+ {
+ if(currentFolder.equals(URL))
+ {
+ super.finish();
+ return true;
+ }
+ currentFolder = currentFolder.substring(0, currentFolder.length()-1);
+ currentFolder = currentFolder.substring(0,currentFolder.lastIndexOf("/")+1);
+ showResources();
+ return true;
+ }
+ return super.onKeyDown(keyCode, event);
}
}
\ No newline at end of file
diff --git a/src/com/upc/pbe/upcnews/HTMLParser.java b/src/com/upc/pbe/upcnews/HTMLParser.java
index 78dc319..aeb2c5a 100644
--- a/src/com/upc/pbe/upcnews/HTMLParser.java
+++ b/src/com/upc/pbe/upcnews/HTMLParser.java
@@ -2,40 +2,108 @@ package com.upc.pbe.upcnews;
import java.util.ArrayList;
-public class HTMLParser {
-
- String code;
- ArrayList directoris;
-
- public HTMLParser(){
- this.code = null;
- directoris = new ArrayList();
- directoris.add("");
- }
-
- public ArrayList parse(String code){
- //Separem el codi en linies
- String[] split = code.split("\n");
- //Mirem a cada linia si cont� un href, i hi haur� un directori si cont� el conjunt /"
- //Si hi ha un directori, tallem l'string per obtenir-ne el nom.
- for(int i = 0; i < split.length; i++){
- if(split[i].contains("href") && split[i].contains("/index.html\"")){
- directoris.add((split[i].substring((split[i].indexOf("href="))+6, (split[i].indexOf("/index.html\"")))));
- }
- }
- return directoris;
- }
-
- public String findvideo(String code, String direccio){
- //Donada la direcci� del directori i el html del mateix, troba l'arxiu .m3u8 i retorna
- //la url directe.
- String[] split = code.split("\n");
- for(int i = 0; i < split.length; i++){
- if(split[i].contains(".m3u8") && !split[i].contains("._")){
- String nomarxiu = split[i].substring((split[i].indexOf("href="))+6, (split[i].indexOf('"',(split[i].indexOf("href="))+6)));
- return direccio+nomarxiu;
- }
- }
- return "No s'ha trobat";
- }
+import android.util.Log;
+
+public class HTMLParser
+{
+ private final static String TAG = "HTMLParser";
+ private ArrayList resources;
+ private String server;
+
+ public HTMLParser(String u)
+ {
+ String host = u.substring(7);
+ server = u.substring(0,host.indexOf("/")+7);
+ resources = new ArrayList();
+ }
+
+ public ArrayList parse(String code)
+ {
+ if(!resources.isEmpty())
+ {
+ resources.clear();
+ }
+ parseDirectories(resources,code);
+ //parseFiles(resources,code);
+ return resources;
+ }
+
+ public void parseDirectories(ArrayList resources, String code)
+ {
+ // Separem el codi en linies
+ String[] split = code.split("\n");
+ /*
+ * Busquemos el tag , descartando comentarios:
+ */
+ for (int i = 0; i < split.length; i++)
+ {
+ while (split[i].startsWith(""))
+ {
+ break;
+ }
+ }
+ // Posible comentario descartado
+ if (split[i].indexOf(" findvideo(String code, String direccio)
+ {
+ // Donada la direcci� del directori i el html del mateix, troba l'arxiu
+ // .m3u8 i retorna
+ // la url directe.
+ String[] split = code.split("\n");
+
+ for (int i = 0; i < split.length; i++)
+ {
+ while (split[i].startsWith(""))
+ {
+ break;
+ }
+ }
+ // Posible comentario descartado
+ if (split[i].contains(" parseFile(String file) throws ErrorException, WarningException, InfoException
{
ArrayList lists = new ArrayList();
lists.add(new ParentList(""));
lists.get(0).getLists().add(new List(-1));
String[] lines = file.split("\n");
- for(int i = 0; i < lines.length; i++)
+ for (int i = 0; i < lines.length; i++)
{
- if(lines[i].endsWith("\\"))
+ if (lines[i].endsWith("\\"))
{
/*
- * Merge multiline entries, which are those lines ending with backslash.
+ * Merge multiline entries, which are those lines ending with
+ * backslash.
*/
- lines[++i] = lines[i-1].substring(0, lines[i-1].indexOf("\\")-1) + lines[i];
+ lines[++i] = lines[i - 1].substring(0, lines[i - 1].indexOf("\\") - 1)
+ + lines[i];
}
try
{
- parseLine(lines[i],lists);
+ parseLine(lines[i], lists);
}
- catch(InfoException iE)
+ catch (InfoException iE)
{
Toast.makeText(caller, iE.getMessage(), Toast.LENGTH_SHORT).show();
}
- catch(WarningException wE)
+ catch (WarningException wE)
{
Toast.makeText(caller, wE.getMessage(), Toast.LENGTH_SHORT).show();
}
}
- /*
- * 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.
+ /*
+ * 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.
*
* -- Imanol, hasta las cejas de cafeína.
*
- * PD: En el último nivel de profundidad hay una lista de segmentos (debajo de calidades).
- * Allí está el auténtico tesoro de Narnia.
+ * PD: En el último nivel de profundidad hay una lista de segmentos
+ * (debajo de calidades). Allí está el auténtico tesoro de Narnia.
*/
- for(int i = 0; i < lists.size(); i++)
+ for (int i = 0; i < lists.size(); i++)
{
sortQuality(lists.get(i));
}
- return lists;
+ return lists;
}
-
+
private int searchID(String ID, ArrayList lists)
{
- for(int i = 0; i < lists.size(); i++)
+ for (int i = 0; i < lists.size(); i++)
{
- if(lists.get(i).getID().equals(ID))
+ if (lists.get(i).getID().equals(ID))
{
return i;
}
}
return -1;
}
-
+
private void sortQuality(ParentList ppls)
{
ArrayList lists = ppls.getLists();
- if(lists.get(0).getQuality() == -1)
+ if (lists.get(0).getQuality() == -1)
{
/*
- * That's the case of Media lists and Segment lists, they don't have distinct qualities.
+ * That's the case of Media lists and Segment lists, they don't have
+ * distinct qualities.
*/
return;
}
- //Bubblesort
- while(true)
+ // Bubblesort
+ while (true)
{
boolean sorted = true;
int i = 0;
do
{
- if(lists.get(i).getQuality() < lists.get(i+1).getQuality())
+ if (lists.get(i).getQuality() < lists.get(i + 1).getQuality())
{
sorted = false;
List aux = lists.get(i);
- lists.set(i, lists.get(i+1));
- lists.set(i+1, aux);
+ lists.set(i, lists.get(i + 1));
+ lists.set(i + 1, aux);
}
-
- }while(++i != lists.size()-1);
- if(sorted)
+
+ }
+ while (++i != lists.size() - 1);
+ if (sorted)
{
break;
}
}
}
-
+
public void parseLine(String line, ArrayList lists) throws ErrorException, WarningException, InfoException
{
- if(line.isEmpty())
+ if (line.isEmpty())
{
currentLine++;
return;
@@ -139,10 +141,10 @@ public class Parser
else
{
ParentList ppls = lists.get(currentList);
- List pls = ppls.getLists().get(ppls.getLists().size()-1);
- if(!validated)
+ List pls = ppls.getLists().get(ppls.getLists().size() - 1);
+ if (!validated)
{
- if(line.equals(STARTWORD))
+ if (line.equals(STARTWORD))
{
validated = true;
}
@@ -153,47 +155,48 @@ public class Parser
}
else
{
- if(line.charAt(0) == '#')
+ if (line.charAt(0) == '#')
{
- if(line.substring(0,4).equals("#EXT"))
+ if (line.substring(0, 4).equals("#EXT"))
{
- if(expectSegment)
+ if (expectSegment)
{
throw new ErrorException("Expected segment URI, got an EXT-TAG instead");
}
- if(expectList)
+ 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"))
+ if (extTag[0].equals("#EXT-X-MEDIA-SEQUENCE"))
{
pls.setSequence(Integer.parseInt(extTag[1]));
}
- else if(extTag[0].equals("#EXT-X-TARGETDURATION"))
+ else if (extTag[0].equals("#EXT-X-TARGETDURATION"))
{
pls.setMaxDuration(Integer.parseInt(extTag[1]));
- }
- else if(extTag[0].equals("#EXTINF"))
+ }
+ else if (extTag[0].equals("#EXTINF"))
{
- if(fileType == -1)
+ if (fileType == -1)
{
fileType = 0;
}
- else if(fileType == 1)
+ else if (fileType == 1)
{
- throw new ErrorException("Invalid file, should contain Lists, " +
- "but segments were found.");
+ throw new ErrorException("Invalid file, should contain Lists, "
+ + "but segments were found.");
}
String[] args = extTag[1].split(",");
float duration = Float.parseFloat(args[0]);
if (duration > pls.getMaxDuration())
{
- throw new ErrorException("Segment " + currentSegment+1 + " on line " + currentLine
- +" exceeds max duration");
+ throw new ErrorException("Segment "
+ + currentSegment + 1 + " on line "
+ + currentLine + " exceeds max duration");
}
Segment s = new Segment(duration);
- if(args.length == 1)
+ if (args.length == 1)
{
s.setName("");
}
@@ -204,42 +207,46 @@ public class Parser
pls.getSegments().add(s);
expectSegment = true;
}
-
- else if(extTag[0].equals("#EXT-X-STREAM-INF"))
+
+ else if (extTag[0].equals("#EXT-X-STREAM-INF"))
{
- if(fileType == -1)
+ if (fileType == -1)
{
fileType = 1;
}
- else if(fileType == 0)
+ else if (fileType == 0)
{
- throw new ErrorException("Invalid file, should contain Segments, " +
- "but lists were found.");
+ throw new ErrorException("Invalid file, should contain Segments, "
+ + "but lists were found.");
}
expectList = true;
String programID = "";
int bandwidth = -1;
String[] arguments = extTag[1].split(",");
- for(int i = 0; i < arguments.length; i++)
+ for (int i = 0; i < arguments.length; i++)
{
String[] argument = arguments[i].split("=");
/*
- * In case current argument contains several values like "val1,val2,val3"
- * detect the " character and merge them all in one single string
+ * In case current argument contains several
+ * values like "val1,val2,val3" detect the "
+ * character and merge them all in one single
+ * string
*/
- if(argument[1].startsWith("\"") && !argument[1].endsWith("\""))
+ if (argument[1].startsWith("\"")
+ && !argument[1].endsWith("\""))
{
int j = i;
- while(true)
+ while (true)
{
- if(i == arguments.length-1)
+ if (i == arguments.length - 1)
{
- throw new ErrorException("Malformed argument on line " + currentLine);
+ throw new ErrorException("Malformed argument on line "
+ + currentLine);
}
- if(arguments[++i].endsWith("\""))
+ if (arguments[++i].endsWith("\""))
{
String end = arguments[i];
- for(int k = j+1; k < i; k++)
+ for (int k = j + 1; k < i; k++)
{
argument[1] += arguments[k];
}
@@ -248,51 +255,62 @@ public class Parser
}
}
}
- if(argument[0].equals("PROGRAM-ID"))
+ if (argument[0].equals("PROGRAM-ID"))
{
programID = argument[1];
}
- else if(argument[0].equals("BANDWIDTH"))
+ else if (argument[0].equals("BANDWIDTH"))
{
bandwidth = Integer.parseInt(argument[1]);
}
}
- if(programID.equals("")|| bandwidth == -1)
+ if (programID.equals("") || bandwidth == -1)
{
- throw new ErrorException("Playlist on line " + currentLine +
- " has missing arguments");
+ throw new ErrorException("Playlist on line "
+ + currentLine
+ + " has missing arguments");
}
- if(!programID.equals(ppls.getID())) //If Program-ID doesn't match, search it or create a new one.
+ if (!programID.equals(ppls.getID()))
{
- if(ppls.getID().equals(""))
+ /*
+ * If Program-ID doesn't match, search it or
+ * create a new one.
+ */
+ if (ppls.getID().equals(""))
{
/*
- * If working with the default ParentList, then modify it, don't create a new one.
+ * 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(programID, lists);
- if(currentList == -1)
+ if (currentList == -1)
{
/*
- * ParentList not found, creating a new one.
+ * ParentList not found, creating a new
+ * one.
*/
lists.add(new ParentList(programID));
- currentList = lists.size() -1;
+ currentList = lists.size() - 1;
}
ppls = lists.get(currentList);
- pls = ppls.getLists().get(ppls.getLists().size()-1);
+ pls = ppls.getLists().get(ppls.getLists().size() - 1);
}
}
/*
- * Now we create a new List inside the correct ParentList.
+ * Now we create a new List inside the correct
+ * ParentList.
*/
- if((ppls.getLists().size() == 1) && (pls.getQuality() == -1) && pls.getSegments().isEmpty())
+ 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.
+ * If working with the default List, then modify
+ * it, don't create a new one.
*/
pls.setQuality(bandwidth);
}
@@ -301,16 +319,16 @@ public class Parser
ppls.getLists().add(new List(bandwidth));
}
}
- else if(extTag[0].equals("#EXT-X-MEDIA"))
+ else if (extTag[0].equals("#EXT-X-MEDIA"))
{
- if(fileType == -1)
+ if (fileType == -1)
{
fileType = 1;
}
- else if(fileType == 0)
+ else if (fileType == 0)
{
- throw new ErrorException("Invalid file, should contain Segments, " +
- "but lists were found.");
+ throw new ErrorException("Invalid file, should contain Segments, "
+ + "but lists were found.");
}
String Type = "";
String Name = "";
@@ -318,26 +336,30 @@ public class Parser
String URI = "";
boolean Default = false;
String[] arguments = extTag[1].split(",");
- for(int i = 0; i < arguments.length; i++)
+ for (int i = 0; i < arguments.length; i++)
{
String[] argument = arguments[i].split("=");
/*
- * In case current argument contains several values like "val1,val2,val3"
- * detect the " character and merge them all in one single string
+ * In case current argument contains several
+ * values like "val1,val2,val3" detect the "
+ * character and merge them all in one single
+ * string
*/
- if(argument[1].startsWith("\"") && !argument[1].endsWith("\""))
+ if (argument[1].startsWith("\"")
+ && !argument[1].endsWith("\""))
{
int j = i;
- while(true)
+ while (true)
{
- if(i == arguments.length-1)
+ if (i == arguments.length - 1)
{
- throw new ErrorException("Malformed argument on line " + currentLine);
+ throw new ErrorException("Malformed argument on line "
+ + currentLine);
}
- if(arguments[++i].endsWith("\""))
+ if (arguments[++i].endsWith("\""))
{
String end = arguments[i];
- for(int k = j+1; k < i; k++)
+ for (int k = j + 1; k < i; k++)
{
argument[1] += arguments[k];
}
@@ -346,62 +368,66 @@ public class Parser
}
}
}
- if(argument[0].equals("NAME"))
+ if (argument[0].equals("NAME"))
{
- Name = argument[1].substring(1,argument[1].length()-1);
+ Name = argument[1].substring(1, argument[1].length() - 1);
}
- else if(argument[0].equals("TYPE"))
+ else if (argument[0].equals("TYPE"))
{
Type = argument[1];
}
- else if(argument[0].equals("GROUP-ID"))
+ else if (argument[0].equals("GROUP-ID"))
{
- GroupID = argument[1].substring(1,argument[1].length()-1);
+ GroupID = argument[1].substring(1, argument[1].length() - 1);
}
- else if(argument[0].equals("DEFAULT"))
+ else if (argument[0].equals("DEFAULT"))
{
- if(argument[1].equals("YES"))
+ if (argument[1].equals("YES"))
{
Default = true;
}
- else if(argument[1].equals("NO"))
+ else if (argument[1].equals("NO"))
{
Default = true;
}
else
{
- throw new ErrorException("Invalid value for argument DEFAULT on line " +
- currentLine);
+ throw new ErrorException("Invalid value for argument DEFAULT on line "
+ + currentLine);
}
}
- else if(argument[0].equals("URI"))
+ else if (argument[0].equals("URI"))
{
- if(!argument[1].contains("http://"))
+ if (!argument[1].contains("http://"))
{
/*
* In case the path read is RELATIVE
*/
- URI = path + argument[1].substring(1,argument[1].length()-1);
+ URI = path
+ + argument[1].substring(1, argument[1].length() - 1);
}
else
{
- URI = argument[1].substring(1,argument[1].length()-1);
+ URI = argument[1].substring(1, argument[1].length() - 1);
}
}
}
- if(Type.equals("") || Name.equals("") || URI.equals("") || GroupID.equals(""))
+ if (Type.equals("") || Name.equals("")
+ || URI.equals("") || GroupID.equals(""))
{
- throw new ErrorException("Playlist on line " + currentLine +
- " has missing arguments");
+ throw new ErrorException("Playlist on line "
+ + currentLine
+ + " has missing arguments");
}
- Parser p = new Parser(URI.substring(0, URI.lastIndexOf("/")+1),caller);
+ 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 (!GroupID.equals(ppls.getID()))
{
- if(ppls.getID().equals(""))
+ if (ppls.getID().equals(""))
{
/*
- * If working with the default ParentList, then modify it, don't create a new one.
+ * If working with the default ParentList,
+ * then modify it, don't create a new one.
*/
ppls.setDefault(Default);
ppls.setName(Name);
@@ -413,14 +439,14 @@ public class Parser
{
currentList = searchID(GroupID, lists);
- if(currentList == -1)
+ if (currentList == -1)
{
ParentList pl = new ParentList(GroupID);
pl.setDefault(Default);
pl.setName(Name);
pl.setType(Type);
lists.add(pl);
- currentList = lists.size()-1;
+ currentList = lists.size() - 1;
}
ppls = lists.get(currentList);
ppls.getLists().add(newList);
@@ -431,40 +457,42 @@ public class Parser
ppls.getLists().add(newList);
}
}
-
- else if(extTag[0].equals("#EXT-X-ENDLIST"))
+
+ else if (extTag[0].equals("#EXT-X-ENDLIST"))
{
- if(expectSegment || expectList)
+ if (expectSegment || expectList)
{
throw new ErrorException("Unexpected end of list!");
- }
+ }
}
- else if(extTag[0].equals("#EXT-X-VERSION"))
+ else if (extTag[0].equals("#EXT-X-VERSION"))
{
- //IGNORE
+ // IGNORE
}
- else if(extTag[0].equals("#EXT-X-PLAYLIST-TYPE"))
+ else if (extTag[0].equals("#EXT-X-PLAYLIST-TYPE"))
{
- //IGNORE
+ // IGNORE
}
-
+
else
{
currentLine++;
- throw new WarningException("Tag not implemented: " + extTag[0]);
+ throw new WarningException("Tag not implemented: "
+ + extTag[0]);
}
}
else
{
String comment = line.substring(1);
- throw new InfoException("Comment on line " + currentLine++ + " " + comment);
+ throw new InfoException("Comment on line "
+ + currentLine++ + " " + comment);
}
}
else
{
- if(expectSegment)
+ if (expectSegment)
{
expectSegment = false;
try
@@ -477,28 +505,30 @@ public class Parser
}
currentSegment++;
}
- else if(expectList)
+ else if (expectList)
{
/*
- * Download list and merge the entries with the current list
+ * Download list and merge the entries with the current
+ * list
*/
expectList = false;
- Parser p = new Parser(line.substring(0,line.lastIndexOf("/")+1),caller);
+ 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++)
+ for (int i = 0; i < newList.getSegments().size(); i++)
{
pls.getSegments().add(newList.getSegments().get(i));
}
}
else
{
- throw new ErrorException("ERROR: Unexpected string " + line);
+ throw new ErrorException("ERROR: Unexpected string "
+ + line);
}
}
}
currentLine++;
- }
+ }
}
}
\ No newline at end of file