From c4e4b49c6cb89b9e84967996665dff0ec6704943 Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Wed, 5 Dec 2012 15:07:00 +0000 Subject: [PATCH] --- gen/com/upc/pbe/upcnews/R.java | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------- src/com/upc/pbe/upcnews/List.java | 13 +------------ src/com/upc/pbe/upcnews/ParentList.java | 5 +++++ src/com/upc/pbe/upcnews/Parser.java | 419 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/com/upc/pbe/upcnews/Segment.java | 6 +++--- 5 files changed, 338 insertions(+), 257 deletions(-) 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/src/com/upc/pbe/upcnews/List.java b/src/com/upc/pbe/upcnews/List.java index 25e566a..dbaff23 100644 --- a/src/com/upc/pbe/upcnews/List.java +++ b/src/com/upc/pbe/upcnews/List.java @@ -9,8 +9,7 @@ public class List private int sequenceFirst; private int maxDuration; private ArrayList segments; //Lista de SEGMENTOS - private ParentList parent; - + public List(int q) { quality = q; @@ -53,16 +52,6 @@ public class List return quality; } - public void setParent(ParentList p) - { - parent = p; - } - - public ParentList getParent() - { - return parent; - } - public ArrayList getSegments() { return segments; diff --git a/src/com/upc/pbe/upcnews/ParentList.java b/src/com/upc/pbe/upcnews/ParentList.java index 4a9eae4..afc5b72 100644 --- a/src/com/upc/pbe/upcnews/ParentList.java +++ b/src/com/upc/pbe/upcnews/ParentList.java @@ -25,6 +25,11 @@ public class ParentList return ID; } + public void setID(String id) + { + ID = id; + } + public int getCurrentQuality() { return currentQuality; diff --git a/src/com/upc/pbe/upcnews/Parser.java b/src/com/upc/pbe/upcnews/Parser.java index 2ebb404..374e25f 100644 --- a/src/com/upc/pbe/upcnews/Parser.java +++ b/src/com/upc/pbe/upcnews/Parser.java @@ -5,216 +5,272 @@ import java.util.ArrayList; import android.util.Log; -public class Parser { +public class Parser +{ private static final String STARTWORD = "#EXTM3U"; private static String TAG = "Parser"; - private int fileType; // indicates if segment list or media list + private int fileType; //indicates if segment list or media list private int currentLine; - private int currentSegment; // Cada segmento de cada calidad distinta - private int currentList; // Indice de cada recurso distinto + private int currentSegment; //Cada segmento de cada calidad distinta + private int currentList; //Indice de cada recurso distinto private boolean expectSegment = false; private boolean expectList = false; private Descarrega download; - - public Parser() { + + public Parser() + { currentLine = 0; currentSegment = 0; currentList = 0; fileType = -1; /* - * -1 indicates UNDETERMINED 0 indicates SEGMENTS 1 indicates MEDIA + * -1 indicates UNDETERMINED + * 0 indicates SEGMENTS + * 1 indicates MEDIA */ download = new Descarrega(); } - - public ArrayList parseFile(String file) throws ErrorException, - WarningException, InfoException { + + public ArrayList 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++) // la primera linea = null + Log.d(TAG, "" + lines.length); + for(int i = 0; i < lines.length; i++) //la primera linea = null { - if (lines[i].endsWith("\\")) { - lines[i] = lines[i].substring(0, lines[i].indexOf("\\")) - + lines[++i]; + if(lines[i].endsWith("\\")) + { + lines[i] = lines[i].substring(0, lines[i].indexOf("\\")) + lines[++i]; } - try { - + try + { + Log.d(TAG, lines[i]); - parseLine(lines[i], lists); - } catch (InfoException iE) { - // Toast.makeText(this, iE.getMessage(), - // Toast.LENGTH_SHORT).show(); - } catch (WarningException wE) { - + parseLine(lines[i],lists); + } + catch(InfoException iE) + { + //Toast.makeText(this, iE.getMessage(), Toast.LENGTH_SHORT).show(); + } + catch(WarningException wE) + { + } } - /* - * 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++) { - if (lists.get(i).getID().equals(ID)) { + + private int searchID(String ID, ArrayList lists) + { + for(int i = 0; i < lists.size(); i++) + { + if(lists.get(i).getID().equals(ID)) + { return i; } } return -1; } - - private void sortQuality(ParentList ppls) { + + private void sortQuality(ParentList ppls) + { ArrayList lists = ppls.getLists(); - if (lists.get(0).getQuality() == -1) { + if(lists.get(0).getQuality() == -1) + { /* * Se trata de ext-x-media's y estos no van por calidad */ return; } - // BUBBLE-SORT!! (Me da un poco de verguenza, pero no quiero ponerme con - // quicksort... - while (true) { + //BUBBLE-SORT!! (Me da un poco de verguenza, pero no quiero ponerme con quicksort... + while(true) + { boolean sorted = true; int i = 0; - do { - if (lists.get(i).getQuality() < lists.get(i + 1).getQuality()) { + do + { + 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()); - if (sorted) { + + }while(++i != lists.size()); + if(sorted) + { break; } } } - - public void parseLine(String line, ArrayList lists) - throws ErrorException, WarningException, InfoException { - if (line.isEmpty()) { + + public void parseLine(String line, ArrayList lists) throws ErrorException, WarningException, InfoException + { + if(line.isEmpty()) + { currentLine++; return; - } else { - ParentList ppls = lists.get(currentList); // VIVA HONDURAS!!! + } + else + { + ParentList ppls = lists.get(currentList); //VIVA HONDURAS!!! List pls = ppls.getLists().get(ppls.getCurrentQuality()); - if (!pls.getValidated()) { - if (line.equals(STARTWORD)) { + if(!pls.getValidated()) + { + if(line.equals(STARTWORD)) + { pls.setValidated(true); - } else { + } + else + { throw new ErrorException("Playlist is not valid"); } - } else { - if (line.charAt(0) == '#') { - if (line.substring(0, 4).equals("#EXT")) { + } + else + { + if(line.charAt(0) == '#') + { + if(line.substring(0,4).equals("#EXT")) + { String[] extTag = line.split(":"); - 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")) { - if (fileType == -1) { + } + else if(extTag[0].equals("#EXTINF")) + { + if(fileType == -1) + { fileType = 0; - } else if (fileType == 1) { - 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"); + else if(fileType == 1) + { + 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()) { - throw new ErrorException("Segment " - + currentSegment + " on line " - + currentLine + " exceeds max duration"); + float duration = Float.parseFloat(args[0]); + if (duration > pls.getMaxDuration()) + { + throw new ErrorException("Segment " + currentSegment + " on line " + currentLine + +" exceeds max duration"); } Segment s = new Segment(duration); - if (args.length == 1) { + if(args.length == 1) + { s.setName(""); - } else { + } + else + { s.setName(args[1]); } pls.getSegments().add(s); expectSegment = true; } - - else if (extTag[0].equals("#EXT-X-STREAM-INF")) { - if (fileType == -1) { + + else if(extTag[0].equals("#EXT-X-STREAM-INF")) + { + if(fileType == -1) + { fileType = 1; - } else if (fileType == 0) { - throw new ErrorException( - "Invalid file, should contain Segments, " - + "but lists were found."); + } + else if(fileType == 0) + { + 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("="); - 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) { - throw new ErrorException("Playlist on line " - + currentLine - + " has missing arguments"); + if(programID.equals("")|| bandwidth == -1) + { + throw new ErrorException("Playlist on line " + currentLine + + " has missing arguments"); } - if (!programID.equals(ppls.getID())) { - if (ppls.getID().equals("")) { + if(!programID.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. + * Este caso se da cuando no se ha creado ninguna lista. + * Hay que sustituir la por defecto por una lista real. */ - lists.add(0, new ParentList(programID)); - } else { + lists.get(0).setID(programID); + } + else + { currentList = searchID(ppls.getID(), lists); - if (currentList == -1) { + if(currentList == -1) + { lists.add(new ParentList(programID)); - currentList = lists.size() + 1; + currentList = lists.size()+1; /* - * ppls y pls se actualizan en la - * siguiente linea procesada + * ppls y pls se actualizan en la siguiente linea procesada */ - } else { + } + else + { ppls = lists.get(currentList); - ppls.getLists() - .add(new List(bandwidth)); + ppls.getLists().add(new List(bandwidth)); } } - } else { + } + else + { ppls.getLists().add(new List(bandwidth)); } - } else if (extTag[0].equals("#EXT-X-MEDIA")) { - if (fileType == -1) { + } + else if(extTag[0].equals("#EXT-X-MEDIA")) + { + if(fileType == -1) + { fileType = 1; - } else if (fileType == 0) { - throw new ErrorException( - "Invalid file, should contain Segments, " - + "but lists were found."); + } + else if(fileType == 0) + { + throw new ErrorException("Invalid file, should contain Segments, " + + "but lists were found."); } String Type = ""; String Name = ""; @@ -222,33 +278,46 @@ 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("="); - if (argument[0].equals("NAME")) { + if(argument[0].equals("NAME")) + { Name = argument[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]; - } else if (argument[0].equals("DEFAULT")) { - if (argument[1].equals("YES")) { + } + else if(argument[0].equals("DEFAULT")) + { + 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); } - } else if (argument[0].equals("URI")) { + else + { + throw new ErrorException("Invalid value for argument DEFAULT on line " + + currentLine); + } + } + else if(argument[0].equals("URI")) + { URI = argument[1]; } } - if (Type.equals("") || Name.equals("") - || URI.equals("") || GroupID.equals("")) { - throw new ErrorException("Playlist on line " - + currentLine - + " has missing arguments"); + if(Type.equals("") || Name.equals("") || URI.equals("") || GroupID.equals("")) + { + throw new ErrorException("Playlist on line " + currentLine + + " has missing arguments"); } ParentList pl = new ParentList(GroupID); pl.setDefault(Default); @@ -257,74 +326,92 @@ public class Parser { Parser p = new Parser(); p.parseFile(download.doInBackground(URI)); /* - * Procesar URI y descargar listas recursivamente y - * añadir a la lista actual. + * 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); - if (!GroupID.equals(ppls.getID())) { - if (ppls.getID().equals("")) { + 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. + * Este caso se da cuando no se ha creado ninguna lista. + * Hay que sustituir la por defecto por una lista real. */ - lists.add(0, pl); - } else { + lists.add(0,pl); + } + else + { currentList = searchID(ppls.getID(), lists); - if (currentList == -1) { + if(currentList == -1) + { lists.add(pl); - currentList = lists.size() + 1; - } else { + currentList = lists.size()+1; + } + else + { ppls = lists.get(currentList); ppls.getLists().add(l); } } - } else { + } + else + { ppls.getLists().add(l); } } - - else if (extTag[0].equals("#EXT-X-ENDLIST")) { - if (expectSegment || expectList) { - throw new ErrorException( - "Unexpected end of list!"); + + else if(extTag[0].equals("#EXT-X-ENDLIST")) + { + if(expectSegment || expectList) + { + throw new ErrorException("Unexpected end of list!"); } - // END REACHED, IGNORE AND LET THE FILE REACH EOF + //END REACHED, IGNORE AND LET THE FILE REACH EOF } - - else { + + else + { currentLine++; - throw new WarningException("Tag not implemented: " - + extTag[0]); + throw new WarningException("Tag not implemented: " + extTag[0]); } - } else { + } + 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) { + } + else + { + if(expectSegment) + { expectSegment = false; - try { + try + { pls.getSegments().get(currentSegment).setURL(line); - } catch (MalformedURLException e) { + } + catch (MalformedURLException e) + { throw new ErrorException(e.getMessage()); } currentSegment++; - } else if (expectList) { + } + else if(expectList) + { expectList = false; Parser p = new Parser(); p.parseFile(download.doInBackground(line)); - } else { - throw new ErrorException("ERROR: Unexpected string " - + line); + } + else + { + throw new ErrorException("ERROR: Unexpected string " + line); } } } currentLine++; - } + } } } \ No newline at end of file diff --git a/src/com/upc/pbe/upcnews/Segment.java b/src/com/upc/pbe/upcnews/Segment.java index 319bafc..6b944a9 100644 --- a/src/com/upc/pbe/upcnews/Segment.java +++ b/src/com/upc/pbe/upcnews/Segment.java @@ -6,10 +6,10 @@ import java.net.URL; public class Segment { private String name; - private int duration; + private float duration; private URL url; - public Segment(int dur) + public Segment(float dur) { name = ""; duration = dur; @@ -25,7 +25,7 @@ public class Segment return name; } - public int getDuration() + public float getDuration() { return duration; } -- libgit2 0.22.2