Commit c4e4b49c6cb89b9e84967996665dff0ec6704943
1 parent
ec4076d7
--no commit message
Showing
5 changed files
with
338 additions
and
257 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=0x7f08000a; | ||
20 | - public static final int ImageView01=0x7f08000c; | ||
21 | - public static final int ImageView1=0x7f08000b; | ||
22 | - public static final int LinearLayout1=0x7f080001; | ||
23 | - public static final int button=0x7f08000f; | ||
24 | - public static final int button1=0x7f080003; | ||
25 | - public static final int button2=0x7f080004; | ||
26 | - public static final int button3=0x7f080005; | ||
27 | - public static final int button4=0x7f080006; | ||
28 | - public static final int button5=0x7f080007; | ||
29 | - public static final int itemhelp=0x7f080012; | ||
30 | - public static final int itemprefs=0x7f080011; | ||
31 | - public static final int menu_settings=0x7f080010; | ||
32 | - public static final int textView1=0x7f080008; | ||
33 | - public static final int textView2=0x7f080009; | ||
34 | - public static final int textViewRoute=0x7f08000d; | ||
35 | - public static final int textViewTitle=0x7f080002; | ||
36 | - public static final int textViewXml=0x7f08000e; | ||
37 | - public static final int videoView1=0x7f080000; | ||
38 | - } | ||
39 | - public static final class layout { | ||
40 | - public static final int activity_video=0x7f030000; | ||
41 | - public static final int dirs=0x7f030001; | ||
42 | - public static final int help=0x7f030002; | ||
43 | - public static final int main_activity=0x7f030003; | ||
44 | - } | ||
45 | - public static final class menu { | ||
46 | - public static final int activity_main=0x7f070000; | ||
47 | - public static final int activity_video=0x7f070001; | ||
48 | - public static final int menu=0x7f070002; | ||
49 | - } | ||
50 | - public static final class string { | ||
51 | - public static final int app_name=0x7f050000; | ||
52 | - public static final int button=0x7f05000c; | ||
53 | - public static final int button1=0x7f05000d; | ||
54 | - public static final int desc=0x7f050009; | ||
55 | - public static final int descarregar=0x7f050003; | ||
56 | - public static final int dir=0x7f05000a; | ||
57 | - public static final int directoris=0x7f05000b; | ||
58 | - public static final int hello_world=0x7f050010; | ||
59 | - public static final int help=0x7f050008; | ||
60 | - public static final int hint=0x7f050004; | ||
61 | - public static final int logodescription=0x7f05000f; | ||
62 | - public static final int menu_settings=0x7f050001; | ||
63 | - public static final int prefs=0x7f050007; | ||
64 | - public static final int title=0x7f05000e; | ||
65 | - public static final int title_activity_main=0x7f050002; | ||
66 | - public static final int title_activity_video=0x7f050011; | ||
67 | - public static final int url=0x7f050005; | ||
68 | - public static final int urlhint=0x7f050006; | ||
69 | - } | ||
70 | - public static final class style { | ||
71 | - public static final int AppTheme=0x7f060000; | ||
72 | - } | ||
73 | - public static final class xml { | ||
74 | - public static final int prefs=0x7f040000; | ||
75 | - } | ||
76 | -} | 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=0x7f08000a; | ||
20 | + public static final int ImageView01=0x7f08000c; | ||
21 | + public static final int ImageView1=0x7f08000b; | ||
22 | + public static final int LinearLayout1=0x7f080001; | ||
23 | + public static final int button=0x7f08000f; | ||
24 | + public static final int button1=0x7f080003; | ||
25 | + public static final int button2=0x7f080004; | ||
26 | + public static final int button3=0x7f080005; | ||
27 | + public static final int button4=0x7f080006; | ||
28 | + public static final int button5=0x7f080007; | ||
29 | + public static final int itemhelp=0x7f080012; | ||
30 | + public static final int itemprefs=0x7f080011; | ||
31 | + public static final int menu_settings=0x7f080010; | ||
32 | + public static final int textView1=0x7f080008; | ||
33 | + public static final int textView2=0x7f080009; | ||
34 | + public static final int textViewRoute=0x7f08000d; | ||
35 | + public static final int textViewTitle=0x7f080002; | ||
36 | + public static final int textViewXml=0x7f08000e; | ||
37 | + public static final int videoView1=0x7f080000; | ||
38 | + } | ||
39 | + public static final class layout { | ||
40 | + public static final int activity_video=0x7f030000; | ||
41 | + public static final int dirs=0x7f030001; | ||
42 | + public static final int help=0x7f030002; | ||
43 | + public static final int main_activity=0x7f030003; | ||
44 | + } | ||
45 | + public static final class menu { | ||
46 | + public static final int activity_main=0x7f070000; | ||
47 | + public static final int activity_video=0x7f070001; | ||
48 | + public static final int menu=0x7f070002; | ||
49 | + } | ||
50 | + public static final class string { | ||
51 | + public static final int app_name=0x7f050000; | ||
52 | + public static final int button=0x7f05000c; | ||
53 | + public static final int button1=0x7f05000d; | ||
54 | + public static final int desc=0x7f050009; | ||
55 | + public static final int descarregar=0x7f050003; | ||
56 | + public static final int dir=0x7f05000a; | ||
57 | + public static final int directoris=0x7f05000b; | ||
58 | + public static final int hello_world=0x7f050010; | ||
59 | + public static final int help=0x7f050008; | ||
60 | + public static final int hint=0x7f050004; | ||
61 | + public static final int logodescription=0x7f05000f; | ||
62 | + public static final int menu_settings=0x7f050001; | ||
63 | + public static final int prefs=0x7f050007; | ||
64 | + public static final int title=0x7f05000e; | ||
65 | + public static final int title_activity_main=0x7f050002; | ||
66 | + public static final int title_activity_video=0x7f050011; | ||
67 | + public static final int url=0x7f050005; | ||
68 | + public static final int urlhint=0x7f050006; | ||
69 | + } | ||
70 | + public static final class style { | ||
71 | + public static final int AppTheme=0x7f060000; | ||
72 | + } | ||
73 | + public static final class xml { | ||
74 | + public static final int prefs=0x7f040000; | ||
75 | + } | ||
76 | +} |
src/com/upc/pbe/upcnews/List.java
@@ -9,8 +9,7 @@ public class List | @@ -9,8 +9,7 @@ public class List | ||
9 | private int sequenceFirst; | 9 | private int sequenceFirst; |
10 | private int maxDuration; | 10 | private int maxDuration; |
11 | private ArrayList<Segment> segments; //Lista de SEGMENTOS | 11 | private ArrayList<Segment> segments; //Lista de SEGMENTOS |
12 | - private ParentList parent; | ||
13 | - | 12 | + |
14 | public List(int q) | 13 | public List(int q) |
15 | { | 14 | { |
16 | quality = q; | 15 | quality = q; |
@@ -53,16 +52,6 @@ public class List | @@ -53,16 +52,6 @@ public class List | ||
53 | return quality; | 52 | return quality; |
54 | } | 53 | } |
55 | 54 | ||
56 | - public void setParent(ParentList p) | ||
57 | - { | ||
58 | - parent = p; | ||
59 | - } | ||
60 | - | ||
61 | - public ParentList getParent() | ||
62 | - { | ||
63 | - return parent; | ||
64 | - } | ||
65 | - | ||
66 | public ArrayList<Segment> getSegments() | 55 | public ArrayList<Segment> getSegments() |
67 | { | 56 | { |
68 | return segments; | 57 | return segments; |
src/com/upc/pbe/upcnews/ParentList.java
@@ -25,6 +25,11 @@ public class ParentList | @@ -25,6 +25,11 @@ public class ParentList | ||
25 | return ID; | 25 | return ID; |
26 | } | 26 | } |
27 | 27 | ||
28 | + public void setID(String id) | ||
29 | + { | ||
30 | + ID = id; | ||
31 | + } | ||
32 | + | ||
28 | public int getCurrentQuality() | 33 | public int getCurrentQuality() |
29 | { | 34 | { |
30 | return currentQuality; | 35 | return currentQuality; |
src/com/upc/pbe/upcnews/Parser.java
@@ -5,216 +5,272 @@ import java.util.ArrayList; | @@ -5,216 +5,272 @@ import java.util.ArrayList; | ||
5 | 5 | ||
6 | import android.util.Log; | 6 | import android.util.Log; |
7 | 7 | ||
8 | -public class Parser { | 8 | +public class Parser |
9 | +{ | ||
9 | private static final String STARTWORD = "#EXTM3U"; | 10 | private static final String STARTWORD = "#EXTM3U"; |
10 | private static String TAG = "Parser"; | 11 | private static String TAG = "Parser"; |
11 | - private int fileType; // indicates if segment list or media list | 12 | + private int fileType; //indicates if segment list or media list |
12 | private int currentLine; | 13 | private int currentLine; |
13 | - private int currentSegment; // Cada segmento de cada calidad distinta | ||
14 | - private int currentList; // Indice de cada recurso distinto | 14 | + private int currentSegment; //Cada segmento de cada calidad distinta |
15 | + private int currentList; //Indice de cada recurso distinto | ||
15 | private boolean expectSegment = false; | 16 | private boolean expectSegment = false; |
16 | private boolean expectList = false; | 17 | private boolean expectList = false; |
17 | private Descarrega download; | 18 | private Descarrega download; |
18 | - | ||
19 | - public Parser() { | 19 | + |
20 | + public Parser() | ||
21 | + { | ||
20 | currentLine = 0; | 22 | currentLine = 0; |
21 | currentSegment = 0; | 23 | currentSegment = 0; |
22 | currentList = 0; | 24 | currentList = 0; |
23 | fileType = -1; | 25 | fileType = -1; |
24 | /* | 26 | /* |
25 | - * -1 indicates UNDETERMINED 0 indicates SEGMENTS 1 indicates MEDIA | 27 | + * -1 indicates UNDETERMINED |
28 | + * 0 indicates SEGMENTS | ||
29 | + * 1 indicates MEDIA | ||
26 | */ | 30 | */ |
27 | download = new Descarrega(); | 31 | download = new Descarrega(); |
28 | } | 32 | } |
29 | - | ||
30 | - public ArrayList<ParentList> parseFile(String file) throws ErrorException, | ||
31 | - WarningException, InfoException { | 33 | + |
34 | + public ArrayList<ParentList> parseFile(String file) throws ErrorException, WarningException, InfoException | ||
35 | + { | ||
32 | ArrayList<ParentList> lists = new ArrayList<ParentList>(); | 36 | ArrayList<ParentList> lists = new ArrayList<ParentList>(); |
33 | lists.add(new ParentList("")); | 37 | lists.add(new ParentList("")); |
34 | lists.get(0).getLists().add(new List(-1)); | 38 | lists.get(0).getLists().add(new List(-1)); |
35 | String[] lines = file.split("\n"); | 39 | String[] lines = file.split("\n"); |
36 | - | ||
37 | - for (int i = 0; i < lines.length; i++) // la primera linea = null | 40 | + Log.d(TAG, "" + lines.length); |
41 | + for(int i = 0; i < lines.length; i++) //la primera linea = null | ||
38 | { | 42 | { |
39 | - if (lines[i].endsWith("\\")) { | ||
40 | - lines[i] = lines[i].substring(0, lines[i].indexOf("\\")) | ||
41 | - + lines[++i]; | 43 | + if(lines[i].endsWith("\\")) |
44 | + { | ||
45 | + lines[i] = lines[i].substring(0, lines[i].indexOf("\\")) + lines[++i]; | ||
42 | } | 46 | } |
43 | - try { | ||
44 | - | 47 | + try |
48 | + { | ||
49 | + | ||
45 | Log.d(TAG, lines[i]); | 50 | Log.d(TAG, lines[i]); |
46 | - parseLine(lines[i], lists); | ||
47 | - } catch (InfoException iE) { | ||
48 | - // Toast.makeText(this, iE.getMessage(), | ||
49 | - // Toast.LENGTH_SHORT).show(); | ||
50 | - } catch (WarningException wE) { | ||
51 | - | 51 | + parseLine(lines[i],lists); |
52 | + } | ||
53 | + catch(InfoException iE) | ||
54 | + { | ||
55 | + //Toast.makeText(this, iE.getMessage(), Toast.LENGTH_SHORT).show(); | ||
56 | + } | ||
57 | + catch(WarningException wE) | ||
58 | + { | ||
59 | + | ||
52 | } | 60 | } |
53 | } | 61 | } |
54 | - /* | ||
55 | - * Esto contiene una lista de RECURSOS, que a su vez contiene una lista | ||
56 | - * de CALIDADES. Si no te gusta mis VERSOS, te mando a la mierda sin | ||
57 | - * SUTILIDADES. | 62 | + /* |
63 | + * Esto contiene una lista de RECURSOS, | ||
64 | + * que a su vez contiene una lista de CALIDADES. | ||
65 | + * Si no te gusta mis VERSOS, | ||
66 | + * te mando a la mierda sin SUTILIDADES. | ||
58 | * | 67 | * |
59 | * -- Imanol, hasta las cejas de cafeรญna. | 68 | * -- Imanol, hasta las cejas de cafeรญna. |
60 | * | 69 | * |
61 | - * PD: En el รบltimo nivel de profundidad hay una lista de segmentos | ||
62 | - * (debajo de calidades). Allรญ estรก el autรฉntico tesoro de Narnia. | 70 | + * PD: En el รบltimo nivel de profundidad hay una lista de segmentos (debajo de calidades). |
71 | + * Allรญ estรก el autรฉntico tesoro de Narnia. | ||
63 | */ | 72 | */ |
64 | - for (int i = 0; i < lists.size(); i++) { | 73 | + for(int i = 0; i < lists.size(); i++) |
74 | + { | ||
65 | sortQuality(lists.get(i)); | 75 | sortQuality(lists.get(i)); |
66 | } | 76 | } |
67 | - return lists; | 77 | + return lists; |
68 | } | 78 | } |
69 | - | ||
70 | - private int searchID(String ID, ArrayList<ParentList> lists) { | ||
71 | - for (int i = 0; i < lists.size(); i++) { | ||
72 | - if (lists.get(i).getID().equals(ID)) { | 79 | + |
80 | + private int searchID(String ID, ArrayList<ParentList> lists) | ||
81 | + { | ||
82 | + for(int i = 0; i < lists.size(); i++) | ||
83 | + { | ||
84 | + if(lists.get(i).getID().equals(ID)) | ||
85 | + { | ||
73 | return i; | 86 | return i; |
74 | } | 87 | } |
75 | } | 88 | } |
76 | return -1; | 89 | return -1; |
77 | } | 90 | } |
78 | - | ||
79 | - private void sortQuality(ParentList ppls) { | 91 | + |
92 | + private void sortQuality(ParentList ppls) | ||
93 | + { | ||
80 | ArrayList<List> lists = ppls.getLists(); | 94 | ArrayList<List> lists = ppls.getLists(); |
81 | - if (lists.get(0).getQuality() == -1) { | 95 | + if(lists.get(0).getQuality() == -1) |
96 | + { | ||
82 | /* | 97 | /* |
83 | * Se trata de ext-x-media's y estos no van por calidad | 98 | * Se trata de ext-x-media's y estos no van por calidad |
84 | */ | 99 | */ |
85 | return; | 100 | return; |
86 | } | 101 | } |
87 | - // BUBBLE-SORT!! (Me da un poco de verguenza, pero no quiero ponerme con | ||
88 | - // quicksort... | ||
89 | - while (true) { | 102 | + //BUBBLE-SORT!! (Me da un poco de verguenza, pero no quiero ponerme con quicksort... |
103 | + while(true) | ||
104 | + { | ||
90 | boolean sorted = true; | 105 | boolean sorted = true; |
91 | int i = 0; | 106 | int i = 0; |
92 | - do { | ||
93 | - if (lists.get(i).getQuality() < lists.get(i + 1).getQuality()) { | 107 | + do |
108 | + { | ||
109 | + if(lists.get(i).getQuality() < lists.get(i+1).getQuality()) | ||
110 | + { | ||
94 | sorted = false; | 111 | sorted = false; |
95 | List aux = lists.get(i); | 112 | List aux = lists.get(i); |
96 | - lists.set(i, lists.get(i + 1)); | ||
97 | - lists.set(i + 1, aux); | 113 | + lists.set(i, lists.get(i+1)); |
114 | + lists.set(i+1, aux); | ||
98 | } | 115 | } |
99 | - | ||
100 | - } while (++i != lists.size()); | ||
101 | - if (sorted) { | 116 | + |
117 | + }while(++i != lists.size()); | ||
118 | + if(sorted) | ||
119 | + { | ||
102 | break; | 120 | break; |
103 | } | 121 | } |
104 | } | 122 | } |
105 | 123 | ||
106 | } | 124 | } |
107 | - | ||
108 | - public void parseLine(String line, ArrayList<ParentList> lists) | ||
109 | - throws ErrorException, WarningException, InfoException { | ||
110 | - if (line.isEmpty()) { | 125 | + |
126 | + public void parseLine(String line, ArrayList<ParentList> lists) throws ErrorException, WarningException, InfoException | ||
127 | + { | ||
128 | + if(line.isEmpty()) | ||
129 | + { | ||
111 | currentLine++; | 130 | currentLine++; |
112 | return; | 131 | return; |
113 | - } else { | ||
114 | - ParentList ppls = lists.get(currentList); // VIVA HONDURAS!!! | 132 | + } |
133 | + else | ||
134 | + { | ||
135 | + ParentList ppls = lists.get(currentList); //VIVA HONDURAS!!! | ||
115 | List pls = ppls.getLists().get(ppls.getCurrentQuality()); | 136 | List pls = ppls.getLists().get(ppls.getCurrentQuality()); |
116 | - if (!pls.getValidated()) { | ||
117 | - if (line.equals(STARTWORD)) { | 137 | + if(!pls.getValidated()) |
138 | + { | ||
139 | + if(line.equals(STARTWORD)) | ||
140 | + { | ||
118 | pls.setValidated(true); | 141 | pls.setValidated(true); |
119 | - } else { | 142 | + } |
143 | + else | ||
144 | + { | ||
120 | throw new ErrorException("Playlist is not valid"); | 145 | throw new ErrorException("Playlist is not valid"); |
121 | } | 146 | } |
122 | - } else { | ||
123 | - if (line.charAt(0) == '#') { | ||
124 | - if (line.substring(0, 4).equals("#EXT")) { | 147 | + } |
148 | + else | ||
149 | + { | ||
150 | + if(line.charAt(0) == '#') | ||
151 | + { | ||
152 | + if(line.substring(0,4).equals("#EXT")) | ||
153 | + { | ||
125 | String[] extTag = line.split(":"); | 154 | String[] extTag = line.split(":"); |
126 | - if (extTag[0].equals("#EXT-X-MEDIA-SEQUENCE")) { | 155 | + if(extTag[0].equals("#EXT-X-MEDIA-SEQUENCE")) |
156 | + { | ||
127 | pls.setSequence(Integer.parseInt(extTag[1])); | 157 | pls.setSequence(Integer.parseInt(extTag[1])); |
128 | - } else if (extTag[0].equals("#EXT-X-TARGETDURATION")) { | 158 | + } |
159 | + else if(extTag[0].equals("#EXT-X-TARGETDURATION")) | ||
160 | + { | ||
129 | pls.setMaxDuration(Integer.parseInt(extTag[1])); | 161 | pls.setMaxDuration(Integer.parseInt(extTag[1])); |
130 | - } else if (extTag[0].equals("#EXTINF")) { | ||
131 | - if (fileType == -1) { | 162 | + } |
163 | + else if(extTag[0].equals("#EXTINF")) | ||
164 | + { | ||
165 | + if(fileType == -1) | ||
166 | + { | ||
132 | fileType = 0; | 167 | fileType = 0; |
133 | - } else if (fileType == 1) { | ||
134 | - throw new ErrorException( | ||
135 | - "Invalid file, should contain Lists, " | ||
136 | - + "but segments were found."); | ||
137 | } | 168 | } |
138 | - if (expectSegment) { | ||
139 | - throw new ErrorException( | ||
140 | - "Expected segment URI, got a different" | ||
141 | - + "segment declaration"); | 169 | + else if(fileType == 1) |
170 | + { | ||
171 | + throw new ErrorException("Invalid file, should contain Lists, " + | ||
172 | + "but segments were found."); | ||
173 | + } | ||
174 | + if(expectSegment) | ||
175 | + { | ||
176 | + throw new ErrorException("Expected segment URI, got a different" + | ||
177 | + "segment declaration"); | ||
142 | } | 178 | } |
143 | String[] args = extTag[1].split(","); | 179 | String[] args = extTag[1].split(","); |
144 | - int duration = Integer.parseInt(args[0]); | ||
145 | - if (duration > pls.getMaxDuration()) { | ||
146 | - throw new ErrorException("Segment " | ||
147 | - + currentSegment + " on line " | ||
148 | - + currentLine + " exceeds max duration"); | 180 | + float duration = Float.parseFloat(args[0]); |
181 | + if (duration > pls.getMaxDuration()) | ||
182 | + { | ||
183 | + throw new ErrorException("Segment " + currentSegment + " on line " + currentLine | ||
184 | + +" exceeds max duration"); | ||
149 | } | 185 | } |
150 | Segment s = new Segment(duration); | 186 | Segment s = new Segment(duration); |
151 | - if (args.length == 1) { | 187 | + if(args.length == 1) |
188 | + { | ||
152 | s.setName(""); | 189 | s.setName(""); |
153 | - } else { | 190 | + } |
191 | + else | ||
192 | + { | ||
154 | s.setName(args[1]); | 193 | s.setName(args[1]); |
155 | } | 194 | } |
156 | pls.getSegments().add(s); | 195 | pls.getSegments().add(s); |
157 | expectSegment = true; | 196 | expectSegment = true; |
158 | } | 197 | } |
159 | - | ||
160 | - else if (extTag[0].equals("#EXT-X-STREAM-INF")) { | ||
161 | - if (fileType == -1) { | 198 | + |
199 | + else if(extTag[0].equals("#EXT-X-STREAM-INF")) | ||
200 | + { | ||
201 | + if(fileType == -1) | ||
202 | + { | ||
162 | fileType = 1; | 203 | fileType = 1; |
163 | - } else if (fileType == 0) { | ||
164 | - throw new ErrorException( | ||
165 | - "Invalid file, should contain Segments, " | ||
166 | - + "but lists were found."); | 204 | + } |
205 | + else if(fileType == 0) | ||
206 | + { | ||
207 | + throw new ErrorException("Invalid file, should contain Segments, " + | ||
208 | + "but lists were found."); | ||
167 | } | 209 | } |
168 | expectList = true; | 210 | expectList = true; |
169 | String programID = ""; | 211 | String programID = ""; |
170 | int bandwidth = -1; | 212 | int bandwidth = -1; |
171 | String[] arguments = extTag[1].split(","); | 213 | String[] arguments = extTag[1].split(","); |
172 | - for (int i = 0; i < arguments.length; i++) { | 214 | + for(int i = 0; i < arguments.length; i++) |
215 | + { | ||
173 | String[] argument = arguments[i].split("="); | 216 | String[] argument = arguments[i].split("="); |
174 | - if (argument[0].equals("PROGRAM-ID")) { | 217 | + if(argument[0].equals("PROGRAM-ID")) |
218 | + { | ||
175 | programID = argument[1]; | 219 | programID = argument[1]; |
176 | - } else if (argument[0].equals("BANDWIDTH")) { | 220 | + } |
221 | + else if(argument[0].equals("BANDWIDTH")) | ||
222 | + { | ||
177 | bandwidth = Integer.parseInt(argument[1]); | 223 | bandwidth = Integer.parseInt(argument[1]); |
178 | } | 224 | } |
179 | } | 225 | } |
180 | - if (programID.equals("") || bandwidth == -1) { | ||
181 | - throw new ErrorException("Playlist on line " | ||
182 | - + currentLine | ||
183 | - + " has missing arguments"); | 226 | + if(programID.equals("")|| bandwidth == -1) |
227 | + { | ||
228 | + throw new ErrorException("Playlist on line " + currentLine + | ||
229 | + " has missing arguments"); | ||
184 | } | 230 | } |
185 | - if (!programID.equals(ppls.getID())) { | ||
186 | - if (ppls.getID().equals("")) { | 231 | + if(!programID.equals(ppls.getID())) |
232 | + { | ||
233 | + if(ppls.getID().equals("")) | ||
234 | + { | ||
187 | /* | 235 | /* |
188 | - * Este caso se da cuando no se ha creado | ||
189 | - * ninguna lista. Hay que sustituir la por | ||
190 | - * defecto por una lista real. | 236 | + * Este caso se da cuando no se ha creado ninguna lista. |
237 | + * Hay que sustituir la por defecto por una lista real. | ||
191 | */ | 238 | */ |
192 | - lists.add(0, new ParentList(programID)); | ||
193 | - } else { | 239 | + lists.get(0).setID(programID); |
240 | + } | ||
241 | + else | ||
242 | + { | ||
194 | currentList = searchID(ppls.getID(), lists); | 243 | currentList = searchID(ppls.getID(), lists); |
195 | - if (currentList == -1) { | 244 | + if(currentList == -1) |
245 | + { | ||
196 | lists.add(new ParentList(programID)); | 246 | lists.add(new ParentList(programID)); |
197 | - currentList = lists.size() + 1; | 247 | + currentList = lists.size()+1; |
198 | /* | 248 | /* |
199 | - * ppls y pls se actualizan en la | ||
200 | - * siguiente linea procesada | 249 | + * ppls y pls se actualizan en la siguiente linea procesada |
201 | */ | 250 | */ |
202 | - } else { | 251 | + } |
252 | + else | ||
253 | + { | ||
203 | ppls = lists.get(currentList); | 254 | ppls = lists.get(currentList); |
204 | - ppls.getLists() | ||
205 | - .add(new List(bandwidth)); | 255 | + ppls.getLists().add(new List(bandwidth)); |
206 | } | 256 | } |
207 | } | 257 | } |
208 | - } else { | 258 | + } |
259 | + else | ||
260 | + { | ||
209 | ppls.getLists().add(new List(bandwidth)); | 261 | ppls.getLists().add(new List(bandwidth)); |
210 | } | 262 | } |
211 | - } else if (extTag[0].equals("#EXT-X-MEDIA")) { | ||
212 | - if (fileType == -1) { | 263 | + } |
264 | + else if(extTag[0].equals("#EXT-X-MEDIA")) | ||
265 | + { | ||
266 | + if(fileType == -1) | ||
267 | + { | ||
213 | fileType = 1; | 268 | fileType = 1; |
214 | - } else if (fileType == 0) { | ||
215 | - throw new ErrorException( | ||
216 | - "Invalid file, should contain Segments, " | ||
217 | - + "but lists were found."); | 269 | + } |
270 | + else if(fileType == 0) | ||
271 | + { | ||
272 | + throw new ErrorException("Invalid file, should contain Segments, " + | ||
273 | + "but lists were found."); | ||
218 | } | 274 | } |
219 | String Type = ""; | 275 | String Type = ""; |
220 | String Name = ""; | 276 | String Name = ""; |
@@ -222,33 +278,46 @@ public class Parser { | @@ -222,33 +278,46 @@ public class Parser { | ||
222 | String URI = ""; | 278 | String URI = ""; |
223 | boolean Default = false; | 279 | boolean Default = false; |
224 | String[] arguments = extTag[1].split(","); | 280 | String[] arguments = extTag[1].split(","); |
225 | - for (int i = 0; i < arguments.length; i++) { | 281 | + for(int i = 0; i < arguments.length; i++) |
282 | + { | ||
226 | String[] argument = arguments[i].split("="); | 283 | String[] argument = arguments[i].split("="); |
227 | - if (argument[0].equals("NAME")) { | 284 | + if(argument[0].equals("NAME")) |
285 | + { | ||
228 | Name = argument[1]; | 286 | Name = argument[1]; |
229 | - } else if (argument[0].equals("TYPE")) { | 287 | + } |
288 | + else if(argument[0].equals("TYPE")) | ||
289 | + { | ||
230 | Type = argument[1]; | 290 | Type = argument[1]; |
231 | - } else if (argument[0].equals("GROUP-ID")) { | 291 | + } |
292 | + else if(argument[0].equals("GROUP-ID")) | ||
293 | + { | ||
232 | GroupID = argument[1]; | 294 | GroupID = argument[1]; |
233 | - } else if (argument[0].equals("DEFAULT")) { | ||
234 | - if (argument[1].equals("YES")) { | 295 | + } |
296 | + else if(argument[0].equals("DEFAULT")) | ||
297 | + { | ||
298 | + if(argument[1].equals("YES")) | ||
299 | + { | ||
235 | Default = true; | 300 | Default = true; |
236 | - } else if (argument[1].equals("NO")) { | 301 | + } |
302 | + else if(argument[1].equals("NO")) | ||
303 | + { | ||
237 | Default = true; | 304 | Default = true; |
238 | - } else { | ||
239 | - throw new ErrorException( | ||
240 | - "Invalid value for argument DEFAULT on line " | ||
241 | - + currentLine); | ||
242 | } | 305 | } |
243 | - } else if (argument[0].equals("URI")) { | 306 | + else |
307 | + { | ||
308 | + throw new ErrorException("Invalid value for argument DEFAULT on line " + | ||
309 | + currentLine); | ||
310 | + } | ||
311 | + } | ||
312 | + else if(argument[0].equals("URI")) | ||
313 | + { | ||
244 | URI = argument[1]; | 314 | URI = argument[1]; |
245 | } | 315 | } |
246 | } | 316 | } |
247 | - if (Type.equals("") || Name.equals("") | ||
248 | - || URI.equals("") || GroupID.equals("")) { | ||
249 | - throw new ErrorException("Playlist on line " | ||
250 | - + currentLine | ||
251 | - + " has missing arguments"); | 317 | + if(Type.equals("") || Name.equals("") || URI.equals("") || GroupID.equals("")) |
318 | + { | ||
319 | + throw new ErrorException("Playlist on line " + currentLine + | ||
320 | + " has missing arguments"); | ||
252 | } | 321 | } |
253 | ParentList pl = new ParentList(GroupID); | 322 | ParentList pl = new ParentList(GroupID); |
254 | pl.setDefault(Default); | 323 | pl.setDefault(Default); |
@@ -257,74 +326,92 @@ public class Parser { | @@ -257,74 +326,92 @@ public class Parser { | ||
257 | Parser p = new Parser(); | 326 | Parser p = new Parser(); |
258 | p.parseFile(download.doInBackground(URI)); | 327 | p.parseFile(download.doInBackground(URI)); |
259 | /* | 328 | /* |
260 | - * Procesar URI y descargar listas recursivamente y | ||
261 | - * aรฑadir a la lista actual. | 329 | + * Procesar URI y descargar listas recursivamente y aรฑadir a la lista actual. |
262 | * | 330 | * |
263 | * TO-DO: Necesito la funcion de Marc | 331 | * TO-DO: Necesito la funcion de Marc |
264 | */ | 332 | */ |
265 | List l = new List(-1); | 333 | List l = new List(-1); |
266 | - if (!GroupID.equals(ppls.getID())) { | ||
267 | - if (ppls.getID().equals("")) { | 334 | + if(!GroupID.equals(ppls.getID())) |
335 | + { | ||
336 | + if(ppls.getID().equals("")) | ||
337 | + { | ||
268 | /* | 338 | /* |
269 | - * Este caso se da cuando no se ha creado | ||
270 | - * ninguna lista. Hay que sustituir la por | ||
271 | - * defecto por una lista real. | 339 | + * Este caso se da cuando no se ha creado ninguna lista. |
340 | + * Hay que sustituir la por defecto por una lista real. | ||
272 | */ | 341 | */ |
273 | - lists.add(0, pl); | ||
274 | - } else { | 342 | + lists.add(0,pl); |
343 | + } | ||
344 | + else | ||
345 | + { | ||
275 | 346 | ||
276 | currentList = searchID(ppls.getID(), lists); | 347 | currentList = searchID(ppls.getID(), lists); |
277 | - if (currentList == -1) { | 348 | + if(currentList == -1) |
349 | + { | ||
278 | lists.add(pl); | 350 | lists.add(pl); |
279 | - currentList = lists.size() + 1; | ||
280 | - } else { | 351 | + currentList = lists.size()+1; |
352 | + } | ||
353 | + else | ||
354 | + { | ||
281 | ppls = lists.get(currentList); | 355 | ppls = lists.get(currentList); |
282 | ppls.getLists().add(l); | 356 | ppls.getLists().add(l); |
283 | } | 357 | } |
284 | } | 358 | } |
285 | - } else { | 359 | + } |
360 | + else | ||
361 | + { | ||
286 | ppls.getLists().add(l); | 362 | ppls.getLists().add(l); |
287 | } | 363 | } |
288 | } | 364 | } |
289 | - | ||
290 | - else if (extTag[0].equals("#EXT-X-ENDLIST")) { | ||
291 | - if (expectSegment || expectList) { | ||
292 | - throw new ErrorException( | ||
293 | - "Unexpected end of list!"); | 365 | + |
366 | + else if(extTag[0].equals("#EXT-X-ENDLIST")) | ||
367 | + { | ||
368 | + if(expectSegment || expectList) | ||
369 | + { | ||
370 | + throw new ErrorException("Unexpected end of list!"); | ||
294 | } | 371 | } |
295 | - // END REACHED, IGNORE AND LET THE FILE REACH EOF | 372 | + //END REACHED, IGNORE AND LET THE FILE REACH EOF |
296 | } | 373 | } |
297 | - | ||
298 | - else { | 374 | + |
375 | + else | ||
376 | + { | ||
299 | currentLine++; | 377 | currentLine++; |
300 | - throw new WarningException("Tag not implemented: " | ||
301 | - + extTag[0]); | 378 | + throw new WarningException("Tag not implemented: " + extTag[0]); |
302 | } | 379 | } |
303 | - } else { | 380 | + } |
381 | + else | ||
382 | + { | ||
304 | String comment = line.substring(1); | 383 | String comment = line.substring(1); |
305 | - throw new InfoException("Comment on line " | ||
306 | - + currentLine++ + " " + comment); | 384 | + throw new InfoException("Comment on line " + currentLine++ + " " + comment); |
307 | } | 385 | } |
308 | - } else { | ||
309 | - if (expectSegment) { | 386 | + } |
387 | + else | ||
388 | + { | ||
389 | + if(expectSegment) | ||
390 | + { | ||
310 | expectSegment = false; | 391 | expectSegment = false; |
311 | - try { | 392 | + try |
393 | + { | ||
312 | pls.getSegments().get(currentSegment).setURL(line); | 394 | pls.getSegments().get(currentSegment).setURL(line); |
313 | - } catch (MalformedURLException e) { | 395 | + } |
396 | + catch (MalformedURLException e) | ||
397 | + { | ||
314 | throw new ErrorException(e.getMessage()); | 398 | throw new ErrorException(e.getMessage()); |
315 | } | 399 | } |
316 | currentSegment++; | 400 | currentSegment++; |
317 | - } else if (expectList) { | 401 | + } |
402 | + else if(expectList) | ||
403 | + { | ||
318 | expectList = false; | 404 | expectList = false; |
319 | Parser p = new Parser(); | 405 | Parser p = new Parser(); |
320 | p.parseFile(download.doInBackground(line)); | 406 | p.parseFile(download.doInBackground(line)); |
321 | - } else { | ||
322 | - throw new ErrorException("ERROR: Unexpected string " | ||
323 | - + line); | 407 | + } |
408 | + else | ||
409 | + { | ||
410 | + throw new ErrorException("ERROR: Unexpected string " + line); | ||
324 | } | 411 | } |
325 | } | 412 | } |
326 | } | 413 | } |
327 | currentLine++; | 414 | currentLine++; |
328 | - } | 415 | + } |
329 | } | 416 | } |
330 | } | 417 | } |
331 | \ No newline at end of file | 418 | \ No newline at end of file |
src/com/upc/pbe/upcnews/Segment.java
@@ -6,10 +6,10 @@ import java.net.URL; | @@ -6,10 +6,10 @@ import java.net.URL; | ||
6 | public class Segment | 6 | public class Segment |
7 | { | 7 | { |
8 | private String name; | 8 | private String name; |
9 | - private int duration; | 9 | + private float duration; |
10 | private URL url; | 10 | private URL url; |
11 | 11 | ||
12 | - public Segment(int dur) | 12 | + public Segment(float dur) |
13 | { | 13 | { |
14 | name = ""; | 14 | name = ""; |
15 | duration = dur; | 15 | duration = dur; |
@@ -25,7 +25,7 @@ public class Segment | @@ -25,7 +25,7 @@ public class Segment | ||
25 | return name; | 25 | return name; |
26 | } | 26 | } |
27 | 27 | ||
28 | - public int getDuration() | 28 | + public float getDuration() |
29 | { | 29 | { |
30 | return duration; | 30 | return duration; |
31 | } | 31 | } |