From c87458590ca5b8680b061772b914789f72f391c8 Mon Sep 17 00:00:00 2001 From: Adam Howard Date: Sun, 8 Nov 2015 02:04:03 +0000 Subject: [PATCH] refactoring VideoInfo & VideoInfoItem, part 1: + created enum VideoFormat --- .../java/org/schabi/newpipe/VideoFormat.java | 46 +++++++ .../java/org/schabi/newpipe/VideoInfo.java | 117 ++++-------------- .../org/schabi/newpipe/VideoInfoItem.java | 3 +- 3 files changed, 75 insertions(+), 91 deletions(-) create mode 100644 app/src/main/java/org/schabi/newpipe/VideoFormat.java diff --git a/app/src/main/java/org/schabi/newpipe/VideoFormat.java b/app/src/main/java/org/schabi/newpipe/VideoFormat.java new file mode 100644 index 000000000..f72acbd4b --- /dev/null +++ b/app/src/main/java/org/schabi/newpipe/VideoFormat.java @@ -0,0 +1,46 @@ +package org.schabi.newpipe; + +/** + * Created by scc on 08/11/15. + */ +public enum VideoFormat { + // id name suffix mime type + MPEG_4 (0x0, "MPEG-4", "mp4", "video/mp4"), + v3GPP (0x1, "3GPP", "3gp", "video/3gpp"), + WEBM (0x2, "WebM", "webm", "video/webm"), + M4A (0x3, "m4a", "m4a", "audio/mp4"), + WEBMA (0x4, "WebM", "webm", "audio/webm"); + + public final int id; + public final String name; + public final String suffix; + public final String mimeType; + + VideoFormat(int id, String name, String suffix, String mimeType) { + this.id = id; + this.name = name; + this.suffix = suffix; + this.mimeType = mimeType; + } + + public static String getNameById(int ident) { + for (VideoFormat vf : VideoFormat.values()) { + if(vf.id == ident) return vf.name; + } + return ""; + } + + public static String getSuffixById(int ident) { + for (VideoFormat vf : VideoFormat.values()) { + if(vf.id == ident) return vf.suffix; + } + return ""; + } + + public static String getMimeById(int ident) { + for (VideoFormat vf : VideoFormat.values()) { + if(vf.id == ident) return vf.mimeType; + } + return ""; + } +} diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfo.java b/app/src/main/java/org/schabi/newpipe/VideoInfo.java index 0e0e149dc..55aa3c8ee 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfo.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfo.java @@ -1,5 +1,9 @@ package org.schabi.newpipe; +import android.graphics.Bitmap; +import android.util.Log; +import java.util.Vector; + /** * Created by Christian Schabesberger on 26.08.15. * @@ -20,82 +24,36 @@ package org.schabi.newpipe; * along with NewPipe. If not, see . */ -import android.graphics.Bitmap; -import android.util.Log; - -import java.util.Vector; public class VideoInfo { + public String id = ""; + public String title = ""; + public String uploader = ""; + public String thumbnail_url = ""; + public Bitmap thumbnail = null; + public String webpage_url = ""; + public String upload_date = ""; + public String view_count = ""; + + public String uploader_thumbnail_url = ""; + public Bitmap uploader_thumbnail = null; + public String description = ""; + public int duration = -1; + public int age_limit = 0; + public String like_count = ""; + public String dislike_count = ""; + public String average_rating = ""; + public VideoStream[] videoStreams = null; + public AudioStream[] audioStreams = null; + public VideoInfoItem nextVideo = null; + public VideoInfoItem[] relatedVideos = null; + public int videoAvailableStatus = VIDEO_AVAILABLE; private static final String TAG = VideoInfo.class.toString(); - // format identifier - public static final int I_MPEG_4 = 0x0; - public static final int I_3GPP = 0x1; - public static final int I_WEBM = 0x2; - public static final int I_M4A = 0x3; - public static final int I_WEBMA = 0x4; - - // format name - public static final String F_MPEG_4 = "MPEG-4"; - public static final String F_3GPP = "3GPP"; - public static final String F_WEBM = "WebM"; - public static final String F_M4A = "m4a"; - public static final String F_WEBMA = "WebM"; - - // file suffix - public static final String C_MPEG_4 = "mp4"; - public static final String C_3GPP = "3gp"; - public static final String C_WEBM = "webm"; - public static final String C_M4A = "m4a"; - public static final String C_WEBMA = "webm"; - - // mimeType - public static final String M_MPEG_4 = "video/mp4"; - public static final String M_3GPP = "video/3gpp"; - public static final String M_WEBM = "video/webm"; - public static final String M_M4A = "audio/mp4"; - public static final String M_WEBMA = "audio/webm"; - public static final int VIDEO_AVAILABLE = 0x00; public static final int VIDEO_UNAVAILABLE = 0x01; - public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;//German DRM organisation; sound pretty draconian - - public static String getNameById(int id) { - switch(id) { - case I_MPEG_4: return F_MPEG_4; - case I_3GPP: return F_3GPP; - case I_WEBM: return F_WEBM; - case I_M4A: return F_M4A; - case I_WEBMA: return F_WEBMA; - default: formatNotKnown(id); - } - return ""; - } - - public static String getSuffixById(int id) { - switch(id) { - case I_MPEG_4: return C_MPEG_4; - case I_3GPP: return C_3GPP; - case I_WEBM: return C_WEBM; - case I_M4A: return C_M4A; - case I_WEBMA: return C_WEBMA; - default: formatNotKnown(id); - } - return ""; - } - - public static String getMimeById(int id) { - switch(id) { - case I_MPEG_4: return M_MPEG_4; - case I_3GPP: return M_3GPP; - case I_WEBM: return M_WEBM; - case I_M4A: return M_M4A; - case I_WEBMA: return M_WEBMA; - default: formatNotKnown(id); - } - return ""; - } + public static final int VIDEO_UNAVAILABLE_GEMA = 0x02;//German DRM organisation public static class VideoStream { public VideoStream(String url, int format, String res) { @@ -123,25 +81,4 @@ public class VideoInfo { } - public String id = ""; - public String uploader = ""; - public String upload_date = ""; - public String uploader_thumbnail_url = ""; - public Bitmap uploader_thumbnail = null; - public String title = ""; - public String thumbnail_url = ""; - public Bitmap thumbnail = null; - public String description = ""; - public int duration = -1; - public int age_limit = 0; - public String webpage_url = ""; - public String view_count = ""; - public String like_count = ""; - public String dislike_count = ""; - public String average_rating = ""; - public VideoStream[] videoStreams = null; - public AudioStream[] audioStreams = null; - public VideoInfoItem nextVideo = null; - public VideoInfoItem[] relatedVideos = null; - public int videoAvailableStatus = VIDEO_AVAILABLE; } \ No newline at end of file diff --git a/app/src/main/java/org/schabi/newpipe/VideoInfoItem.java b/app/src/main/java/org/schabi/newpipe/VideoInfoItem.java index e34f064b1..dca5f0edc 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoInfoItem.java +++ b/app/src/main/java/org/schabi/newpipe/VideoInfoItem.java @@ -28,13 +28,14 @@ public class VideoInfoItem implements Parcelable { public String id = ""; public String title = ""; public String uploader = ""; - public String duration = ""; public String thumbnail_url = ""; public Bitmap thumbnail = null; public String webpage_url = ""; public String upload_date = ""; public String view_count = ""; + public String duration = ""; + protected VideoInfoItem(Parcel in) { id = in.readString(); title = in.readString();