From 5ea22450c076e95aa14d3dc40235045b60665811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Thu, 13 May 2021 21:24:28 +0200 Subject: [PATCH] Use custom getUriProtocol function Gst.Uri.get_protocol function is very simple. It just splits string by ":" and return the first part. We can do the same in JS and by doing that we do not have to initialize GStreamer just to get this function. --- src/misc.js | 7 +++++++ src/player.js | 4 ++-- src/playlist.js | 5 +++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/misc.js b/src/misc.js index 9e389d4f..94e238a5 100644 --- a/src/misc.js +++ b/src/misc.js @@ -140,6 +140,13 @@ function getFileFromLocalUri(uri) return file; } +/* JS replacement of "Gst.Uri.get_protocol" */ +function getUriProtocol(uri) +{ + const arr = uri.split(':'); + return (arr.length > 1) ? arr[0] : null; +} + function encodeHTML(text) { return text.replace(/&/g, '&') diff --git a/src/player.js b/src/player.js index cceb5c6e..7a80b809 100644 --- a/src/player.js +++ b/src/player.js @@ -141,7 +141,7 @@ class ClapperPlayer extends GstClapper.Clapper { this.customVideoTitle = null; - if(Gst.Uri.get_protocol(uri) !== 'file') { + if(Misc.getUriProtocol(uri) !== 'file') { const [isYouTubeUri, videoId] = YouTube.checkYouTubeUri(uri); if(!isYouTubeUri) @@ -256,7 +256,7 @@ class ClapperPlayer extends GstClapper.Clapper /* Check local file existence */ if( - Gst.Uri.get_protocol(uri) === 'file' + Misc.getUriProtocol(uri) === 'file' && !Misc.getFileFromLocalUri(uri) ) return; diff --git a/src/playlist.js b/src/playlist.js index 626468dd..b0d80e39 100644 --- a/src/playlist.js +++ b/src/playlist.js @@ -1,5 +1,6 @@ -const { Gdk, GLib, GObject, Gst, Gtk, Pango } = imports.gi; +const { Gdk, GLib, GObject, Gtk, Pango } = imports.gi; const Debug = imports.src.debug; +const Misc = imports.src.misc; const { debug, warn } = Debug; @@ -245,7 +246,7 @@ class ClapperPlaylistItem extends Gtk.ListBoxRow this.isLocalFile = false; let filename; - if(Gst.Uri.get_protocol(uri) === 'file') { + if(Misc.getUriProtocol(uri) === 'file') { filename = GLib.path_get_basename( GLib.filename_from_uri(uri)[0] );