aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/players/Streamable.hx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/players/Streamable.hx')
-rw-r--r--src/client/players/Streamable.hx66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/client/players/Streamable.hx b/src/client/players/Streamable.hx
new file mode 100644
index 0000000..21ef0f0
--- /dev/null
+++ b/src/client/players/Streamable.hx
@@ -0,0 +1,66 @@
+package client.players;
+
+import Types.VideoData;
+import Types.VideoDataRequest;
+import haxe.DynamicAccess;
+import haxe.Http;
+import haxe.Json;
+
+class Streamable extends Raw {
+ final matchStreamable = ~/streamable\.com\/(.+)/g;
+ final matchBadStreamableId = ~/[^0-9A-z-_]/g;
+
+ override function isSupportedLink(url:String):Bool {
+ if (!matchStreamable.match(url)) return false;
+ final id = matchStreamable.matched(1);
+ if (matchBadStreamableId.match(id)) return false;
+ return true;
+ }
+
+ override function getVideoData(data:VideoDataRequest, callback:(data:VideoData) -> Void) {
+ getStreamableVideoData(data.url, info -> {
+ if (info == null) {
+ callback({duration: 0});
+ return;
+ }
+
+ getRawVideoData({url: info.url, atEnd: data.atEnd}, data -> {
+ // set new url instead of using input one to load video
+ data.url = info.url;
+ data.title = info.title;
+ callback(data);
+ });
+ });
+ }
+
+ function getRawVideoData(data:VideoDataRequest, callback:(data:VideoData) -> Void):Void {
+ super.getVideoData(data, callback);
+ }
+
+ function getStreamableVideoData(url:String, callback:(info:Null<{url:String, title:String}>) -> Void):Void {
+ if (!matchStreamable.match(url)) {
+ callback(null);
+ return;
+ }
+ final id = matchStreamable.matched(1);
+ final http = new Http('https://api.streamable.com/videos/$id');
+ http.onData = text -> {
+ try {
+ final json:{title:String, ?files:DynamicAccess<Dynamic>} = Json.parse(text);
+ final files = json?.files;
+ var item = files["mp4"];
+ if (item == null) {
+ final key = files.keys()[0];
+ item = files[key];
+ }
+ callback({
+ url: item.url,
+ title: json.title
+ });
+ } catch (e) {
+ callback(null);
+ }
+ }
+ http.request();
+ }
+}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage