diff --git a/src/com/upc/pbe/upcnews/SegmentList.java b/src/com/upc/pbe/upcnews/List.java index ca2bf0e..f0412eb 100644 --- a/src/com/upc/pbe/upcnews/SegmentList.java +++ b/src/com/upc/pbe/upcnews/List.java @@ -2,14 +2,15 @@ package com.upc.pbe.upcnews; import java.util.ArrayList; -public class SegmentList +public class List { private boolean validated; private int sequenceFirst; private int maxDuration; private ArrayList segments; + private ParentList parent; - public SegmentList() + public List() { validated = false; segments = new ArrayList(); @@ -45,6 +46,16 @@ public class SegmentList return maxDuration; } + public void setParent(ParentList p) + { + parent = p; + } + + public ParentList getParent() + { + return parent; + } + public ArrayList getSegments() { return segments; diff --git a/src/com/upc/pbe/upcnews/ParentList.java b/src/com/upc/pbe/upcnews/ParentList.java new file mode 100644 index 0000000..195843b --- /dev/null +++ b/src/com/upc/pbe/upcnews/ParentList.java @@ -0,0 +1,27 @@ +package com.upc.pbe.upcnews; + +import java.util.ArrayList; + +public class ParentList +{ + int currentID; + ArrayList lists; //per cada qualitat + + public ParentList() + { + currentID = 0; + lists = new ArrayList(); + } + + public int getCurrent() + { + return currentID; + } + + public ArrayList getLists() + { + return lists; + } + + +} diff --git a/src/com/upc/pbe/upcnews/Parser.java b/src/com/upc/pbe/upcnews/Parser.java index 0e10a0d..ed771c9 100644 --- a/src/com/upc/pbe/upcnews/Parser.java +++ b/src/com/upc/pbe/upcnews/Parser.java @@ -1,39 +1,40 @@ package com.upc.pbe.upcnews; +import java.util.ArrayList; + public class Parser -{ - private SegmentList playlist; - +{ private static final String STARTWORD = "#EXTM3U"; - public Parser() - { - - } + private int currentLine; + private int currentSegment; + private int currentList; - public void setPlaylist(SegmentList pls) + public Parser() { - playlist = pls; + currentLine = 0; + currentSegment = 0; + currentList = 0; } - public SegmentList getPlaylist() + public ArrayList parseFile(String file) throws ErrorException, WarningException, InfoException { - return playlist; + ArrayList lists = new ArrayList(); + 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; } - public void parseLine(String line) throws ErrorException, WarningException, InfoException + public void parseLine(String line, ArrayList lists) throws ErrorException, WarningException, InfoException { - SegmentList pls = getPlaylist(); - int currentLine = 0; - int currentSegment = 0; boolean expectSegment = false; boolean expectList = false; - if(pls == null) - { - throw new ErrorException("Playlist uninitialized"); - } - if(line.isEmpty()) { currentLine++; @@ -41,6 +42,7 @@ public class Parser } else { + List pls = lists.get(currentList).getLists().get(lists.get(currentList).currentID); if(!pls.getValidated()) { if(line.equals(STARTWORD)) @@ -59,7 +61,6 @@ public class Parser if(line.substring(0,4).equals("#EXT")) { String[] extTag = line.split(":"); - //switch(extTag[0]) Esto no se puede usar hasta JDK7 y Android no lo permite, diffikultyz??? if(extTag[0].equals("#EXT-X-MEDIA-SEQUENCE")) { pls.setSequence(Integer.parseInt(extTag[1])); @@ -87,8 +88,8 @@ public class Parser else if(extTag[0].equals("#EXT-X-STREAM-INF")) { - /*EXTXSTREAM=1 - PROGRAMID="" + expectList = true; + /*PROGRAMID="" CODECS="" RESOLUTION="" ARGUMENTS=`echo $line | cut -d':' -f 2` diff --git a/src/com/upc/pbe/upcnews/Playlist.java b/src/com/upc/pbe/upcnews/Playlist.java index 1812c49..e69de29 100644 --- a/src/com/upc/pbe/upcnews/Playlist.java +++ b/src/com/upc/pbe/upcnews/Playlist.java @@ -1,12 +0,0 @@ -package com.upc.pbe.upcnews; - -public class Playlist -{ - private SegmentList segmentList; - - public Playlist() - { - segmentList = new SegmentList(); - } - -}