Commit 3b7556d5b5e67811c35823996b294d8a52ecb176
1 parent
08b0801c
Added Playlist and Parses classes
Showing
2 changed files
with
134 additions
and
0 deletions
src/com/upc/pbe/upcnews/Parser.java
0 → 100644
1 | +package com.upc.pbe.upcnews; | |
2 | + | |
3 | +import android.annotation.TargetApi; | |
4 | + | |
5 | +public class Parser | |
6 | +{ | |
7 | + private Playlist playlist; | |
8 | + | |
9 | + private static final String STARTWORD = "#EXTM3U"; | |
10 | + | |
11 | + public Parser() | |
12 | + { | |
13 | + | |
14 | + } | |
15 | + | |
16 | + public void setPlaylist(Playlist m3u8) | |
17 | + { | |
18 | + playlist = m3u8; | |
19 | + } | |
20 | + | |
21 | + public Playlist getPlaylist() | |
22 | + { | |
23 | + return playlist; | |
24 | + } | |
25 | + | |
26 | + public void parseLine(String line) | |
27 | + { | |
28 | + int currentLine = 0; | |
29 | + boolean m3u8Validated = false; | |
30 | + if(line.isEmpty()) | |
31 | + { | |
32 | + currentLine++; | |
33 | + return; | |
34 | + } | |
35 | + else | |
36 | + { | |
37 | + if(!m3u8Validated) | |
38 | + { | |
39 | + if(line.equals(STARTWORD)) | |
40 | + { | |
41 | + m3u8Validated = true; | |
42 | + } | |
43 | + } | |
44 | + } | |
45 | + | |
46 | + | |
47 | + /*else | |
48 | + if [[ $M3U8_VALIDATED -eq 0 ]]; then | |
49 | + if [[ $line == "#EXTM3U" ]]; then | |
50 | + M3U8_VALIDATED=1 | |
51 | + else | |
52 | + echo "ERROR: This is not an m3u8 file!!" | |
53 | + exit 1 | |
54 | + fi | |
55 | + else | |
56 | + if [[ `echo $line | head -c1` == "#" ]]; then | |
57 | + if [[ `echo $line | head -c4` == "#EXT" ]]; then | |
58 | + case `echo $line | cut -d':' -f 1` in | |
59 | + "#EXT-X-MEDIA-SEQUENCE") | |
60 | + SEQUENCE_FIRST=`echo $line | cut -d':' -f 2`; | |
61 | + echo "INFO: First element to be played is: $SEQUENCE_FIRST";; | |
62 | + "#EXT-X-TARGETDURATION") | |
63 | + MAX_DURATION=`echo $line | cut -d':' -f 2`; | |
64 | + echo "INFO: Maximum segment duration is: $MAX_DURATION";; | |
65 | + "#EXTINF") | |
66 | + DURATION=`echo $line | cut -d':' -f 2 | cut -d',' -f 1` | |
67 | + if [[ $DURATION > $MAX_DURATION ]]; then | |
68 | + echo "ERROR: Segment $CURRENT_SEGMENT on line $CURRENT_LINE is larger than EXT-X-TARGETDURATION" | |
69 | + exit 1 | |
70 | + else | |
71 | + NAME=`echo $line | cut -d':' -f 2 | cut -d',' -f 2` | |
72 | + EXTINF=1 | |
73 | + fi;; | |
74 | + "#EXT-X-STREAM-INF") | |
75 | + EXTXSTREAM=1 | |
76 | + PROGRAMID="" | |
77 | + CODECS="" | |
78 | + RESOLUTION="" | |
79 | + ARGUMENTS=`echo $line | cut -d':' -f 2` | |
80 | + i=1 | |
81 | + while [[ `echo $ARGUMENTS | cut -d',' -f $i` != "" ]]; do | |
82 | + PARAMETER=`echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 2` | |
83 | + case `echo $ARGUMENTS | cut -d',' -f $i | cut -d'=' -f 1` in | |
84 | + "PROGRAM-ID") | |
85 | + PROGRAMID=$PARAMETER;; | |
86 | + "BANDWIDTH") | |
87 | + BANDWIDTH=$PARAMETER;; | |
88 | + "RESOLUTION") | |
89 | + RESOLUTION=$PARAMETER;; | |
90 | + "CODECS") | |
91 | + CODECS=$PARAMETER;; | |
92 | + esac | |
93 | + ((i++)) | |
94 | + done;; | |
95 | + "#EXT-X-ENDLIST") | |
96 | + echo "INFO: Playlist end reached";; | |
97 | + esac | |
98 | + else | |
99 | + echo "INFO: Comment found on line $CURRENT_LINE: \"`echo $line | cut -d'#' -f 2`\"" | |
100 | + fi; | |
101 | + else | |
102 | + if [[ $EXTINF -eq 1 ]]; then | |
103 | + echo -n "SEGMENT $CURRENT_SEGMENT: \"$NAME\" - $DURATION seconds ($line)" | |
104 | + EXTINF=0 | |
105 | + if [[ $CURRENT_SEGMENT -eq $SEQUENCE_FIRST ]]; then | |
106 | + echo " (first element)" | |
107 | + else | |
108 | + echo "" | |
109 | + fi; | |
110 | + ((CURRENT_SEGMENT++)) | |
111 | + elif [[ $EXTXSTREAM -eq 1 ]]; then | |
112 | + echo "PLAYLIST: $line [PROGRAM-ID=$PROGRAMID,BANDWIDTH=$BANDWIDTH,RESOLUTION=$RESOLUTION,CODECS=$CODECS]" | |
113 | + EXTXSTREAM=0 | |
114 | + else | |
115 | + echo "ERROR: Unexpected string \"$line\"" | |
116 | + exit 1 | |
117 | + fi | |
118 | + fi | |
119 | + fi | |
120 | + fi | |
121 | + ((CURRENT_LINE++)) | |
122 | +} | |
123 | + | |
124 | + */ | |
125 | + | |
126 | + } | |
127 | + | |
128 | +} | ... | ... |