diff options
Diffstat (limited to 'cmpcj')
45 files changed, 263 insertions, 59 deletions
diff --git a/cmpcj/.classpath b/cmpcj/.classpath index ae6697e..b28f98d 100644 --- a/cmpcj/.classpath +++ b/cmpcj/.classpath @@ -4,6 +4,7 @@ <classpathentry kind="src" path="res"/> <classpathentry kind="lib" path="lib/glazedlists_java15.jar"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="lib" path="lib/jackson-all-1.9.2.jar"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> + <classpathentry kind="lib" path="lib/gson-2.2.2.jar"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/cmpcj/lib/gson-2.2.2.jar b/cmpcj/lib/gson-2.2.2.jar Binary files differnew file mode 100644 index 0000000..f2108e0 --- /dev/null +++ b/cmpcj/lib/gson-2.2.2.jar diff --git a/cmpcj/lib/jackson-all-1.9.2.jar b/cmpcj/lib/jackson-all-1.9.2.jar Binary files differdeleted file mode 100644 index f1d8c3d..0000000 --- a/cmpcj/lib/jackson-all-1.9.2.jar +++ /dev/null diff --git a/cmpcj/res/images/folder_black.png b/cmpcj/res/images/folder_black.png Binary files differdeleted file mode 100644 index 01b5b20..0000000 --- a/cmpcj/res/images/folder_black.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_dvd.png b/cmpcj/res/images/folder_black_dvd.png Binary files differdeleted file mode 100644 index 26c72c2..0000000 --- a/cmpcj/res/images/folder_black_dvd.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_i_dvd.png b/cmpcj/res/images/folder_black_i_dvd.png Binary files differdeleted file mode 100644 index 2b4294c..0000000 --- a/cmpcj/res/images/folder_black_i_dvd.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_i_movies.png b/cmpcj/res/images/folder_black_i_movies.png Binary files differdeleted file mode 100644 index e5ed555..0000000 --- a/cmpcj/res/images/folder_black_i_movies.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_i_vdr.png b/cmpcj/res/images/folder_black_i_vdr.png Binary files differdeleted file mode 100644 index 129b733..0000000 --- a/cmpcj/res/images/folder_black_i_vdr.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_i_vdr_old.png b/cmpcj/res/images/folder_black_i_vdr_old.png Binary files differdeleted file mode 100644 index 4cb2584..0000000 --- a/cmpcj/res/images/folder_black_i_vdr_old.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_library.png b/cmpcj/res/images/folder_black_library.png Binary files differdeleted file mode 100644 index 6e1cc81..0000000 --- a/cmpcj/res/images/folder_black_library.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_movies.png b/cmpcj/res/images/folder_black_movies.png Binary files differdeleted file mode 100644 index 34c46f3..0000000 --- a/cmpcj/res/images/folder_black_movies.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_music.png b/cmpcj/res/images/folder_black_music.png Binary files differdeleted file mode 100644 index e534703..0000000 --- a/cmpcj/res/images/folder_black_music.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_photos.png b/cmpcj/res/images/folder_black_photos.png Binary files differdeleted file mode 100644 index 59f80a4..0000000 --- a/cmpcj/res/images/folder_black_photos.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_playlist.png b/cmpcj/res/images/folder_black_playlist.png Binary files differdeleted file mode 100644 index 6e1cc81..0000000 --- a/cmpcj/res/images/folder_black_playlist.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_vdr.png b/cmpcj/res/images/folder_black_vdr.png Binary files differdeleted file mode 100644 index 17fcbb9..0000000 --- a/cmpcj/res/images/folder_black_vdr.png +++ /dev/null diff --git a/cmpcj/res/images/folder_black_vdr_old.png b/cmpcj/res/images/folder_black_vdr_old.png Binary files differdeleted file mode 100644 index b56f5f7..0000000 --- a/cmpcj/res/images/folder_black_vdr_old.png +++ /dev/null diff --git a/cmpcj/res/images/sr_default.png b/cmpcj/res/images/sr_default.png Binary files differnew file mode 100644 index 0000000..8628dfe --- /dev/null +++ b/cmpcj/res/images/sr_default.png diff --git a/cmpcj/res/images/sr_dvd.png b/cmpcj/res/images/sr_dvd.png Binary files differnew file mode 100644 index 0000000..899b0e3 --- /dev/null +++ b/cmpcj/res/images/sr_dvd.png diff --git a/cmpcj/res/images/sr_dvd_i.png b/cmpcj/res/images/sr_dvd_i.png Binary files differnew file mode 100644 index 0000000..18a7571 --- /dev/null +++ b/cmpcj/res/images/sr_dvd_i.png diff --git a/cmpcj/res/images/sr_lvdr.png b/cmpcj/res/images/sr_lvdr.png Binary files differnew file mode 100644 index 0000000..1b90956 --- /dev/null +++ b/cmpcj/res/images/sr_lvdr.png diff --git a/cmpcj/res/images/sr_lvdr_i.png b/cmpcj/res/images/sr_lvdr_i.png Binary files differnew file mode 100644 index 0000000..31a475e --- /dev/null +++ b/cmpcj/res/images/sr_lvdr_i.png diff --git a/cmpcj/res/images/sr_movies.png b/cmpcj/res/images/sr_movies.png Binary files differnew file mode 100644 index 0000000..794a5fa --- /dev/null +++ b/cmpcj/res/images/sr_movies.png diff --git a/cmpcj/res/images/sr_movies_i.png b/cmpcj/res/images/sr_movies_i.png Binary files differnew file mode 100644 index 0000000..efe3e3a --- /dev/null +++ b/cmpcj/res/images/sr_movies_i.png diff --git a/cmpcj/res/images/sr_music.png b/cmpcj/res/images/sr_music.png Binary files differnew file mode 100644 index 0000000..cacaa0c --- /dev/null +++ b/cmpcj/res/images/sr_music.png diff --git a/cmpcj/res/images/sr_photos.png b/cmpcj/res/images/sr_photos.png Binary files differnew file mode 100644 index 0000000..8493512 --- /dev/null +++ b/cmpcj/res/images/sr_photos.png diff --git a/cmpcj/res/images/sr_playlist.png b/cmpcj/res/images/sr_playlist.png Binary files differnew file mode 100644 index 0000000..41ca388 --- /dev/null +++ b/cmpcj/res/images/sr_playlist.png diff --git a/cmpcj/res/images/sr_vdr.png b/cmpcj/res/images/sr_vdr.png Binary files differnew file mode 100644 index 0000000..d750edf --- /dev/null +++ b/cmpcj/res/images/sr_vdr.png diff --git a/cmpcj/res/images/sr_vdr_i.png b/cmpcj/res/images/sr_vdr_i.png Binary files differnew file mode 100644 index 0000000..a02a741 --- /dev/null +++ b/cmpcj/res/images/sr_vdr_i.png diff --git a/cmpcj/res/images/sradefault.png b/cmpcj/res/images/sradefault.png Binary files differnew file mode 100644 index 0000000..fa5ae3d --- /dev/null +++ b/cmpcj/res/images/sradefault.png diff --git a/cmpcj/res/images/sradvd.png b/cmpcj/res/images/sradvd.png Binary files differnew file mode 100644 index 0000000..fd66ad5 --- /dev/null +++ b/cmpcj/res/images/sradvd.png diff --git a/cmpcj/res/images/sradvd_i.png b/cmpcj/res/images/sradvd_i.png Binary files differnew file mode 100644 index 0000000..b7fc014 --- /dev/null +++ b/cmpcj/res/images/sradvd_i.png diff --git a/cmpcj/res/images/sralvdr.png b/cmpcj/res/images/sralvdr.png Binary files differnew file mode 100644 index 0000000..5677308 --- /dev/null +++ b/cmpcj/res/images/sralvdr.png diff --git a/cmpcj/res/images/sralvdr_i.png b/cmpcj/res/images/sralvdr_i.png Binary files differnew file mode 100644 index 0000000..c6f1725 --- /dev/null +++ b/cmpcj/res/images/sralvdr_i.png diff --git a/cmpcj/res/images/sramovies.png b/cmpcj/res/images/sramovies.png Binary files differnew file mode 100644 index 0000000..b74967a --- /dev/null +++ b/cmpcj/res/images/sramovies.png diff --git a/cmpcj/res/images/sramovies_i.png b/cmpcj/res/images/sramovies_i.png Binary files differnew file mode 100644 index 0000000..85c08e7 --- /dev/null +++ b/cmpcj/res/images/sramovies_i.png diff --git a/cmpcj/res/images/sramusic.png b/cmpcj/res/images/sramusic.png Binary files differnew file mode 100644 index 0000000..9a0ceb9 --- /dev/null +++ b/cmpcj/res/images/sramusic.png diff --git a/cmpcj/res/images/sraphotos.png b/cmpcj/res/images/sraphotos.png Binary files differnew file mode 100644 index 0000000..47192f0 --- /dev/null +++ b/cmpcj/res/images/sraphotos.png diff --git a/cmpcj/res/images/sraplaylist.png b/cmpcj/res/images/sraplaylist.png Binary files differnew file mode 100644 index 0000000..f1dc30b --- /dev/null +++ b/cmpcj/res/images/sraplaylist.png diff --git a/cmpcj/res/images/sravdr.png b/cmpcj/res/images/sravdr.png Binary files differnew file mode 100644 index 0000000..2f75626 --- /dev/null +++ b/cmpcj/res/images/sravdr.png diff --git a/cmpcj/res/images/sravdr_i.png b/cmpcj/res/images/sravdr_i.png Binary files differnew file mode 100644 index 0000000..24c0e18 --- /dev/null +++ b/cmpcj/res/images/sravdr_i.png diff --git a/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java index 73f6204..0448549 100644 --- a/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java +++ b/cmpcj/src/de/schwarzrot/cmpc/app/SRMediaPlayer.java @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== * - * File: SRMediaPlayer.java - * Created: - * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media + * File: SRMediaPlayer.java Created: Author: <a + * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend + * (client) part of compound media player uses external players to play the + * media * * CMP - compound media player * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. + * is a client/server mediaplayer intended to play any media from any + * workstation without the need to export or mount shares. cmps is an easy to + * use backend with a (ready to use) HTML-interface. Additionally the backend + * supports authentication via HTTP-digest authorization. cmpc is a client with + * vdr-like osd-menues. * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under + * Creative Commons by-sa For details see + * http://creativecommons.org/licenses/by-sa/3.0/ * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * The cmp project's homepage is at + * http://projects.vdr-developer.org/projects/cmp * * -------------------------------------------------------------- */ @@ -159,6 +159,7 @@ public class SRMediaPlayer implements IMediaPlayer { public static void main(final String[] args) { + appInfo(); javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { @@ -169,6 +170,14 @@ public class SRMediaPlayer implements IMediaPlayer { }); } + + protected static void appInfo() { + System.err.println("cmpcj - the java frontend of CMP (compound media player)"); + System.err.println(" serves to browse a medialist from remote systems and to start a player"); + System.err.println(" for selected media."); + System.err.println(" (c) 2012 - Reinhard Mantey - some rights reserved."); + System.err.println(" CMP is published as open source under Creative Commons by-sa"); + } private boolean debug = false; private JFrame mainFrame; private Config config; diff --git a/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java index c336329..57f320f 100644 --- a/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java +++ b/cmpcj/src/de/schwarzrot/cmpc/domain/MediaType.java @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== * - * File: MediaType.java - * Created: - * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media + * File: MediaType.java Created: Author: <a + * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend + * (client) part of compound media player uses external players to play the + * media * * CMP - compound media player * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. + * is a client/server mediaplayer intended to play any media from any + * workstation without the need to export or mount shares. cmps is an easy to + * use backend with a (ready to use) HTML-interface. Additionally the backend + * supports authentication via HTTP-digest authorization. cmpc is a client with + * vdr-like osd-menues. * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under + * Creative Commons by-sa For details see + * http://creativecommons.org/licenses/by-sa/3.0/ * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * The cmp project's homepage is at + * http://projects.vdr-developer.org/projects/cmp * * -------------------------------------------------------------- */ @@ -32,7 +32,7 @@ public class MediaType { } - public int getStart() { + public long getStart() { return start; } @@ -42,10 +42,10 @@ public class MediaType { } - public void setStart(int start) { + public void setStart(long start) { this.start = start; } private String name; - private int start; + private long start; } diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java index b37834c..983fdd3 100644 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java +++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaListLoader.java @@ -1,25 +1,25 @@ /** * ======================== legal notice ====================== * - * File: MediaListLoader.java - * Created: - * Author: <a href="mailto:geronimo013@gmx.de">Geronimo</a> - * Project: cmpc - a java frontend (client) part of compound media player - * uses external players to play the media + * File: MediaListLoader.java Created: Author: <a + * href="mailto:geronimo013@gmx.de">Geronimo</a> Project: cmpc - a java frontend + * (client) part of compound media player uses external players to play the + * media * * CMP - compound media player * - * is a client/server mediaplayer intended to play any media from any workstation - * without the need to export or mount shares. cmps is an easy to use backend - * with a (ready to use) HTML-interface. Additionally the backend supports - * authentication via HTTP-digest authorization. - * cmpc is a client with vdr-like osd-menues. + * is a client/server mediaplayer intended to play any media from any + * workstation without the need to export or mount shares. cmps is an easy to + * use backend with a (ready to use) HTML-interface. Additionally the backend + * supports authentication via HTTP-digest authorization. cmpc is a client with + * vdr-like osd-menues. * - * Copyright (c) 2012 Reinhard Mantey, some rights reserved! - * published under Creative Commons by-sa - * For details see http://creativecommons.org/licenses/by-sa/3.0/ + * Copyright (c) 2012 Reinhard Mantey, some rights reserved! published under + * Creative Commons by-sa For details see + * http://creativecommons.org/licenses/by-sa/3.0/ * - * The cmp project's homepage is at http://projects.vdr-developer.org/projects/cmp + * The cmp project's homepage is at + * http://projects.vdr-developer.org/projects/cmp * * -------------------------------------------------------------- */ @@ -30,7 +30,6 @@ import java.net.ConnectException; import java.net.URL; import java.net.URLConnection; import java.util.Date; -import org.codehaus.jackson.map.ObjectMapper; import ca.odell.glazedlists.BasicEventList; import ca.odell.glazedlists.EventList; import de.schwarzrot.cmpc.domain.Media; @@ -64,7 +63,7 @@ public class MediaListLoader implements Runnable { start = new Date(); request = new URL("http", hostName, port, "/?format=json"); URLConnection conn = request.openConnection(); - final PlayList firstPlaylist = jsonOM.readValue(conn.getInputStream(), PlayList.class); + final PlayList firstPlaylist = jsonParser.parseListChunk(conn.getInputStream()); mediaPool.getReadWriteLock().writeLock().lock(); for (Media m : firstPlaylist.getResults()) { @@ -85,7 +84,7 @@ public class MediaListLoader implements Runnable { uri = String.format("/?start=%d&limit=%d&format=json", n, 100); request = new URL("http", hostName, port, uri); conn = request.openConnection(); - next = jsonOM.readValue(conn.getInputStream(), PlayList.class); + next = jsonParser.parseListChunk(conn.getInputStream()); mediaPool.getReadWriteLock().writeLock().lock(); for (Media m : next.getResults()) { mediaPool.add(m); @@ -96,6 +95,7 @@ public class MediaListLoader implements Runnable { } } catch (Throwable t) { System.out.println("Oups, media list contains now #" + mediaPool.size() + " entries."); + System.err.println("Error on chunk #" + n); t.printStackTrace(); } finally { try { @@ -119,6 +119,6 @@ public class MediaListLoader implements Runnable { private String hostName; private int port; - private ObjectMapper jsonOM = new ObjectMapper(); + private MedialistParser jsonParser = new MedialistParser(); private EventList<Media> mediaPool = new BasicEventList<Media>(); } diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java index 24cd506..bde865a 100644 --- a/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java +++ b/cmpcj/src/de/schwarzrot/cmpc/util/MediaTypeSelect.java @@ -60,14 +60,17 @@ public class MediaTypeSelect extends AbstractMatcherEditor<Media> implements Lis @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + ImageIcon icon = null; + if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); + icon = selImages[((Media.SupportedMediaType) value).ordinal()]; } else { setBackground(list.getBackground()); setForeground(list.getForeground()); + icon = stdImages[((Media.SupportedMediaType) value).ordinal()]; } - ImageIcon icon = images[((Media.SupportedMediaType) value).ordinal()]; setSize(110, 110); setHorizontalAlignment(JLabel.CENTER); @@ -86,21 +89,35 @@ public class MediaTypeSelect extends AbstractMatcherEditor<Media> implements Lis ClassLoader cl = getClass().getClassLoader(); URL url; - images = new ImageIcon[iconFiles.length]; + stdImages = new ImageIcon[iconFiles.length]; for (int i = 0; i < iconFiles.length; ++i) { try { url = cl.getResource(iconFiles[i]); img = ImageIO.read(url); - images[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH)); + stdImages[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH)); } catch (Throwable t) { System.err.println("failed to read image from " + iconFiles[i]); t.printStackTrace(); } } + + selImages = new ImageIcon[activeIconFiles.length]; + for (int i = 0; i < activeIconFiles.length; ++i) { + try { + url = cl.getResource(activeIconFiles[i]); + + img = ImageIO.read(url); + selImages[i] = new ImageIcon(img.getScaledInstance(110, 110, Image.SCALE_SMOOTH)); + } catch (Throwable t) { + System.err.println("failed to read image from " + activeIconFiles[i]); + t.printStackTrace(); + } + } } - ImageIcon[] images; + ImageIcon[] stdImages; + ImageIcon[] selImages; } @@ -139,11 +156,15 @@ public class MediaTypeSelect extends AbstractMatcherEditor<Media> implements Lis private EventList<Media.SupportedMediaType> selectedTypes; private JList mediaTypeJList; private static final String[] iconFiles; + private static final String[] activeIconFiles; static { - iconFiles = new String[] { "images/folder_black.png", "images/folder_black_music.png", - "images/folder_black_movies.png", "images/folder_black_i_movies.png", "images/folder_black_dvd.png", - "images/folder_black_i_dvd.png", "images/folder_black_vdr_old.png", - "images/folder_black_i_vdr_old.png", "images/folder_black_vdr.png", "images/folder_black_i_vdr.png", - "images/folder_black_photos.png", "images/folder_black.png" }; + iconFiles = new String[] { "images/sr_default.png", "images/sr_music.png", "images/sr_movies.png", + "images/sr_movies_i.png", "images/sr_dvd.png", "images/sr_dvd_i.png", "images/sr_lvdr.png", + "images/sr_lvdr_i.png", "images/sr_vdr.png", "images/sr_vdr_i.png", "images/sr_photos.png", + "images/sr_default.png" }; + activeIconFiles = new String[] { "images/sradefault.png", "images/sramusic.png", "images/sramovies.png", + "images/sramovies_i.png", "images/sradvd.png", "images/sradvd_i.png", "images/sralvdr.png", + "images/sralvdr_i.png", "images/sravdr.png", "images/sravdr_i.png", "images/sraphotos.png", + "images/sradefault.png" }; } } diff --git a/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java b/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java new file mode 100644 index 0000000..8f69af0 --- /dev/null +++ b/cmpcj/src/de/schwarzrot/cmpc/util/MedialistParser.java @@ -0,0 +1,173 @@ +package de.schwarzrot.cmpc.util; + + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import com.google.gson.stream.JsonReader; +import de.schwarzrot.cmpc.domain.Media; +import de.schwarzrot.cmpc.domain.MediaType; +import de.schwarzrot.cmpc.domain.PlayList; + + +public class MedialistParser { + public PlayList parseListChunk(InputStream is) { + JsonReader reader = null; + PlayList rv = null; + + try { + reader = new JsonReader(new InputStreamReader(is, "UTF-8")); + + rv = readPlayList(reader); + } catch (Throwable t) { + t.printStackTrace(); + } finally { + try { + reader.close(); + } catch (Throwable t) { + } + } + return rv; + } + + + @Test + public void testJSonParsing() { + FileInputStream fis = null; + + try { + fis = new FileInputStream(new File("test.json")); + parseListChunk(fis); + fis.close(); + fis = null; + } catch (Throwable t) { + t.printStackTrace(); + } finally { + if (fis != null) { + try { + fis.close(); + } catch (Throwable t) { + } + } + } + } + + + protected Media readMedia(JsonReader reader) { + Media rv = new Media(); + + try { + reader.beginObject(); + while (reader.hasNext()) { + String name = reader.nextName(); + + if ("name".equals(name)) { + rv.setName(reader.nextString()); + } else if ("type".equals(name)) { + rv.setType(reader.nextInt()); + } else if ("format".equals(name)) { + rv.setFormat(reader.nextString()); + } else if ("width".equals(name)) { + rv.setWidth(reader.nextInt()); + } else if ("height".equals(name)) { + rv.setHeight(reader.nextInt()); + } else if ("path".equals(name)) { + rv.setPath(reader.nextString()); + } else { + reader.skipValue(); + } + } + reader.endObject(); + } catch (Throwable t) { + t.printStackTrace(); + } + return rv; + } + + + protected List<Media> readMediaArray(JsonReader reader) { + List<Media> rv = new ArrayList<Media>(); + + try { + reader.beginArray(); + while (reader.hasNext()) { + rv.add(readMedia(reader)); + } + reader.endArray(); + } catch (Throwable t) { + t.printStackTrace(); + } + return rv; + } + + + protected MediaType readMediaType(JsonReader reader) { + MediaType rv = new MediaType(); + + try { + reader.beginObject(); + while (reader.hasNext()) { + String name = reader.nextName(); + + if ("name".equals(name)) { + rv.setName(reader.nextString()); + } else if ("start".equals(name)) { + rv.setStart(reader.nextLong()); + } else { + reader.skipValue(); + } + } + reader.endObject(); + } catch (Throwable t) { + t.printStackTrace(); + } + return rv; + } + + + protected PlayList readPlayList(JsonReader reader) { + PlayList rv = new PlayList(); + + try { + reader.beginObject(); + while (reader.hasNext()) { + String name = reader.nextName(); + + if ("total".equals(name)) { + rv.setTotal(reader.nextLong()); + } else if ("types".equals(name)) { + rv.setTypes(readTypeArray(reader)); + } else if ("results".equals(name)) { + rv.setResults(readMediaArray(reader)); + } else { + reader.skipValue(); + } + } + reader.endObject(); + } catch (Throwable t) { + t.printStackTrace(); + rv = null; + } + return rv; + } + + + protected List<MediaType> readTypeArray(JsonReader reader) { + List<MediaType> rv = new ArrayList<MediaType>(); + + try { + reader.beginArray(); + while (reader.hasNext()) { + rv.add(readMediaType(reader)); + } + reader.endArray(); + } catch (Throwable t) { + t.printStackTrace(); + } + return rv; + } +} |