From 1978a9e8376e30508c716f7e9d4d6f04339639c4 Mon Sep 17 00:00:00 2001 From: vexorian Date: Sun, 24 Jan 2021 21:33:30 -0400 Subject: [PATCH] #106 Allow group-title customization in channels. --- src/api.js | 7 +++++ src/database-migration.js | 29 ++++++++++++++++++-- src/services/m3u-service.js | 2 +- web/directives/channel-config.js | 9 ++++++ web/public/templates/channel-config.html | 35 ++++++++++++++++-------- 5 files changed, 68 insertions(+), 14 deletions(-) diff --git a/src/api.js b/src/api.js index 4f46328..5ab4a41 100644 --- a/src/api.js +++ b/src/api.js @@ -627,6 +627,13 @@ function api(db, channelDB, fillerDB, xmltvInterval, guideService, _m3uService } function cleanUpChannel(channel) { + if ( + (typeof(channel.groupTitle) === 'undefined') + || + (channel.groupTitle === '') + ) { + channel.groupTitle = "dizqueTV"; + } channel.programs.forEach( cleanUpProgram ); delete channel.fillerContent; delete channel.filler; diff --git a/src/database-migration.js b/src/database-migration.js index 2634fd5..4cf6321 100644 --- a/src/database-migration.js +++ b/src/database-migration.js @@ -20,7 +20,7 @@ const path = require('path'); var fs = require('fs'); -const TARGET_VERSION = 801; +const TARGET_VERSION = 802; const STEPS = [ // [v, v2, x] : if the current version is v, call x(db), and version becomes v2 @@ -41,6 +41,7 @@ const STEPS = [ // but we have to migrate it to 800 using the reAddIcon. [ 702, 800, (db,channels,dir) => reAddIcon(dir) ], [ 800, 801, (db) => addImageCache(db) ], + [ 801, 802, () => addGroupTitle() ], ] const { v4: uuidv4 } = require('uuid'); @@ -741,7 +742,7 @@ function migrateWatermark(db, channelDB) { return channel; } - console.log("Extracting fillers from channels..."); + console.log("Migrating watermarks..."); let channels = path.join(process.env.DATABASE, 'channels'); let channelFiles = fs.readdirSync(channels); for (let i = 0; i < channelFiles.length; i++) { @@ -811,6 +812,30 @@ function addImageCache(db) { fs.writeFileSync( f, JSON.stringify( [xmltvSettings] ) ); } +function addGroupTitle() { + + function migrateChannel(channel) { + channel.groupTitle= "dizqueTV"; + return channel; + } + + console.log("Adding group title to channels..."); + let channels = path.join(process.env.DATABASE, 'channels'); + let channelFiles = fs.readdirSync(channels); + for (let i = 0; i < channelFiles.length; i++) { + if (path.extname( channelFiles[i] ) === '.json') { + console.log("Adding group title to channel : " + channelFiles[i] +"..." ); + let channelPath = path.join(channels, channelFiles[i]); + let channel = JSON.parse(fs.readFileSync(channelPath, 'utf-8')); + channel = migrateChannel(channel); + fs.writeFileSync( channelPath, JSON.stringify(channel), 'utf-8'); + } + } + console.log("Done migrating group titles in channels."); +} + + + module.exports = { initDB: initDB, diff --git a/src/services/m3u-service.js b/src/services/m3u-service.js index 674e200..f3563b5 100644 --- a/src/services/m3u-service.js +++ b/src/services/m3u-service.js @@ -50,7 +50,7 @@ class M3uService { for (var i = 0; i < channels.length; i++) { if (channels[i].stealth !== true) { - data += `#EXTINF:0 tvg-id="${channels[i].number}" CUID="${channels[i].number}" tvg-chno="${channels[i].number}" tvg-name="${channels[i].name}" tvg-logo="${channels[i].icon}" group-title="dizqueTV",${channels[i].name}\n` + data += `#EXTINF:0 tvg-id="${channels[i].number}" CUID="${channels[i].number}" tvg-chno="${channels[i].number}" tvg-name="${channels[i].name}" tvg-logo="${channels[i].icon}" group-title="${channels[i].groupTitle}",${channels[i].name}\n` data += `{{host}}/video?channel=${channels[i].number}\n` } } diff --git a/web/directives/channel-config.js b/web/directives/channel-config.js index df76d16..fd45176 100644 --- a/web/directives/channel-config.js +++ b/web/directives/channel-config.js @@ -60,6 +60,7 @@ module.exports = function ($timeout, $location, dizquetv, resolutionOptions) { scope.channel.guideMinimumDurationSeconds = 5 * 60; scope.isNewChannel = true scope.channel.icon = `${$location.protocol()}://${location.host}/images/dizquetv.png` + scope.channel.groupTitle = "dizqueTV"; scope.channel.disableFillerOverlay = true; scope.channel.iconWidth = 120 scope.channel.iconDuration = 60 @@ -95,6 +96,14 @@ module.exports = function ($timeout, $location, dizquetv, resolutionOptions) { scope.channel.watermark = defaultWatermark(); } + if ( + (typeof(scope.channel.groupTitle) === 'undefined') + || + (scope.channel.groupTitle === '') + ) { + scope.channel.groupTitle = "dizqueTV"; + } + if (typeof(scope.channel.fillerRepeatCooldown) === 'undefined') { scope.channel.fillerRepeatCooldown = 30 * 60 * 1000; } diff --git a/web/public/templates/channel-config.html b/web/public/templates/channel-config.html index 506265a..53606da 100644 --- a/web/public/templates/channel-config.html +++ b/web/public/templates/channel-config.html @@ -21,16 +21,28 @@