From e7e2ca8427ed28f8c308a0053e1cc03152a4b7b6 Mon Sep 17 00:00:00 2001 From: Wei Zhuo Date: Wed, 16 Sep 2015 16:27:10 +1000 Subject: [PATCH] Play SBS video --- sbs/build.gradle | 3 +- .../io/github/xwz/sbs/api/SBSApiBase.java | 30 +++-- .../io/github/xwz/sbs/api/SBSAuthApi.java | 114 ++++++++++++++++++ .../io/github/xwz/sbs/api/SBSRelatedApi.java | 8 +- .../xwz/sbs/content/ContentManager.java | 6 +- 5 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 sbs/src/main/java/io/github/xwz/sbs/api/SBSAuthApi.java diff --git a/sbs/build.gradle b/sbs/build.gradle index 97fe125..1f9a7c1 100644 --- a/sbs/build.gradle +++ b/sbs/build.gradle @@ -21,10 +21,9 @@ android { productFlavors { app { - buildConfigField 'String', 'AUTH_TOKEN', getAppProp('SBS_AUTH_TOKEN') buildConfigField 'String', 'API_URL', getAppProp('SBS_API_URL') buildConfigField 'String', 'RELATED_URL', getAppProp('SBS_RELATED_URL') - buildConfigField 'String', 'SMIL_URL', getAppProp('SBS_SMIL_URL') + buildConfigField 'String', 'VIDEO_URL', getAppProp('SBS_VIDEO_URL') } } } diff --git a/sbs/src/main/java/io/github/xwz/sbs/api/SBSApiBase.java b/sbs/src/main/java/io/github/xwz/sbs/api/SBSApiBase.java index 8b8f272..70e1e39 100644 --- a/sbs/src/main/java/io/github/xwz/sbs/api/SBSApiBase.java +++ b/sbs/src/main/java/io/github/xwz/sbs/api/SBSApiBase.java @@ -17,7 +17,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import io.github.xwz.base.ImmutableMap; import io.github.xwz.base.api.HttpApiBase; import io.github.xwz.base.models.IEpisodeModel; import io.github.xwz.sbs.BuildConfig; @@ -26,15 +29,10 @@ abstract class SBSApiBase extends HttpApiBase { private static final String API_URL = BuildConfig.API_URL; private static final String RELATED_URL = BuildConfig.RELATED_URL; - private static final String SMIL_URL = BuildConfig.SMIL_URL; - private static final String AUTH_TOKEN = BuildConfig.AUTH_TOKEN; - - // http://www.sbs.com.au/api/video_feed/related?context=android&form=json&id=517455939941 - // http://www.sbs.com.au/api/video_feed/smil?context=android&form=xml&id=517455939941 - - // Basic YW5kcm9pZDliYTNmMTgzYmM1MjY5MzI4YTM1YTBlNmQzYmJmMGYwMmY5ZTFhZWE6YW5kcm9pZA== + private static final String VIDEO_URL = BuildConfig.VIDEO_URL; private static final String CACHE_PATH = "sbs-api"; + private static final Pattern ID_PATTERN = Pattern.compile("/(\\d+)$"); private int lastEntryCount = 0; @@ -54,8 +52,14 @@ Uri buildRelatedUrl(Map params) { return buildUrl(RELATED_URL, params); } - Uri buildVideoUrl(Map params) { - return buildUrl(SMIL_URL, params); + protected Uri createStreamUrl(String href) { + String id = getIdFromUrl(href); + if (id != null) { + Uri.Builder uri = Uri.parse(VIDEO_URL).buildUpon(); + uri.appendPath(id); + return uri.build(); + } + return null; } private Uri buildUrl(String path, Map params) { @@ -68,6 +72,14 @@ private Uri buildUrl(String path, Map params) { return uri.build(); } + String getIdFromUrl(String url) { + Matcher m = ID_PATTERN.matcher(url); + if (m.find()) { + return m.group(1); + } + return null; + } + protected int getLastEntryCount() { return lastEntryCount; } diff --git a/sbs/src/main/java/io/github/xwz/sbs/api/SBSAuthApi.java b/sbs/src/main/java/io/github/xwz/sbs/api/SBSAuthApi.java new file mode 100644 index 0000000..e6b0410 --- /dev/null +++ b/sbs/src/main/java/io/github/xwz/sbs/api/SBSAuthApi.java @@ -0,0 +1,114 @@ +package io.github.xwz.sbs.api; + +import android.content.Context; +import android.net.Uri; +import android.util.Log; + +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import io.github.xwz.sbs.content.ContentManager; + +public class SBSAuthApi extends SBSApiBase { + private static final String TAG = "SBSAuthApi"; + private final String id; + private static final Pattern SRC_PATTERN = Pattern.compile("