Skip to content

Commit

Permalink
Streamable support
Browse files Browse the repository at this point in the history
closes #49
  • Loading branch information
RblSb committed Aug 2, 2024
1 parent 4df711e commit 7ee893a
Show file tree
Hide file tree
Showing 21 changed files with 187 additions and 94 deletions.
84 changes: 42 additions & 42 deletions build/server.js

Large diffs are not rendered by default.

75 changes: 66 additions & 9 deletions res/client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/Lang.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package;

import haxe.Json;
import haxe.io.Path;

using Lambda;

#if (sys || nodejs)
import sys.io.File;
#else
Expand Down
2 changes: 0 additions & 2 deletions src/PathTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package;

import haxe.io.Path;

using StringTools;

class PathTools {
public static function urlExtension(url:String) {
return Path.extension(~/[#?]/.split(url)[0]).trim().toLowerCase();
Expand Down
14 changes: 7 additions & 7 deletions src/Types.hx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import Client.ClientData;
import utils.YoutubeUtils.YouTubeVideoInfo;

typedef VideoDataRequest = {
url:String,
atEnd:Bool
final url:String;
final atEnd:Bool;
}

typedef VideoData = {
duration:Float,
?title:String,
?url:String,
?subs:String,
?isIframe:Bool
final duration:Float;
var ?title:String;
var ?url:String;
var ?subs:String;
var ?isIframe:Bool;
}

typedef Config = {
Expand Down
2 changes: 0 additions & 2 deletions src/VideoList.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package;

import Types.VideoItem;

using Lambda;

class VideoList {
public var length(get, never):Int;
public var pos(default, null) = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/client/Buttons.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import js.html.InputElement;
import js.html.KeyboardEvent;
import js.html.VisualViewport;

using StringTools;

class Buttons {
static inline var CHAT_MIN_SIZE = 200;
static var split:Split;
Expand Down
2 changes: 0 additions & 2 deletions src/client/JsApi.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import js.Browser.document;
import js.Browser.window;
import js.Syntax;

using StringTools;

private typedef VideoChangeFunc = (item:VideoItem) -> Void;
private typedef OnceEventFunc = (event:WsEvent) -> Void;

Expand Down
1 change: 0 additions & 1 deletion src/client/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import js.html.VideoElement;
import js.html.WebSocket;

using ClientTools;
using StringTools;

class Main {
static inline var SETTINGS_VERSION = 4;
Expand Down
7 changes: 3 additions & 4 deletions src/client/Player.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import Types.VideoItem;
import client.Main.ge;
import client.players.Iframe;
import client.players.Raw;
import client.players.Streamable;
import client.players.Youtube;
import haxe.Http;
import haxe.Json;
import js.html.Element;

using Lambda;
using StringTools;

class Player {
final main:Main;
final youtube:Youtube;
Expand All @@ -32,7 +30,8 @@ class Player {
this.main = main;
youtube = new Youtube(main, this);
players = [
youtube
youtube,
new Streamable(main, this)
];
iframePlayer = new Iframe(main, this);
rawPlayer = new Raw(main, this);
Expand Down
2 changes: 0 additions & 2 deletions src/client/players/Raw.hx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import js.html.InputElement;
import js.html.URL;
import js.html.VideoElement;

using StringTools;

class Raw implements IPlayer {
final main:Main;
final player:Player;
Expand Down
2 changes: 0 additions & 2 deletions src/client/players/RawSubs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import js.Browser.window;
import js.Browser;
import js.html.VideoElement;

using StringTools;

private typedef Duration = {
h:Int,
m:Int,
Expand Down
66 changes: 66 additions & 0 deletions src/client/players/Streamable.hx
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 1 addition & 3 deletions src/client/players/Youtube.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import js.youtube.Youtube as YtInit;
import js.youtube.YoutubePlayer;
import utils.YoutubeUtils;

using StringTools;

class Youtube implements IPlayer {
final videosUrl = "https://www.googleapis.com/youtube/v3/videos";
final playlistUrl = "https://www.googleapis.com/youtube/v3/playlistItems";
Expand Down Expand Up @@ -133,7 +131,7 @@ class Youtube implements IPlayer {
function loadNextItem():Void {
final item = items.shift();
final id:String = item.snippet.resourceId.videoId;
final obj = {
final obj:VideoDataRequest = {
url: 'https://youtu.be/$id',
atEnd: data.atEnd
};
Expand Down
2 changes: 2 additions & 0 deletions src/import.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
using Lambda;
using StringTools;
2 changes: 0 additions & 2 deletions src/server/ConsoleInput.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import js.node.Readline;
import sys.FileSystem;
import sys.io.File;

using StringTools;

private typedef CommandData = {
args:Array<String>,
desc:String
Expand Down
2 changes: 0 additions & 2 deletions src/server/HttpServer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import js.node.http.ServerResponse;
import js.node.url.URL;
import sys.FileSystem;

using StringTools;

class HttpServer {
static final mimeTypes = [
"html" => "text/html",
Expand Down
3 changes: 0 additions & 3 deletions src/server/Logger.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import haxe.io.Path;
import sys.FileSystem;
import sys.io.File;

using Lambda;
using StringTools;

class Logger {
final folder:String;
final maxCount:Int;
Expand Down
2 changes: 0 additions & 2 deletions src/server/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import sys.FileSystem;
import sys.io.File;

using ClientTools;
using Lambda;
using StringTools;

private typedef MainOptions = {
loadState:Bool
Expand Down
2 changes: 0 additions & 2 deletions src/server/Utils.hx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import js.node.Os;
import js.node.url.URL;
import sys.FileSystem;

using StringTools;

class Utils {
public static function parseArgs(args:Array<String>, caseSensitive = true):Map<String,
String> {
Expand Down
2 changes: 0 additions & 2 deletions src/server/YoutubeFallback.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import js.node.Https.HttpsRequestOptions;
import js.node.url.URLSearchParams;
import utils.YoutubeUtils;

using Lambda;

class YoutubeFallback {
static function httpsGet(
url:String,
Expand Down

0 comments on commit 7ee893a

Please sign in to comment.