Skip to content

Commit

Permalink
interpolate special substrings in POST to HTTP endpoint: "/show-toast"
Browse files Browse the repository at this point in the history
summary:
* "{{video-uri}}"
  - video URI
  - ex: "http://example.com/video.mp4"
* "{{video-caption}}"
  - caption URI
  - ex: "http://example.com/video.srt"
* "{{video-req-headers}}"
  - video HTTP headers
  - ex: "Referer:    http://example.com/videos.html
         Origin:     http://example.com
         User-Agent: Chrome/90"
* "{{video-drm-scheme}}"
  - DRM scheme
  - ex: "widevine"
* "{{video-drm-server}}"
  - DRM license server URL
  - ex: "http://widevine.example.com/"
* "{{video-drm-headers}}"
  - DRM HTTP headers
  - ex: "Authorization: Bearer <TOKEN>
         Cookie:        token=<TOKEN>
         User-Agent:    Chrome/90"
  • Loading branch information
warren-bank committed Oct 22, 2021
1 parent 1f0a171 commit 2b0ff4d
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void handleMessage(Message msg) {
case Constant.Msg.Msg_Show_Toast : {
String text;
text = (String) msg.obj;
text = ToastUtils.interpolate_variables(service.getApplicationContext(), text);
text = ToastUtils.interpolate_variables(service.getApplicationContext(), playerManager, text);

if (!TextUtils.isEmpty(text)) {
Toast.makeText(service.getApplicationContext(), text, Toast.LENGTH_LONG).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,18 @@ public static String encodeURL(URL url) {
}
}

public static String toString(HashMap<String, String> map) {
if (map == null) return null;

String value = "";
for (String key : map.keySet()) {
value += key + ": " + map.get(key) + "\n";
}

value = value.trim();
value = (value == "") ? null : value;

return value;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.github.warren_bank.exoplayer_airplay_receiver.BuildConfig;
import com.github.warren_bank.exoplayer_airplay_receiver.R;
import com.github.warren_bank.exoplayer_airplay_receiver.exoplayer2.PlayerManager;
import com.github.warren_bank.exoplayer_airplay_receiver.exoplayer2.VideoSource;

import android.app.ActivityManager;
import android.content.Context;
Expand All @@ -13,9 +15,18 @@

public class ToastUtils {

public static String interpolate_variables(Context context, String text) {
public static String interpolate_variables(Context context, PlayerManager playerManager, String text) {
if (TextUtils.isEmpty(text)) return null;

if (playerManager != null) {
text = ToastUtils.interpolate_video_uri(context, playerManager, text);
text = ToastUtils.interpolate_video_caption(context, playerManager, text);
text = ToastUtils.interpolate_video_req_headers(context, playerManager, text);
text = ToastUtils.interpolate_video_drm_scheme(context, playerManager, text);
text = ToastUtils.interpolate_video_drm_server(context, playerManager, text);
text = ToastUtils.interpolate_video_drm_headers(context, playerManager, text);
}

text = ToastUtils.interpolate_date(context, text);
text = ToastUtils.interpolate_time(context, text);
text = ToastUtils.interpolate_version(context, text);
Expand All @@ -28,6 +39,128 @@ public static String interpolate_variables(Context context, String text) {
return text;
}

private static VideoSource getVideoSource(PlayerManager playerManager) {
if (playerManager == null) return null;

return playerManager.getItem(
playerManager.getCurrentItemIndex()
);
}

private static String interpolate_video_uri(Context context, PlayerManager playerManager, String text) {
if (TextUtils.isEmpty(text)) return null;

String variable_substring = context.getString(R.string.toast_variable_video_uri);

if (!text.contains(variable_substring))
return text;

try {
VideoSource sample = getVideoSource(playerManager);
String video_uri = (sample == null) ? null : sample.uri;

return ToastUtils.interpolate_variable(text, variable_substring, video_uri);
}
catch(Exception e) {
return ToastUtils.interpolate_variable(text, variable_substring, "");
}
}

private static String interpolate_video_caption(Context context, PlayerManager playerManager, String text) {
if (TextUtils.isEmpty(text)) return null;

String variable_substring = context.getString(R.string.toast_variable_video_caption);

if (!text.contains(variable_substring))
return text;

try {
VideoSource sample = getVideoSource(playerManager);
String video_caption = (sample == null) ? null : sample.caption;

return ToastUtils.interpolate_variable(text, variable_substring, video_caption);
}
catch(Exception e) {
return ToastUtils.interpolate_variable(text, variable_substring, "");
}
}

private static String interpolate_video_req_headers(Context context, PlayerManager playerManager, String text) {
if (TextUtils.isEmpty(text)) return null;

String variable_substring = context.getString(R.string.toast_variable_video_req_headers);

if (!text.contains(variable_substring))
return text;

try {
VideoSource sample = getVideoSource(playerManager);
String video_req_headers = (sample == null) ? null : StringUtils.toString(sample.reqHeadersMap);

return ToastUtils.interpolate_variable(text, variable_substring, video_req_headers);
}
catch(Exception e) {
return ToastUtils.interpolate_variable(text, variable_substring, "");
}
}

private static String interpolate_video_drm_scheme(Context context, PlayerManager playerManager, String text) {
if (TextUtils.isEmpty(text)) return null;

String variable_substring = context.getString(R.string.toast_variable_video_drm_scheme);

if (!text.contains(variable_substring))
return text;

try {
VideoSource sample = getVideoSource(playerManager);
String video_drm_scheme = (sample == null) ? null : sample.drm_scheme;

return ToastUtils.interpolate_variable(text, variable_substring, video_drm_scheme);
}
catch(Exception e) {
return ToastUtils.interpolate_variable(text, variable_substring, "");
}
}

private static String interpolate_video_drm_server(Context context, PlayerManager playerManager, String text) {
if (TextUtils.isEmpty(text)) return null;

String variable_substring = context.getString(R.string.toast_variable_video_drm_server);

if (!text.contains(variable_substring))
return text;

try {
VideoSource sample = getVideoSource(playerManager);
String video_drm_server = (sample == null) ? null : sample.drm_license_server;

return ToastUtils.interpolate_variable(text, variable_substring, video_drm_server);
}
catch(Exception e) {
return ToastUtils.interpolate_variable(text, variable_substring, "");
}
}

private static String interpolate_video_drm_headers(Context context, PlayerManager playerManager, String text) {
if (TextUtils.isEmpty(text)) return null;

String variable_substring = context.getString(R.string.toast_variable_video_drm_headers);

if (!text.contains(variable_substring))
return text;

try {
VideoSource sample = getVideoSource(playerManager);
String video_drm_headers = (sample == null) ? null : StringUtils.toString(sample.drmHeadersMap);

return ToastUtils.interpolate_variable(text, variable_substring, video_drm_headers);
}
catch(Exception e) {
return ToastUtils.interpolate_variable(text, variable_substring, "");
}
}

private static String interpolate_date(Context context, String text) {
if (TextUtils.isEmpty(text)) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<string name="toast_registration_failure">AirPlay registration failed</string>

<!-- strings that are interpolated within "/show-toast" text -->
<string translatable="false" name="toast_variable_video_uri">{{video-uri}}</string>
<string translatable="false" name="toast_variable_video_caption">{{video-caption}}</string>
<string translatable="false" name="toast_variable_video_req_headers">{{video-req-headers}}</string>
<string translatable="false" name="toast_variable_video_drm_scheme">{{video-drm-scheme}}</string>
<string translatable="false" name="toast_variable_video_drm_server">{{video-drm-server}}</string>
<string translatable="false" name="toast_variable_video_drm_headers">{{video-drm-headers}}</string>
<string translatable="false" name="toast_variable_date">{{date}}</string>
<string translatable="false" name="toast_variable_time">{{time}}</string>
<string translatable="false" name="toast_variable_version">{{version}}</string>
Expand Down
4 changes: 2 additions & 2 deletions android-studio-project/constants.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project.ext {
releaseVersionCode = Integer.parseInt("002003416", 10) //Integer.MAX_VALUE == 2147483647
releaseVersion = '002.00.34-16API'
releaseVersionCode = Integer.parseInt("002003516", 10) //Integer.MAX_VALUE == 2147483647
releaseVersion = '002.00.35-16API'
javaVersion = JavaVersion.VERSION_1_8
minSdkVersion = 16
targetSdkVersion = 29
Expand Down
10 changes: 8 additions & 2 deletions tests/02. AirPlay sender.es5.html
Original file line number Diff line number Diff line change
Expand Up @@ -1211,10 +1211,16 @@ <h3>User Interface:</h3>
<div>
<select id="toast_variables">
<option value="">Add Variable:</option>
<option value="{{video-uri}}">Video URI</option>
<option value="{{video-caption}}">Caption URI</option>
<option value="{{video-req-headers}}">Video HTTP Headers</option>
<option value="{{video-drm-scheme}}">DRM Scheme</option>
<option value="{{video-drm-server}}">DRM License Server URL</option>
<option value="{{video-drm-headers}}">DRM HTTP Headers</option>
<option value="{{date}}">Date</option>
<option value="{{time}}">Time</option>
<option value="{{version}}">Version of ExoAirPlayer</option>
<option value="{{abi}}">List of ABIs Supported by Device</option>
<option value="{{version}}">ExoAirPlayer Version</option>
<option value="{{abi}}">ABIs Supported by Device</option>
<option value="{{top-process}}">Package Name of Top Process</option>
<option value="{{top-activity}}">Class Name of Top Activity</option>
</select>
Expand Down
10 changes: 8 additions & 2 deletions tests/02. AirPlay sender.html
Original file line number Diff line number Diff line change
Expand Up @@ -1425,10 +1425,16 @@ <h3>User Interface:</h3>
<div>
<select id="toast_variables">
<option value="">Add Variable:</option>
<option value="{{video-uri}}">Video URI</option>
<option value="{{video-caption}}">Caption URI</option>
<option value="{{video-req-headers}}">Video HTTP Headers</option>
<option value="{{video-drm-scheme}}">DRM Scheme</option>
<option value="{{video-drm-server}}">DRM License Server URL</option>
<option value="{{video-drm-headers}}">DRM HTTP Headers</option>
<option value="{{date}}">Date</option>
<option value="{{time}}">Time</option>
<option value="{{version}}">Version of ExoAirPlayer</option>
<option value="{{abi}}">List of ABIs Supported by Device</option>
<option value="{{version}}">ExoAirPlayer Version</option>
<option value="{{abi}}">ABIs Supported by Device</option>
<option value="{{top-process}}">Package Name of Top Process</option>
<option value="{{top-activity}}">Class Name of Top Activity</option>
</select>
Expand Down

0 comments on commit 2b0ff4d

Please sign in to comment.