[vlc-devel] [PATCH 12/15] http: add utils

David Loiret loiret.d at gmail.com
Tue Jun 23 14:42:47 CEST 2020


---
 share/Makefile.am                            |  4 +++
 share/lua/http/src/utils/filters/duration.js |  8 +++++
 share/lua/http/src/utils/lang/index.js       |  8 +++++
 share/lua/http/src/utils/media/types.js      | 37 ++++++++++++++++++++
 share/lua/http/src/utils/time/index.js       | 19 ++++++++++
 5 files changed, 76 insertions(+)
 create mode 100644 share/lua/http/src/utils/filters/duration.js
 create mode 100644 share/lua/http/src/utils/lang/index.js
 create mode 100644 share/lua/http/src/utils/media/types.js
 create mode 100644 share/lua/http/src/utils/time/index.js

diff --git a/share/Makefile.am b/share/Makefile.am
index 39455eff05..a7112f330c 100644
--- a/share/Makefile.am
+++ b/share/Makefile.am
@@ -4,6 +4,10 @@ MOSTLYCLEANFILES =
 EXTRA_DIST =
 
 JS_TARGETS = --js $(srcdir)/lua/http/src/services/initialize.service.js \
+--js $(srcdir)/lua/http/src/utils/lang/index.js \
+--js $(srcdir)/lua/http/src/utils/media/types.js \
+--js $(srcdir)/lua/http/src/utils/time/index.js \
+--js $(srcdir)/lua/http/src/utils/filters/duration.js \
 --js $(srcdir)/lua/http/src/components/playlist/playlist.component.js \
 --js $(srcdir)/lua/http/src/components/playlist/buttons.playlist.component.js \
 --js $(srcdir)/lua/http/src/components/vlm/vlm.component.js \
diff --git a/share/lua/http/src/utils/filters/duration.js b/share/lua/http/src/utils/filters/duration.js
new file mode 100644
index 0000000000..15055bfc00
--- /dev/null
+++ b/share/lua/http/src/utils/filters/duration.js
@@ -0,0 +1,8 @@
+import timeUtils from '../time/index.js';
+
+Vue.filter('formatDuration', (value) => {
+    if (!value) {
+        return '';
+    }
+    return timeUtils.formatTime(value / 1000);
+});
diff --git a/share/lua/http/src/utils/lang/index.js b/share/lua/http/src/utils/lang/index.js
new file mode 100644
index 0000000000..9cc8ce0295
--- /dev/null
+++ b/share/lua/http/src/utils/lang/index.js
@@ -0,0 +1,8 @@
+export default {
+    isBlank(obj) {
+        return obj === undefined || obj === null;
+    },
+    isPresent(obj) {
+        return !this.isBlank(obj);
+    }
+};
diff --git a/share/lua/http/src/utils/media/types.js b/share/lua/http/src/utils/media/types.js
new file mode 100644
index 0000000000..ac6a86e040
--- /dev/null
+++ b/share/lua/http/src/utils/media/types.js
@@ -0,0 +1,37 @@
+export const VIDEO_TYPES = [
+    'asf', 'avi', 'bik', 'bin', 'divx', 'drc', 'dv', 'f4v', 'flv', 'gxf', 'iso',
+    'm1v', 'm2v', 'm2t', 'm2ts', 'm4v', 'mkv', 'mov',
+    'mp2', 'mp4', 'mpeg', 'mpeg1',
+    'mpeg2', 'mpeg4', 'mpg', 'mts', 'mtv', 'mxf', 'mxg', 'nuv',
+    'ogg', 'ogm', 'ogv', 'ogx', 'ps',
+    'rec', 'rm', 'rmvb', 'rpl', 'thp', 'ts', 'txd', 'vob', 'wmv', 'xesc'
+];
+
+export const AUDIO_TYPES = [
+    '3ga', 'a52', 'aac', 'ac3', 'ape', 'awb', 'dts', 'flac', 'it',
+    'm4a', 'm4p', 'mka', 'mlp', 'mod', 'mp1', 'mp2', 'mp3',
+    'oga', 'ogg', 'oma', 's3m', 'spx', 'thd', 'tta',
+    'wav', 'wma', 'wv', 'xm'
+];
+
+export const PLAYLIST_TYPES = [
+    'asx', 'b4s', 'cue', 'ifo', 'm3u', 'm3u8', 'pls', 'ram', 'rar',
+    'sdp', 'vlc', 'xspf', 'zip', 'conf'
+];
+
+export const guessTypeFromUri = (uri) => {
+    if (!uri) {
+        return;
+    }
+    const ext = uri.split('.').pop();
+    if (!ext) {
+        return;
+    }
+    if (VIDEO_TYPES.includes(ext)) {
+        return 'video';
+    } else if (AUDIO_TYPES.includes(ext)) {
+        return 'audio';
+    } else if (PLAYLIST_TYPES.includes(ext)) {
+        return 'playlist';
+    }
+}
diff --git a/share/lua/http/src/utils/time/index.js b/share/lua/http/src/utils/time/index.js
new file mode 100644
index 0000000000..eab6946acd
--- /dev/null
+++ b/share/lua/http/src/utils/time/index.js
@@ -0,0 +1,19 @@
+export default {
+    formatTime(seconds) {
+        const date = new Date(seconds * 1000);
+        let hh = date.getUTCHours();
+        let mm = date.getUTCMinutes();
+        let ss = date.getSeconds();
+        if (hh < 10) {
+            hh = `0${hh}`;
+        }
+        if (mm < 10) {
+            mm = `0${mm}`;
+        }
+        if (ss < 10) {
+            ss = `0${ss}`;
+        }
+        const t = `${hh !== '00' ? hh + ':' : ''}${mm}:${ss}`;
+        return t;
+    }
+}
-- 
2.18.0



More information about the vlc-devel mailing list