From d443fc74bf6fc4468ec245e9ba6b401e4824a5c8 Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Wed, 19 May 2021 08:55:20 +0200 Subject: [PATCH] add title to chromecast --- app/app/build.gradle | 4 +-- app/app/src/main/AndroidManifest.xml | 6 ----- .../java/it/purser/stream/MainActivity.java | 12 --------- .../java/it/purser/stream/ShareActivity.java | 2 -- app/app/src/main/res/layout/activity_main.xml | 8 ------ frontend/script.js | 4 +++ stream.py | 25 ++++++++++++++++--- 7 files changed, 28 insertions(+), 33 deletions(-) delete mode 100644 app/app/src/main/java/it/purser/stream/MainActivity.java delete mode 100644 app/app/src/main/res/layout/activity_main.xml diff --git a/app/app/build.gradle b/app/app/build.gradle index aff3fed..eea89dc 100644 --- a/app/app/build.gradle +++ b/app/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "it.purser.stream" minSdkVersion 25 targetSdkVersion 29 - versionCode 103 - versionName "103.0" + versionCode 104 + versionName "104.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/app/src/main/AndroidManifest.xml b/app/app/src/main/AndroidManifest.xml index 108e6b4..a5ade38 100644 --- a/app/app/src/main/AndroidManifest.xml +++ b/app/app/src/main/AndroidManifest.xml @@ -8,12 +8,6 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.ProxyStream"> - - - - - - diff --git a/app/app/src/main/java/it/purser/stream/MainActivity.java b/app/app/src/main/java/it/purser/stream/MainActivity.java deleted file mode 100644 index 7ad1449..0000000 --- a/app/app/src/main/java/it/purser/stream/MainActivity.java +++ /dev/null @@ -1,12 +0,0 @@ -package it.purser.stream; - -import android.app.Activity; -import android.os.Bundle; - -public class MainActivity extends Activity { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - } -} \ No newline at end of file diff --git a/app/app/src/main/java/it/purser/stream/ShareActivity.java b/app/app/src/main/java/it/purser/stream/ShareActivity.java index a5a152e..7008d4b 100644 --- a/app/app/src/main/java/it/purser/stream/ShareActivity.java +++ b/app/app/src/main/java/it/purser/stream/ShareActivity.java @@ -29,7 +29,6 @@ public class ShareActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); Uri uri = getSharedLink(); if(uri != null) { Uri.Builder builder = new Uri.Builder(); @@ -38,7 +37,6 @@ public class ShareActivity extends Activity { builder.path(uri.getPath()); builder.appendQueryParameter("provider", "youtube"); builder.appendQueryParameter("render", "true"); - builder.appendQueryParameter("cast", "true"); Intent launch = new Intent(Intent.ACTION_VIEW, builder.build()); launch.setPackage("com.android.chrome"); launch.putExtra("android.support.customtabs.extra.SESSION", "Proxy Stream"); diff --git a/app/app/src/main/res/layout/activity_main.xml b/app/app/src/main/res/layout/activity_main.xml deleted file mode 100644 index f9f6f0b..0000000 --- a/app/app/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - \ No newline at end of file diff --git a/frontend/script.js b/frontend/script.js index 544df98..c67452c 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -28,6 +28,10 @@ options.techOrder = ["chromecast", "html5"]; options.plugins = {}; options.plugins.chromecast = {}; + player.plugins.chromecast.requestTitleFn = (src) => { + return "{{ title }}"; + } + let player = videojs(video, options); let source = {}; source.type = ctype; diff --git a/stream.py b/stream.py index 7f5f922..d81822c 100755 --- a/stream.py +++ b/stream.py @@ -131,7 +131,7 @@ class UpstreamHandler(): self.upstream = None self.upstream_safe = None self.render = False - self.stream = True + self.stream = False async def setup(self, handler): self.provider = handler.get_query_argument("provider", None) render_str = handler.get_query_argument("render", "false") @@ -142,6 +142,7 @@ class UpstreamHandler(): self.render = True else: self.stream = True + path = handler.request.path if self.provider == "youtube": path = path.strip("/") @@ -213,6 +214,7 @@ class UpstreamHandler(): data = list(data_new.items()) except Exception as e: logger.info(e) + logger.info(data) return data if icecast_server is not None and stream_server is not None: @@ -324,10 +326,27 @@ class MainHandler(tornado.web.RequestHandler): async def handle_render(self, handler): if template_js is not None and template_html is not None: - rendered_js = template_js.generate(stream=handler.stream_url); + meta = await handler.meta() + title = handler.render_url + video_creator = None + video_title = None + for elem in meta: + if isinstance(elem[1], str): + if elem[0] == "og:title": + video_title = elem[1] + elif elem[0] == "og:description": + video_creator = elem[1] + + if isinstance(video_creator, str) and isinstance(video_title, str): + title = f'{video_creator}: {video_title}' + elif isinstance(video_creator, str): + title = video_creator + elif isinstance(video_title, str): + title = video_title + + rendered_js = template_js.generate(stream=handler.stream_url, title=title); b64_js = str(base64.b64encode(rendered_js), "ascii") script = f'data:text/javascript;charset=utf-8;base64,{b64_js}' - meta = await handler.meta() data["script"] = script data["videojs_version"] = videojs_version data["chromecast_version"] = chromecast_version