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.
This commit is contained in:
Rafał Dzięgiel
2021-05-13 21:24:28 +02:00
parent 6ae38327ca
commit 5ea22450c0
3 changed files with 12 additions and 4 deletions

View File

@@ -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, '&')

View File

@@ -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;

View File

@@ -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]
);