Skip to content

Commit

Permalink
Merge pull request #227 from vexorian/20200110_main
Browse files Browse the repository at this point in the history
1.2.3
  • Loading branch information
vexorian authored Jan 10, 2021
2 parents f428dbe + d0ac96a commit 3661aa9
Show file tree
Hide file tree
Showing 27 changed files with 2,640 additions and 757 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# dizqueTV 1.1.4
# dizqueTV 1.2.3
![Discord](https://img.shields.io/discord/711313431457693727?logo=discord&logoColor=fff&style=flat-square) ![GitHub top language](https://img.shields.io/github/languages/top/vexorian/dizquetv?logo=github&style=flat-square) ![Docker Pulls](https://img.shields.io/docker/pulls/vexorian/dizquetv?logo=docker&logoColor=fff&style=flat-square)

Create live TV channel streams from media on your Plex servers.
Expand Down
29 changes: 28 additions & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const FFMPEGInfo = require('./ffmpeg-info');
const PlexServerDB = require('./dao/plex-server-db');
const Plex = require("./plex.js");
const FillerDB = require('./dao/filler-db');
const timeSlotsService = require('./services/time-slots-service');

module.exports = { router: api }
function api(db, channelDB, fillerDB, xmltvInterval, guideService ) {
Expand Down Expand Up @@ -303,6 +304,10 @@ function api(db, channelDB, fillerDB, xmltvInterval, guideService ) {
try {
db['ffmpeg-settings'].update({ _id: req.body._id }, req.body)
let ffmpeg = db['ffmpeg-settings'].find()[0]
let err = fixupFFMPEGSettings(ffmpeg);
if (typeof(err) !== 'undefined') {
return res.status(400).send(err);
}
res.send(ffmpeg)
} catch(err) {
console.error(err);
Expand All @@ -323,6 +328,14 @@ function api(db, channelDB, fillerDB, xmltvInterval, guideService ) {

})

function fixupFFMPEGSettings(ffmpeg) {
if (typeof(ffmpeg.maxFPS) === 'undefined') {
ffmpeg.maxFPS = 60;
} else if ( isNaN(ffmpeg.maxFPS) ) {
return "maxFPS should be a number";
}
}

// PLEX SETTINGS
router.get('/api/plex-settings', (req, res) => {
try {
Expand Down Expand Up @@ -528,6 +541,20 @@ function api(db, channelDB, fillerDB, xmltvInterval, guideService ) {

})

//tool services
router.post('/api/channel-tools/time-slots', async (req, res) => {
try {
let toolRes = await timeSlotsService(req.body.programs, req.body.schedule);
if ( typeof(toolRes.userError) !=='undefined') {
return res.status(400).send(toolRes.userError);
}
res.status(200).send(toolRes);
} catch(err) {
console.error(err);
res.status(500).send("Internal error");
}
});

// CHANNELS.M3U Download
router.get('/api/channels.m3u', async (req, res) => {
try {
Expand All @@ -538,7 +565,7 @@ function api(db, channelDB, fillerDB, xmltvInterval, guideService ) {
var data = `#EXTM3U url-tvg="${tvg}" x-tvg-url="${tvg}"\n`;
for (var i = 0; i < channels.length; i++) {
if (channels[i].stealth!==true) {
data += `#EXTINF:0 tvg-id="${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="dizqueTV",${channels[i].name}\n`
data += `${req.protocol}://${req.get('host')}/video?channel=${channels[i].number}\n`
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
SLACK: 9999,
TVGUIDE_MAXIMUM_PADDING_LENGTH_MS: 30*60*1000,
STEALTH_DURATION: 5 * 60* 1000,
DEFAULT_GUIDE_STEALTH_DURATION: 5 * 60* 1000,
TVGUIDE_MAXIMUM_FLEX_DURATION : 6 * 60 * 60 * 1000,
TOO_FREQUENT: 100,

VERSION_NAME: "1.1.4"
VERSION_NAME: "1.2.3"
}
96 changes: 95 additions & 1 deletion src/database-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
const path = require('path');
var fs = require('fs');

const TARGET_VERSION = 600;
const TARGET_VERSION = 701;

const STEPS = [
// [v, v2, x] : if the current version is v, call x(db), and version becomes v2
Expand All @@ -31,6 +31,9 @@ const STEPS = [
[ 400, 500, (db,channels) => splitServersSingleChannels(db, channels) ],
[ 500, 501, (db) => fixCorruptedServer(db) ],
[ 501, 600, () => extractFillersFromChannels() ],
[ 600, 601, (db) => addFPS(db) ],
[ 601, 700, (db) => migrateWatermark(db) ],
[ 700, 701, (db) => addScalingAlgorithm(db) ],
]

const { v4: uuidv4 } = require('uuid');
Expand Down Expand Up @@ -392,6 +395,8 @@ function ffmpeg() {
normalizeAudioCodec: true,
normalizeResolution: true,
normalizeAudio: true,
maxFPS: 60,
scalingAlgorithm: "bicubic",
}
}

Expand Down Expand Up @@ -662,6 +667,95 @@ function extractFillersFromChannels() {

}

function addFPS(db) {
let ffmpegSettings = db['ffmpeg-settings'].find()[0];
let f = path.join(process.env.DATABASE, 'ffmpeg-settings.json');
ffmpegSettings.maxFPS = 60;
fs.writeFileSync( f, JSON.stringify( [ffmpegSettings] ) );
}

function migrateWatermark(db, channelDB) {
let ffmpegSettings = db['ffmpeg-settings'].find()[0];
let w = 1920;
let h = 1080;

function parseResolutionString(s) {
var i = s.indexOf('x');
if (i == -1) {
i = s.indexOf("×");
if (i == -1) {
return {w:1920, h:1080}
}
}
return {
w: parseInt( s.substring(0,i) , 10 ),
h: parseInt( s.substring(i+1) , 10 ),
}
}

if (
(ffmpegSettings.targetResolution != null)
&& (typeof(ffmpegSettings.targetResolution) !== 'undefined')
&& (typeof(ffmpegSettings.targetResolution) !== '')
) {
let p = parseResolutionString( ffmpegSettings.targetResolution );
w = p.w;
h = p.h;
}
console.log(`Using ${w}x${h} as resolution to migrate new watermark settings.`);
function migrateChannel(channel) {
if (channel.overlayIcon === true) {
channel.watermark = {
enabled: true,
width: Math.max(0.001, Math.min(100, (channel.iconWidth*100) / w ) ),
verticalMargin: Math.max(0.000, Math.min(100, 2000 / h ) ),
horizontalMargin: Math.max(0.000, Math.min(100, 2000 / w ) ),
duration: channel.iconDuration,
fixedSize: false,
position: [
"top-left",
"top-right",
"bottom-left",
"bottom-right",
][ channel.iconPosition ],
url: '', //same as channel icon
animated: false,
}
} else {
channel.watermark = {
enabled: false,
}
}
delete channel.overlayIcon;
delete channel.iconDuration;
delete channel.iconPosition;
delete channel.iconWidth;
return channel;
}

console.log("Extracting fillers from 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("Migrating watermark in 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 watermarks in channels.");
}

function addScalingAlgorithm(db) {
let ffmpegSettings = db['ffmpeg-settings'].find()[0];
let f = path.join(process.env.DATABASE, 'ffmpeg-settings.json');
ffmpegSettings.scalingAlgorithm = "bicubic";
fs.writeFileSync( f, JSON.stringify( [ffmpegSettings] ) );
}


module.exports = {
initDB: initDB,
defaultFFMPEG: ffmpeg,
Expand Down
7 changes: 6 additions & 1 deletion src/ffmpeg-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class FFMPEGInfo {
}
});
});
return s.match( /version ([^\s]+) Copyright/ )[1];
var m = s.match( /version\s+([^\s]+)\s+.*Copyright/ )
if (m == null) {
console.error("ffmpeg -version command output not in the expected format: " + s);
return s;
}
return m[1];
} catch (err) {
console.error("Error getting ffmpeg version", err);
return "Error";
Expand Down
Loading

0 comments on commit 3661aa9

Please sign in to comment.