From 881516aa93856ef39d16d404a4b16f72610aefdc Mon Sep 17 00:00:00 2001 From: Equip de Desenvolupadors de PBE Date: Sun, 18 Nov 2012 20:57:46 +0000 Subject: [PATCH] --- .settings/org.eclipse.jdt.core.prefs | 15 +++++++++++---- src/com/upc/pbe/upcnews/ErrorException.java | 10 ++++++++++ src/com/upc/pbe/upcnews/MainActivity.java | 2 +- src/com/upc/pbe/upcnews/Parser.java | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------- src/com/upc/pbe/upcnews/Playlist.java | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- src/com/upc/pbe/upcnews/Segment.java | 41 +++++++++++++++++++++++++++++++++++++++++ src/com/upc/pbe/upcnews/WarningException.java | 10 ++++++++++ 7 files changed, 193 insertions(+), 40 deletions(-) create mode 100644 src/com/upc/pbe/upcnews/ErrorException.java create mode 100644 src/com/upc/pbe/upcnews/Segment.java create mode 100644 src/com/upc/pbe/upcnews/WarningException.java diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index da5d060..416f4fb 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,4 +1,11 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 -org.eclipse.jdt.core.compiler.compliance=1.5 -org.eclipse.jdt.core.compiler.source=1.5 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/src/com/upc/pbe/upcnews/ErrorException.java b/src/com/upc/pbe/upcnews/ErrorException.java new file mode 100644 index 0000000..abd185c --- /dev/null +++ b/src/com/upc/pbe/upcnews/ErrorException.java @@ -0,0 +1,10 @@ +package com.upc.pbe.upcnews; + +public class ErrorException extends Exception +{ + private static final long serialVersionUID = 1L; + public ErrorException(String message) + { + super(message); + } +} diff --git a/src/com/upc/pbe/upcnews/MainActivity.java b/src/com/upc/pbe/upcnews/MainActivity.java index c24ab54..3cfa910 100644 --- a/src/com/upc/pbe/upcnews/MainActivity.java +++ b/src/com/upc/pbe/upcnews/MainActivity.java @@ -18,7 +18,7 @@ public class MainActivity extends Activity implements OnClickListener { Button buttonDescarrega; String file = "ejemplo.xml"; - String folder = "Environment.getExternalStorageDirectory.getPath()"; // hauria de ser /sdcard/downloads + String folder = "Environment.getExternalStorageDirectory.getPath()"; TextView showText, showRoute; @Override diff --git a/src/com/upc/pbe/upcnews/Parser.java b/src/com/upc/pbe/upcnews/Parser.java index 7426c02..0260806 100644 --- a/src/com/upc/pbe/upcnews/Parser.java +++ b/src/com/upc/pbe/upcnews/Parser.java @@ -11,9 +11,9 @@ public class Parser } - public void setPlaylist(Playlist m3u8) + public void setPlaylist(Playlist pls) { - playlist = m3u8; + playlist = pls; } public Playlist getPlaylist() @@ -21,54 +21,92 @@ public class Parser return playlist; } - public void parseLine(String line) + public void parseLine(String line) throws ErrorException, WarningException { + Playlist pls = getPlaylist(); int currentLine = 0; - boolean m3u8Validated = false; - if(true) //NIGGRADA PER QUE TIRI, JA HO MIRARÉ + int currentSegment = 0; + boolean expectSegment = false; + + if(pls == null) + { + throw new ErrorException("Playlist uninitialized"); + } + + if(line.isEmpty()) { currentLine++; return; } else { - if(!m3u8Validated) + if(!pls.getValidated()) { if(line.equals(STARTWORD)) { - m3u8Validated = true; + pls.setValidated(true); + } + else + { + throw new ErrorException("Playlist is not valid"); } } + else + { + if(line.charAt(0) == '#') + { + 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])); + } + else if(extTag[0].equals("#EXT-X-TARGETDURATION")) + { + pls.setMaxDuration(Integer.parseInt(extTag[1])); + } + + else if(extTag[0].equals("#EXTINF")) + { + String[] args = extTag[1].split(","); + int duration = Integer.parseInt(args[0]); + if (duration > pls.getMaxDuration()) + { + throw new ErrorException("Segment " + currentSegment + " on line " + currentLine + +" exceeds max duration"); + } + Segment s = new Segment(duration); + s.setName(args[1]); + pls.getSegments().add(s); + currentSegment++; + expectSegment = true; + } + + else if(extTag[0].equals("#EXT-X-STREAM-INF")) + { + + } + + else if(extTag[0].equals("#EXT-X-ENDLIST")) + { + //END REACHED, IGNORE AND LET THE FILE REACH EOF + } + + else + { + throw new WarningException("Tag not implemented"); + } + } + + } + + } } - /*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="" diff --git a/src/com/upc/pbe/upcnews/Playlist.java b/src/com/upc/pbe/upcnews/Playlist.java index cb8b094..98ca928 100644 --- a/src/com/upc/pbe/upcnews/Playlist.java +++ b/src/com/upc/pbe/upcnews/Playlist.java @@ -1,6 +1,53 @@ package com.upc.pbe.upcnews; +import java.util.ArrayList; + public class Playlist { - + private boolean validated; + private int sequenceFirst; + private int maxDuration; + private ArrayList segments; + + public Playlist() + { + validated = false; + segments = new ArrayList(); + } + + public void setValidated(boolean val) + { + validated = val; + } + + public boolean getValidated() + { + return validated; + } + + public void setSequence(int seq) + { + sequenceFirst = seq; + } + + public int getSequence() + { + return sequenceFirst; + } + + public void setMaxDuration(int dur) + { + maxDuration = dur; + } + + public int getMaxDuration() + { + return maxDuration; + } + + public ArrayList getSegments() + { + return segments; + } } + diff --git a/src/com/upc/pbe/upcnews/Segment.java b/src/com/upc/pbe/upcnews/Segment.java new file mode 100644 index 0000000..319bafc --- /dev/null +++ b/src/com/upc/pbe/upcnews/Segment.java @@ -0,0 +1,41 @@ +package com.upc.pbe.upcnews; + +import java.net.MalformedURLException; +import java.net.URL; + +public class Segment +{ + private String name; + private int duration; + private URL url; + + public Segment(int dur) + { + name = ""; + duration = dur; + } + + public void setName(String nam) + { + name = nam; + } + + public String getName() + { + return name; + } + + public int getDuration() + { + return duration; + } + public void setURL(String url) throws MalformedURLException + { + this.url = new URL(url); + } + + public URL getURL() + { + return url; + } +} diff --git a/src/com/upc/pbe/upcnews/WarningException.java b/src/com/upc/pbe/upcnews/WarningException.java new file mode 100644 index 0000000..22ae5cf --- /dev/null +++ b/src/com/upc/pbe/upcnews/WarningException.java @@ -0,0 +1,10 @@ +package com.upc.pbe.upcnews; + +public class WarningException extends Exception +{ + private static final long serialVersionUID = 1L; + public WarningException(String message) + { + super(message); + } +} -- libgit2 0.22.2