From 94240569fc6ec0b9b319c8fda7636853182bd11b Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Tue, 4 Dec 2012 05:59:04 +0000 Subject: [PATCH] Currele con le parser, aun no está terminado, sigo en ello. Faltan dos polladas. Necesito la funcion de descargar fichero de Marc, --- gen/com/upc/pbe/upcnews/R.java | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------- src/com/upc/pbe/upcnews/ParentList.java | 23 +++++++++++++++++------ src/com/upc/pbe/upcnews/Parser.java | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------- 3 files changed, 199 insertions(+), 108 deletions(-) diff --git a/gen/com/upc/pbe/upcnews/R.java b/gen/com/upc/pbe/upcnews/R.java index ba09742..849a54a 100644 --- a/gen/com/upc/pbe/upcnews/R.java +++ b/gen/com/upc/pbe/upcnews/R.java @@ -1,71 +1,71 @@ -/* 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=0x7f080009; - public static final int ImageView01=0x7f08000b; - public static final int ImageView1=0x7f08000a; - public static final int LinearLayout1=0x7f080000; - public static final int button=0x7f08000e; - public static final int button1=0x7f080002; - public static final int button2=0x7f080003; - public static final int button3=0x7f080004; - public static final int button4=0x7f080005; - public static final int button5=0x7f080006; - public static final int itemhelp=0x7f080011; - public static final int itemprefs=0x7f080010; - public static final int menu_settings=0x7f08000f; - public static final int textView1=0x7f080007; - public static final int textView2=0x7f080008; - public static final int textViewRoute=0x7f08000c; - public static final int textViewTitle=0x7f080001; - public static final int textViewXml=0x7f08000d; - } - public static final class layout { - public static final int dirs=0x7f030000; - public static final int help=0x7f030001; - public static final int main_activity=0x7f030002; - } - public static final class menu { - public static final int activity_main=0x7f070000; - public static final int menu=0x7f070001; - } - 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 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 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=0x7f080009; + public static final int ImageView01=0x7f08000b; + public static final int ImageView1=0x7f08000a; + public static final int LinearLayout1=0x7f080000; + public static final int button=0x7f08000e; + public static final int button1=0x7f080002; + public static final int button2=0x7f080003; + public static final int button3=0x7f080004; + public static final int button4=0x7f080005; + public static final int button5=0x7f080006; + public static final int itemhelp=0x7f080011; + public static final int itemprefs=0x7f080010; + public static final int menu_settings=0x7f08000f; + public static final int textView1=0x7f080007; + public static final int textView2=0x7f080008; + public static final int textViewRoute=0x7f08000c; + public static final int textViewTitle=0x7f080001; + public static final int textViewXml=0x7f08000d; + } + public static final class layout { + public static final int dirs=0x7f030000; + public static final int help=0x7f030001; + public static final int main_activity=0x7f030002; + } + public static final class menu { + public static final int activity_main=0x7f070000; + public static final int menu=0x7f070001; + } + 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 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 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/ParentList.java b/src/com/upc/pbe/upcnews/ParentList.java index 195843b..815115d 100644 --- a/src/com/upc/pbe/upcnews/ParentList.java +++ b/src/com/upc/pbe/upcnews/ParentList.java @@ -4,18 +4,29 @@ import java.util.ArrayList; public class ParentList { - int currentID; - ArrayList lists; //per cada qualitat + private String ID; + private int currentQuality; + private ArrayList lists; //per cada qualitat - public ParentList() + public ParentList(String ID) { - currentID = 0; + this.ID = ID; + currentQuality = 0; lists = new ArrayList(); } - public int getCurrent() + public String getID() { - return currentID; + return ID; + } + + public int getQuality() + { + return currentQuality; + } + public void setQuality(int q) + { + currentQuality = q; } public ArrayList getLists() diff --git a/src/com/upc/pbe/upcnews/Parser.java b/src/com/upc/pbe/upcnews/Parser.java index ed771c9..9c65b87 100644 --- a/src/com/upc/pbe/upcnews/Parser.java +++ b/src/com/upc/pbe/upcnews/Parser.java @@ -5,36 +5,63 @@ import java.util.ArrayList; public class Parser { private static final String STARTWORD = "#EXTM3U"; - + private int fileType; //indicates if segment list or media list private int currentLine; - private int currentSegment; - private int currentList; + 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; public Parser() { currentLine = 0; currentSegment = 0; - currentList = 0; + currentList = 0; + fileType = -1; + /* + * -1 indicates UNDETERMINED + * 0 indicates SEGMENTS + * 1 indicates MEDIA + */ } public ArrayList parseFile(String file) throws ErrorException, WarningException, InfoException { ArrayList lists = new ArrayList(); - lists.add(new ParentList()); + lists.add(new ParentList("")); lists.get(0).getLists().add(new List()); String[] lines = file.split("\n"); for(int i = 0; i < lines.length; i++) { parseLine(lines[i],lists); } - return lists; + /* 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. + */ + return lists; + } + + 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; } public void parseLine(String line, ArrayList lists) throws ErrorException, WarningException, InfoException { - boolean expectSegment = false; - boolean expectList = false; - if(line.isEmpty()) { currentLine++; @@ -42,7 +69,8 @@ public class Parser } else { - List pls = lists.get(currentList).getLists().get(lists.get(currentList).currentID); + ParentList ppls = lists.get(currentList); //VIVA HONDURAS!!! + List pls = ppls.getLists().get(ppls.getQuality()); if(!pls.getValidated()) { if(line.equals(STARTWORD)) @@ -72,6 +100,15 @@ public class Parser 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."); + } String[] args = extTag[1].split(","); int duration = Integer.parseInt(args[0]); if (duration > pls.getMaxDuration()) @@ -82,32 +119,67 @@ public class Parser Segment s = new Segment(duration); s.setName(args[1]); pls.getSegments().add(s); - currentSegment++; expectSegment = true; } 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."); + } expectList = true; - /*PROGRAMID="" - CODECS="" - RESOLUTION="" - ARGUMENTS=`echo $line | cut -d':' -f 2` - i=1 - while [[ `echo $ARGUMENTS | cut -d',' -f $i` != "" ]]; do - PARAMETER=`echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 2` - case `echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 1` in - "PROGRAM-ID") - PROGRAMID=$PARAMETER;; - "BANDWIDTH") - BANDWIDTH=$PARAMETER;; - "RESOLUTION") - RESOLUTION=$PARAMETER;; - "CODECS") - CODECS=$PARAMETER;; - esac - ((i++)) - done;;*/ + String programID = ""; + int bandwidth = -1; + String[] arguments = extTag[1].split(","); + for(int i = 0; i < arguments.length; i++) + { + if(arguments[i].equals("PROGRAM-ID")) + { + programID = arguments[i]; + } + else if(arguments[i].equals("BANDWIDTH")) + { + bandwidth = Integer.parseInt(arguments[i]); + } + } + if(programID.equals("")|| bandwidth == -1) + { + throw new ErrorException("Playlist on line " + currentLine + + " has missing arguments"); + } + 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. + */ + lists.add(0,new ParentList(programID)); + } + else + { + currentList = searchID(ppls.getID(), lists); + if(currentList == -1) + { + lists.add(new ParentList(programID)); + currentList = lists.size()+1; + /* + * ppls y pls se actualizan en la siguiente linea procesada + */ + } + } + } + } + else if(extTag[0].equals("#EXT-X-MEDIA")) + { + //TO-DO } else if(extTag[0].equals("#EXT-X-ENDLIST")) @@ -118,7 +190,7 @@ public class Parser else { currentLine++; - throw new WarningException("Tag not implemented"); + throw new WarningException("Tag not implemented: " + extTag[0]); } } else @@ -129,6 +201,14 @@ public class Parser } else { + if(expectSegment) + { + + } + else if(expectList) + { + + } /*if [[ $EXTINF -eq 1 ]]; then echo -n "SEGMENT $CURRENT_SEGMENT: \"$NAME\" - $DURATION seconds ($line)" -- libgit2 0.22.2