From 2d4353aaec015775a1c6342cdfe052ef5e1dde8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Wed, 2 Jun 2021 15:47:09 +0200 Subject: [PATCH] Append some common subtitle track titles In order to not end up with multiple subitle tracks simply named for e.g. "English", add some common postfix to it when detected in track title. --- src/misc.js | 21 +++++++++++++++++++++ src/widget.js | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/misc.js b/src/misc.js index b3ab2c96..069f3082 100644 --- a/src/misc.js +++ b/src/misc.js @@ -19,6 +19,16 @@ var settings = new Gio.Settings({ var maxVolume = 1.5; +/* Keys must be lowercase */ +const subsTitles = { + sdh: 'SDH', + cc: 'CC', + traditional: 'Traditional', + simplified: 'Simplified', + honorifics: 'Honorifics', +}; +const subsKeys = Object.keys(subsTitles); + let inhibitCookie; function getClapperPath() @@ -90,6 +100,17 @@ function getClapperThemeIconUri() return iconUri; } +function getSubsTitle(infoTitle) +{ + if(!infoTitle) + return null; + + const searchName = infoTitle.toLowerCase(); + const found = subsKeys.find(key => key === searchName); + + return (found) ? subsTitles[found] : null; +} + function loadCustomCss() { const clapperPath = getClapperPath(); diff --git a/src/widget.js b/src/widget.js index 6cbc1dd0..c737926f 100644 --- a/src/widget.js +++ b/src/widget.js @@ -231,7 +231,11 @@ class ClapperWidget extends Gtk.Grid break; case GstClapper.ClapperSubtitleInfo: type = 'subtitle'; - text = info.get_language() || 'Undetermined'; + const subsLang = info.get_language(); + text = (subsLang) ? subsLang.split(',')[0] : 'Undetermined'; + const subsTitle = Misc.getSubsTitle(info.get_title()); + if(subsTitle) + text += ', ' + subsTitle; break; default: debug(`unrecognized media info type: ${info.constructor}`);