From 3b7556d5b5e67811c35823996b294d8a52ecb176 Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Wed, 7 Nov 2012 16:36:50 +0000 Subject: [PATCH] Added Playlist and Parses classes --- src/com/upc/pbe/upcnews/Parser.java | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/com/upc/pbe/upcnews/Playlist.java | 6 ++++++ 2 files changed, 134 insertions(+), 0 deletions(-) create mode 100644 src/com/upc/pbe/upcnews/Parser.java create mode 100644 src/com/upc/pbe/upcnews/Playlist.java diff --git a/src/com/upc/pbe/upcnews/Parser.java b/src/com/upc/pbe/upcnews/Parser.java new file mode 100644 index 0000000..a92ff6e --- /dev/null +++ b/src/com/upc/pbe/upcnews/Parser.java @@ -0,0 +1,128 @@ +package com.upc.pbe.upcnews; + +import android.annotation.TargetApi; + +public class Parser +{ + private Playlist playlist; + + private static final String STARTWORD = "#EXTM3U"; + + public Parser() + { + + } + + public void setPlaylist(Playlist m3u8) + { + playlist = m3u8; + } + + public Playlist getPlaylist() + { + return playlist; + } + + public void parseLine(String line) + { + int currentLine = 0; + boolean m3u8Validated = false; + if(line.isEmpty()) + { + currentLine++; + return; + } + else + { + if(!m3u8Validated) + { + if(line.equals(STARTWORD)) + { + m3u8Validated = true; + } + } + } + + + /*else + if [[ $M3U8_VALIDATED -eq 0 ]]; then + if [[ $line == "#EXTM3U" ]]; then + M3U8_VALIDATED=1 + else + echo "ERROR: This is not an m3u8 file!!" + exit 1 + fi + else + if [[ `echo $line | head -c1` == "#" ]]; then + if [[ `echo $line | head -c4` == "#EXT" ]]; then + case `echo $line | cut -d':' -f 1` in + "#EXT-X-MEDIA-SEQUENCE") + SEQUENCE_FIRST=`echo $line | cut -d':' -f 2`; + echo "INFO: First element to be played is: $SEQUENCE_FIRST";; + "#EXT-X-TARGETDURATION") + MAX_DURATION=`echo $line | cut -d':' -f 2`; + echo "INFO: Maximum segment duration is: $MAX_DURATION";; + "#EXTINF") + DURATION=`echo $line | cut -d':' -f 2 | cut -d',' -f 1` + if [[ $DURATION > $MAX_DURATION ]]; then + echo "ERROR: Segment $CURRENT_SEGMENT on line $CURRENT_LINE is larger than EXT-X-TARGETDURATION" + exit 1 + else + NAME=`echo $line | cut -d':' -f 2 | cut -d',' -f 2` + EXTINF=1 + fi;; + "#EXT-X-STREAM-INF") + EXTXSTREAM=1 + 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;; + "#EXT-X-ENDLIST") + echo "INFO: Playlist end reached";; + esac + else + echo "INFO: Comment found on line $CURRENT_LINE: \"`echo $line | cut -d'#' -f 2`\"" + fi; + else + if [[ $EXTINF -eq 1 ]]; then + echo -n "SEGMENT $CURRENT_SEGMENT: \"$NAME\" - $DURATION seconds ($line)" + EXTINF=0 + if [[ $CURRENT_SEGMENT -eq $SEQUENCE_FIRST ]]; then + echo " (first element)" + else + echo "" + fi; + ((CURRENT_SEGMENT++)) + elif [[ $EXTXSTREAM -eq 1 ]]; then + echo "PLAYLIST: $line [PROGRAM-ID=$PROGRAMID,BANDWIDTH=$BANDWIDTH,RESOLUTION=$RESOLUTION,CODECS=$CODECS]" + EXTXSTREAM=0 + else + echo "ERROR: Unexpected string \"$line\"" + exit 1 + fi + fi + fi + fi + ((CURRENT_LINE++)) +} + + */ + + } + +} diff --git a/src/com/upc/pbe/upcnews/Playlist.java b/src/com/upc/pbe/upcnews/Playlist.java new file mode 100644 index 0000000..cb8b094 --- /dev/null +++ b/src/com/upc/pbe/upcnews/Playlist.java @@ -0,0 +1,6 @@ +package com.upc.pbe.upcnews; + +public class Playlist +{ + +} -- libgit2 0.22.2