Commit 94240569fc6ec0b9b319c8fda7636853182bd11b
1 parent
d3f3ab85
Currele con le parser, aun no está terminado, sigo en ello. Faltan dos polladas.…
… Necesito la funcion de descargar fichero de Marc,
Showing
3 changed files
with
199 additions
and
108 deletions
gen/com/upc/pbe/upcnews/R.java
1 | -/* AUTO-GENERATED FILE. DO NOT MODIFY. | ||
2 | - * | ||
3 | - * This class was automatically generated by the | ||
4 | - * aapt tool from the resource data it found. It | ||
5 | - * should not be modified by hand. | ||
6 | - */ | ||
7 | - | ||
8 | -package com.upc.pbe.upcnews; | ||
9 | - | ||
10 | -public final class R { | ||
11 | - public static final class attr { | ||
12 | - } | ||
13 | - public static final class drawable { | ||
14 | - public static final int ic_action_search=0x7f020000; | ||
15 | - public static final int ic_launcher=0x7f020001; | ||
16 | - public static final int ic_menu_name=0x7f020002; | ||
17 | - } | ||
18 | - public static final class id { | ||
19 | - public static final int AbsoluteLayout1=0x7f080009; | ||
20 | - public static final int ImageView01=0x7f08000b; | ||
21 | - public static final int ImageView1=0x7f08000a; | ||
22 | - public static final int LinearLayout1=0x7f080000; | ||
23 | - public static final int button=0x7f08000e; | ||
24 | - public static final int button1=0x7f080002; | ||
25 | - public static final int button2=0x7f080003; | ||
26 | - public static final int button3=0x7f080004; | ||
27 | - public static final int button4=0x7f080005; | ||
28 | - public static final int button5=0x7f080006; | ||
29 | - public static final int itemhelp=0x7f080011; | ||
30 | - public static final int itemprefs=0x7f080010; | ||
31 | - public static final int menu_settings=0x7f08000f; | ||
32 | - public static final int textView1=0x7f080007; | ||
33 | - public static final int textView2=0x7f080008; | ||
34 | - public static final int textViewRoute=0x7f08000c; | ||
35 | - public static final int textViewTitle=0x7f080001; | ||
36 | - public static final int textViewXml=0x7f08000d; | ||
37 | - } | ||
38 | - public static final class layout { | ||
39 | - public static final int dirs=0x7f030000; | ||
40 | - public static final int help=0x7f030001; | ||
41 | - public static final int main_activity=0x7f030002; | ||
42 | - } | ||
43 | - public static final class menu { | ||
44 | - public static final int activity_main=0x7f070000; | ||
45 | - public static final int menu=0x7f070001; | ||
46 | - } | ||
47 | - public static final class string { | ||
48 | - public static final int app_name=0x7f050000; | ||
49 | - public static final int button=0x7f05000c; | ||
50 | - public static final int button1=0x7f05000d; | ||
51 | - public static final int desc=0x7f050009; | ||
52 | - public static final int descarregar=0x7f050003; | ||
53 | - public static final int dir=0x7f05000a; | ||
54 | - public static final int directoris=0x7f05000b; | ||
55 | - public static final int help=0x7f050008; | ||
56 | - public static final int hint=0x7f050004; | ||
57 | - public static final int logodescription=0x7f05000f; | ||
58 | - public static final int menu_settings=0x7f050001; | ||
59 | - public static final int prefs=0x7f050007; | ||
60 | - public static final int title=0x7f05000e; | ||
61 | - public static final int title_activity_main=0x7f050002; | ||
62 | - public static final int url=0x7f050005; | ||
63 | - public static final int urlhint=0x7f050006; | ||
64 | - } | ||
65 | - public static final class style { | ||
66 | - public static final int AppTheme=0x7f060000; | ||
67 | - } | ||
68 | - public static final class xml { | ||
69 | - public static final int prefs=0x7f040000; | ||
70 | - } | ||
71 | -} | 1 | +/* AUTO-GENERATED FILE. DO NOT MODIFY. |
2 | + * | ||
3 | + * This class was automatically generated by the | ||
4 | + * aapt tool from the resource data it found. It | ||
5 | + * should not be modified by hand. | ||
6 | + */ | ||
7 | + | ||
8 | +package com.upc.pbe.upcnews; | ||
9 | + | ||
10 | +public final class R { | ||
11 | + public static final class attr { | ||
12 | + } | ||
13 | + public static final class drawable { | ||
14 | + public static final int ic_action_search=0x7f020000; | ||
15 | + public static final int ic_launcher=0x7f020001; | ||
16 | + public static final int ic_menu_name=0x7f020002; | ||
17 | + } | ||
18 | + public static final class id { | ||
19 | + public static final int AbsoluteLayout1=0x7f080009; | ||
20 | + public static final int ImageView01=0x7f08000b; | ||
21 | + public static final int ImageView1=0x7f08000a; | ||
22 | + public static final int LinearLayout1=0x7f080000; | ||
23 | + public static final int button=0x7f08000e; | ||
24 | + public static final int button1=0x7f080002; | ||
25 | + public static final int button2=0x7f080003; | ||
26 | + public static final int button3=0x7f080004; | ||
27 | + public static final int button4=0x7f080005; | ||
28 | + public static final int button5=0x7f080006; | ||
29 | + public static final int itemhelp=0x7f080011; | ||
30 | + public static final int itemprefs=0x7f080010; | ||
31 | + public static final int menu_settings=0x7f08000f; | ||
32 | + public static final int textView1=0x7f080007; | ||
33 | + public static final int textView2=0x7f080008; | ||
34 | + public static final int textViewRoute=0x7f08000c; | ||
35 | + public static final int textViewTitle=0x7f080001; | ||
36 | + public static final int textViewXml=0x7f08000d; | ||
37 | + } | ||
38 | + public static final class layout { | ||
39 | + public static final int dirs=0x7f030000; | ||
40 | + public static final int help=0x7f030001; | ||
41 | + public static final int main_activity=0x7f030002; | ||
42 | + } | ||
43 | + public static final class menu { | ||
44 | + public static final int activity_main=0x7f070000; | ||
45 | + public static final int menu=0x7f070001; | ||
46 | + } | ||
47 | + public static final class string { | ||
48 | + public static final int app_name=0x7f050000; | ||
49 | + public static final int button=0x7f05000c; | ||
50 | + public static final int button1=0x7f05000d; | ||
51 | + public static final int desc=0x7f050009; | ||
52 | + public static final int descarregar=0x7f050003; | ||
53 | + public static final int dir=0x7f05000a; | ||
54 | + public static final int directoris=0x7f05000b; | ||
55 | + public static final int help=0x7f050008; | ||
56 | + public static final int hint=0x7f050004; | ||
57 | + public static final int logodescription=0x7f05000f; | ||
58 | + public static final int menu_settings=0x7f050001; | ||
59 | + public static final int prefs=0x7f050007; | ||
60 | + public static final int title=0x7f05000e; | ||
61 | + public static final int title_activity_main=0x7f050002; | ||
62 | + public static final int url=0x7f050005; | ||
63 | + public static final int urlhint=0x7f050006; | ||
64 | + } | ||
65 | + public static final class style { | ||
66 | + public static final int AppTheme=0x7f060000; | ||
67 | + } | ||
68 | + public static final class xml { | ||
69 | + public static final int prefs=0x7f040000; | ||
70 | + } | ||
71 | +} |
src/com/upc/pbe/upcnews/ParentList.java
@@ -4,18 +4,29 @@ import java.util.ArrayList; | @@ -4,18 +4,29 @@ import java.util.ArrayList; | ||
4 | 4 | ||
5 | public class ParentList | 5 | public class ParentList |
6 | { | 6 | { |
7 | - int currentID; | ||
8 | - ArrayList<List> lists; //per cada qualitat | 7 | + private String ID; |
8 | + private int currentQuality; | ||
9 | + private ArrayList<List> lists; //per cada qualitat | ||
9 | 10 | ||
10 | - public ParentList() | 11 | + public ParentList(String ID) |
11 | { | 12 | { |
12 | - currentID = 0; | 13 | + this.ID = ID; |
14 | + currentQuality = 0; | ||
13 | lists = new ArrayList<List>(); | 15 | lists = new ArrayList<List>(); |
14 | } | 16 | } |
15 | 17 | ||
16 | - public int getCurrent() | 18 | + public String getID() |
17 | { | 19 | { |
18 | - return currentID; | 20 | + return ID; |
21 | + } | ||
22 | + | ||
23 | + public int getQuality() | ||
24 | + { | ||
25 | + return currentQuality; | ||
26 | + } | ||
27 | + public void setQuality(int q) | ||
28 | + { | ||
29 | + currentQuality = q; | ||
19 | } | 30 | } |
20 | 31 | ||
21 | public ArrayList<List> getLists() | 32 | public ArrayList<List> getLists() |
src/com/upc/pbe/upcnews/Parser.java
@@ -5,36 +5,63 @@ import java.util.ArrayList; | @@ -5,36 +5,63 @@ import java.util.ArrayList; | ||
5 | public class Parser | 5 | public class Parser |
6 | { | 6 | { |
7 | private static final String STARTWORD = "#EXTM3U"; | 7 | private static final String STARTWORD = "#EXTM3U"; |
8 | - | 8 | + private int fileType; //indicates if segment list or media list |
9 | private int currentLine; | 9 | private int currentLine; |
10 | - private int currentSegment; | ||
11 | - private int currentList; | 10 | + private int currentSegment; //Cada segmento de cada calidad distinta |
11 | + private int currentList; //Indice de cada recurso distinto | ||
12 | + private boolean expectSegment = false; | ||
13 | + private boolean expectList = false; | ||
12 | 14 | ||
13 | public Parser() | 15 | public Parser() |
14 | { | 16 | { |
15 | currentLine = 0; | 17 | currentLine = 0; |
16 | currentSegment = 0; | 18 | currentSegment = 0; |
17 | - currentList = 0; | 19 | + currentList = 0; |
20 | + fileType = -1; | ||
21 | + /* | ||
22 | + * -1 indicates UNDETERMINED | ||
23 | + * 0 indicates SEGMENTS | ||
24 | + * 1 indicates MEDIA | ||
25 | + */ | ||
18 | } | 26 | } |
19 | 27 | ||
20 | public ArrayList<ParentList> parseFile(String file) throws ErrorException, WarningException, InfoException | 28 | public ArrayList<ParentList> parseFile(String file) throws ErrorException, WarningException, InfoException |
21 | { | 29 | { |
22 | ArrayList<ParentList> lists = new ArrayList<ParentList>(); | 30 | ArrayList<ParentList> lists = new ArrayList<ParentList>(); |
23 | - lists.add(new ParentList()); | 31 | + lists.add(new ParentList("")); |
24 | lists.get(0).getLists().add(new List()); | 32 | lists.get(0).getLists().add(new List()); |
25 | String[] lines = file.split("\n"); | 33 | String[] lines = file.split("\n"); |
26 | for(int i = 0; i < lines.length; i++) | 34 | for(int i = 0; i < lines.length; i++) |
27 | { | 35 | { |
28 | parseLine(lines[i],lists); | 36 | parseLine(lines[i],lists); |
29 | } | 37 | } |
30 | - return lists; | 38 | + /* Esto contiene una lista de RECURSOS, |
39 | + * que a su vez contiene una lista de CALIDADES. | ||
40 | + * Si no te gusta mis VERSOS, | ||
41 | + * te mando a la mierda sin SUTILIDADES. | ||
42 | + * | ||
43 | + * -- Imanol, hasta las cejas de cafeína. | ||
44 | + * | ||
45 | + * PD: En el último nivel de profundidad hay una lista de segmentos (debajo de calidades). | ||
46 | + * Allí está el auténtico tesoro de Narnia. | ||
47 | + */ | ||
48 | + return lists; | ||
49 | + } | ||
50 | + | ||
51 | + private int searchID(String ID, ArrayList<ParentList> lists) | ||
52 | + { | ||
53 | + for(int i = 0; i < lists.size(); i++) | ||
54 | + { | ||
55 | + if(lists.get(i).getID().equals(ID)) | ||
56 | + { | ||
57 | + return i; | ||
58 | + } | ||
59 | + } | ||
60 | + return -1; | ||
31 | } | 61 | } |
32 | 62 | ||
33 | public void parseLine(String line, ArrayList<ParentList> lists) throws ErrorException, WarningException, InfoException | 63 | public void parseLine(String line, ArrayList<ParentList> lists) throws ErrorException, WarningException, InfoException |
34 | { | 64 | { |
35 | - boolean expectSegment = false; | ||
36 | - boolean expectList = false; | ||
37 | - | ||
38 | if(line.isEmpty()) | 65 | if(line.isEmpty()) |
39 | { | 66 | { |
40 | currentLine++; | 67 | currentLine++; |
@@ -42,7 +69,8 @@ public class Parser | @@ -42,7 +69,8 @@ public class Parser | ||
42 | } | 69 | } |
43 | else | 70 | else |
44 | { | 71 | { |
45 | - List pls = lists.get(currentList).getLists().get(lists.get(currentList).currentID); | 72 | + ParentList ppls = lists.get(currentList); //VIVA HONDURAS!!! |
73 | + List pls = ppls.getLists().get(ppls.getQuality()); | ||
46 | if(!pls.getValidated()) | 74 | if(!pls.getValidated()) |
47 | { | 75 | { |
48 | if(line.equals(STARTWORD)) | 76 | if(line.equals(STARTWORD)) |
@@ -72,6 +100,15 @@ public class Parser | @@ -72,6 +100,15 @@ public class Parser | ||
72 | 100 | ||
73 | else if(extTag[0].equals("#EXTINF")) | 101 | else if(extTag[0].equals("#EXTINF")) |
74 | { | 102 | { |
103 | + if(fileType == -1) | ||
104 | + { | ||
105 | + fileType = 0; | ||
106 | + } | ||
107 | + else if(fileType == 1) | ||
108 | + { | ||
109 | + throw new ErrorException("Invalid file, should contain Lists, " + | ||
110 | + "but segments were found."); | ||
111 | + } | ||
75 | String[] args = extTag[1].split(","); | 112 | String[] args = extTag[1].split(","); |
76 | int duration = Integer.parseInt(args[0]); | 113 | int duration = Integer.parseInt(args[0]); |
77 | if (duration > pls.getMaxDuration()) | 114 | if (duration > pls.getMaxDuration()) |
@@ -82,32 +119,67 @@ public class Parser | @@ -82,32 +119,67 @@ public class Parser | ||
82 | Segment s = new Segment(duration); | 119 | Segment s = new Segment(duration); |
83 | s.setName(args[1]); | 120 | s.setName(args[1]); |
84 | pls.getSegments().add(s); | 121 | pls.getSegments().add(s); |
85 | - currentSegment++; | ||
86 | expectSegment = true; | 122 | expectSegment = true; |
87 | } | 123 | } |
88 | 124 | ||
89 | else if(extTag[0].equals("#EXT-X-STREAM-INF")) | 125 | else if(extTag[0].equals("#EXT-X-STREAM-INF")) |
90 | { | 126 | { |
127 | + if(fileType == -1) | ||
128 | + { | ||
129 | + fileType = 1; | ||
130 | + } | ||
131 | + else if(fileType == 0) | ||
132 | + { | ||
133 | + throw new ErrorException("Invalid file, should contain Segments, " + | ||
134 | + "but lists were found."); | ||
135 | + } | ||
91 | expectList = true; | 136 | expectList = true; |
92 | - /*PROGRAMID="" | ||
93 | - CODECS="" | ||
94 | - RESOLUTION="" | ||
95 | - ARGUMENTS=`echo $line | cut -d':' -f 2` | ||
96 | - i=1 | ||
97 | - while [[ `echo $ARGUMENTS | cut -d',' -f $i` != "" ]]; do | ||
98 | - PARAMETER=`echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 2` | ||
99 | - case `echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 1` in | ||
100 | - "PROGRAM-ID") | ||
101 | - PROGRAMID=$PARAMETER;; | ||
102 | - "BANDWIDTH") | ||
103 | - BANDWIDTH=$PARAMETER;; | ||
104 | - "RESOLUTION") | ||
105 | - RESOLUTION=$PARAMETER;; | ||
106 | - "CODECS") | ||
107 | - CODECS=$PARAMETER;; | ||
108 | - esac | ||
109 | - ((i++)) | ||
110 | - done;;*/ | 137 | + String programID = ""; |
138 | + int bandwidth = -1; | ||
139 | + String[] arguments = extTag[1].split(","); | ||
140 | + for(int i = 0; i < arguments.length; i++) | ||
141 | + { | ||
142 | + if(arguments[i].equals("PROGRAM-ID")) | ||
143 | + { | ||
144 | + programID = arguments[i]; | ||
145 | + } | ||
146 | + else if(arguments[i].equals("BANDWIDTH")) | ||
147 | + { | ||
148 | + bandwidth = Integer.parseInt(arguments[i]); | ||
149 | + } | ||
150 | + } | ||
151 | + if(programID.equals("")|| bandwidth == -1) | ||
152 | + { | ||
153 | + throw new ErrorException("Playlist on line " + currentLine + | ||
154 | + " has missing arguments"); | ||
155 | + } | ||
156 | + if(!programID.equals(ppls.getID())) | ||
157 | + { | ||
158 | + if(ppls.getID().equals("")) | ||
159 | + { | ||
160 | + /* | ||
161 | + * Este caso se da cuando no se ha creado ninguna lista. | ||
162 | + * Hay que sustituir la por defecto por una lista real. | ||
163 | + */ | ||
164 | + lists.add(0,new ParentList(programID)); | ||
165 | + } | ||
166 | + else | ||
167 | + { | ||
168 | + currentList = searchID(ppls.getID(), lists); | ||
169 | + if(currentList == -1) | ||
170 | + { | ||
171 | + lists.add(new ParentList(programID)); | ||
172 | + currentList = lists.size()+1; | ||
173 | + /* | ||
174 | + * ppls y pls se actualizan en la siguiente linea procesada | ||
175 | + */ | ||
176 | + } | ||
177 | + } | ||
178 | + } | ||
179 | + } | ||
180 | + else if(extTag[0].equals("#EXT-X-MEDIA")) | ||
181 | + { | ||
182 | + //TO-DO | ||
111 | } | 183 | } |
112 | 184 | ||
113 | else if(extTag[0].equals("#EXT-X-ENDLIST")) | 185 | else if(extTag[0].equals("#EXT-X-ENDLIST")) |
@@ -118,7 +190,7 @@ public class Parser | @@ -118,7 +190,7 @@ public class Parser | ||
118 | else | 190 | else |
119 | { | 191 | { |
120 | currentLine++; | 192 | currentLine++; |
121 | - throw new WarningException("Tag not implemented"); | 193 | + throw new WarningException("Tag not implemented: " + extTag[0]); |
122 | } | 194 | } |
123 | } | 195 | } |
124 | else | 196 | else |
@@ -129,6 +201,14 @@ public class Parser | @@ -129,6 +201,14 @@ public class Parser | ||
129 | } | 201 | } |
130 | else | 202 | else |
131 | { | 203 | { |
204 | + if(expectSegment) | ||
205 | + { | ||
206 | + | ||
207 | + } | ||
208 | + else if(expectList) | ||
209 | + { | ||
210 | + | ||
211 | + } | ||
132 | 212 | ||
133 | /*if [[ $EXTINF -eq 1 ]]; then | 213 | /*if [[ $EXTINF -eq 1 ]]; then |
134 | echo -n "SEGMENT $CURRENT_SEGMENT: \"$NAME\" - $DURATION seconds ($line)" | 214 | echo -n "SEGMENT $CURRENT_SEGMENT: \"$NAME\" - $DURATION seconds ($line)" |