From 4ffc036fd2bfc3f9eba8c5b939674528912d77f8 Mon Sep 17 00:00:00 2001 From: Dan Ferguson Date: Fri, 24 Apr 2020 14:07:30 -0400 Subject: [PATCH] Added program managment options.. Shuffle, Block Shuffle, Sort, and Remove Dups.. --- index.js | 4 + web/directives/channel-config.js | 101 +++++++++++++++++++++++ web/directives/plex-library.js | 53 ++++++------ web/public/templates/channel-config.html | 22 ++++- web/public/templates/plex-library.html | 7 +- web/public/templates/program-config.html | 4 +- 6 files changed, 161 insertions(+), 30 deletions(-) diff --git a/index.js b/index.js index 39e1ab1..c23517d 100644 --- a/index.js +++ b/index.js @@ -32,6 +32,9 @@ process.env.HOST = process.env.HOST || "127.0.0.1" if (!fs.existsSync(process.env.DATABASE)) fs.mkdirSync(process.env.DATABASE) +if(!fs.existsSync(path.join(process.env.DATABASE, 'images'))) + fs.mkdirSync(path.join(process.env.DATABASE, 'images')) + db.connect(process.env.DATABASE, ['channels', 'plex-servers', 'ffmpeg-settings', 'xmltv-settings', 'hdhr-settings']) initDB(db) @@ -89,6 +92,7 @@ let hdhr = HDHR(db) let app = express() app.use(bodyParser.json({limit: '50mb'})) app.use(express.static(path.join(__dirname, 'web/public'))) +app.use('/images', express.static(path.join(process.env.DATABASE, 'images'))) app.use(api.router(db, xmltvInterval)) app.use(video.router(db)) app.use(hdhr.router) diff --git a/web/directives/channel-config.js b/web/directives/channel-config.js index 0bb7eff..dcc7478 100644 --- a/web/directives/channel-config.js +++ b/web/directives/channel-config.js @@ -39,6 +39,107 @@ module.exports = function ($timeout) { scope.$watch('channel.startTime', () => { updateChannelDuration() }) + scope.sortShows = () => { + let shows = {} + let movies = [] + let newProgs = [] + let progs = scope.channel.programs + for (let i = 0, l = progs.length; i < l; i++) { + if (progs[i].type === 'movie') { + movies.push(progs[i]) + } else { + if (typeof shows[progs[i].showTitle] === 'undefined') + shows[progs[i].showTitle] = [] + shows[progs[i].showTitle].push(progs[i]) + } + } + let keys = Object.keys(shows) + for (let i = 0, l = keys.length; i < l; i++) { + shows[keys[i]].sort((a, b) => { + if (a.season === b.season) { + if (a.episode > b.episode) { + return 1 + } else { + return -1 + } + } else if (a.season > b.season) { + return 1; + } else if (b.season > a.season) { + return -1; + } else { + return 0 + } + }) + newProgs = newProgs.concat(shows[keys[i]]) + } + scope.channel.programs = newProgs.concat(movies) + updateChannelDuration() + } + scope.removeDuplicates = () => { + let tmpProgs = {} + let progs = scope.channel.programs + for (let i = 0, l = progs.length; i < l; i++) { + if (progs[i].type === 'movie') { + tmpProgs[progs[i].title + progs[i].durationStr] = progs[i] + } else { + tmpProgs[progs[i].showTitle + '-' + progs[i].season + '-' + progs[i].episode] = progs[i] + } + } + let newProgs = [] + let keys = Object.keys(tmpProgs) + for (let i = 0, l = keys.length; i < l; i++) { + newProgs.push(tmpProgs[keys[i]]) + } + scope.channel.programs = newProgs + } + scope.blockShuffle = (blockCount) => { + if (typeof blockCount === 'undefined' || blockCount == null) + return + let shows = {} + let movies = [] + let newProgs = [] + let progs = scope.channel.programs + for (let i = 0, l = progs.length; i < l; i++) { + if (progs[i].type === 'movie') { + movies.push(progs[i]) + } else { + if (typeof shows[progs[i].showTitle] === 'undefined') + shows[progs[i].showTitle] = [] + shows[progs[i].showTitle].push(progs[i]) + } + } + let keys = Object.keys(shows) + let index = 0 + while (keys.length > 0) { + if (shows[keys[index]].length === 0) { + keys.splice(index, 1) + if (index >= keys.length) + index = 0 + continue + } + for (let i = 0, l = blockCount; i < l; i++) { + if (shows[keys[index]].length > 0) + newProgs.push(shows[keys[index]].shift()) + } + index++ + if (index >= keys.length) + index = 0 + } + + scope.channel.programs = newProgs.concat(movies) + updateChannelDuration() + } + scope.randomShuffle = () => { + randomShuffle(scope.channel.programs) + updateChannelDuration() + } + function randomShuffle(a) { + for (let i = a.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [a[i], a[j]] = [a[j], a[i]]; + } + return a; + } function updateChannelDuration() { scope.channel.duration = 0 for (let i = 0, l = scope.channel.programs.length; i < l; i++) { diff --git a/web/directives/plex-library.js b/web/directives/plex-library.js index 9d3af0c..07882c1 100644 --- a/web/directives/plex-library.js +++ b/web/directives/plex-library.js @@ -40,40 +40,41 @@ module.exports = function (plex, pseudotv) { scope.$apply(() => { scope.libraries = lib if (play.length > 0) - scope.libraries.push({ title: "Playlists", key: "", icon: "", nested: play, collapse: false }) + scope.libraries.push({ title: "Playlists", key: "", icon: "", nested: play }) }) }) }, (err) => { console.log(err) }) } - scope.getNested = function (list) { - if (typeof list.collapse == 'undefined') { - plex.getNested(scope.plexServer, list.key).then((res) => { - list.nested = res - list.collapse = true - scope.$apply() - }, (err) => { - console.log(err) - }) - } else { - list.collapse = !list.collapse + scope.getNested = async (list) => { + let r = false + if (typeof list.nested == 'undefined') { + list.nested = await plex.getNested(scope.plexServer, list.key) + r = true } + list.collapse = !list.collapse + if (r) + scope.$apply() } - scope.selectPlaylist = (playlist) => { - if (typeof playlist.collapse == 'undefined') { - plex.getNested(scope.plexServer, playlist.key).then((res) => { - playlist.nested = res - for (let i = 0, l = playlist.nested.length; i < l; i++) - scope.selectItem(playlist.nested[i]) - scope.$apply() - }, (err) => { - console.log(err) - }) - } else { - for (let i = 0, l = playlist.nested.length; i < l; i++) - scope.selectItem(playlist.nested[i]) - } + + scope.selectSeason = async (season) => { + if (typeof season.nested == 'undefined') + season.nested = await plex.getNested(scope.plexServer, season.key) + for (let i = 0, l = season.nested.length; i < l; i++) + scope.$apply(() => { scope.selectItem(season.nested[i]) }) + } + scope.selectShow = async (show) => { + if (typeof show.nested == 'undefined') + show.nested = await plex.getNested(scope.plexServer, show.key) + for (let i = 0, l = show.nested.length; i < l; i++) + await scope.selectSeason(show.nested[i]) + } + scope.selectPlaylist = async (playlist) => { + if (typeof playlist.nested == 'undefined') + playlist.nested = await plex.getNested(scope.plexServer, playlist.key) + for (let i = 0, l = playlist.nested.length; i < l; i++) + scope.$apply(() => { scope.selectItem(playlist.nested[i]) }) } scope.createShowIdentifier = (season, ep) => { return 'S' + (season.toString().padStart(2, '0')) + 'E' + (ep.toString().padStart(2, '0')) diff --git a/web/public/templates/channel-config.html b/web/public/templates/channel-config.html index 1f6713f..a56e6e4 100644 --- a/web/public/templates/channel-config.html +++ b/web/public/templates/channel-config.html @@ -37,6 +37,9 @@
Programs + {{error.programs}}
- +
+

"Block Shuffle" and "Sort TV Shows" will push any movies to the end of the channel.

+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
Add programs to this channel by selecting media from your Plex library
diff --git a/web/public/templates/plex-library.html b/web/public/templates/plex-library.html index 656893b..55575c2 100644 --- a/web/public/templates/plex-library.html +++ b/web/public/templates/plex-library.html @@ -54,7 +54,9 @@ - + + +