From 7b625ade868992240c49041f1f46dc0d0a3c9bec Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 5 May 2016 23:09:36 -0400 Subject: [PATCH] consolidate datetime methods --- dashboard-ui/components/remotecontrol.js | 8 +- dashboard-ui/scripts/dashboardpage.js | 6 +- dashboard-ui/scripts/externalplayer.js | 4 +- dashboard-ui/scripts/itemdetailpage.js | 8 +- dashboard-ui/scripts/librarybrowser.js | 4 +- dashboard-ui/scripts/mediaplayer-video.js | 6 +- dashboard-ui/scripts/mediaplayer.js | 220 +------------------ dashboard-ui/scripts/nowplayingbar.js | 8 +- dashboard-ui/scripts/site.js | 245 ++++++++++++++++++---- 9 files changed, 231 insertions(+), 278 deletions(-) diff --git a/dashboard-ui/components/remotecontrol.js b/dashboard-ui/components/remotecontrol.js index 0d54dd64d9..d5049894cd 100644 --- a/dashboard-ui/components/remotecontrol.js +++ b/dashboard-ui/components/remotecontrol.js @@ -1,4 +1,4 @@ -define(['browser', 'jQuery', 'paper-fab', 'paper-tabs', 'paper-slider', 'paper-icon-button'], function (browser, $) { +define(['browser', 'datetime', 'jQuery', 'paper-fab', 'paper-tabs', 'paper-slider', 'paper-icon-button'], function (browser, datetime, $) { function showSlideshowMenu(context) { require(['scripts/slideshow'], function () { @@ -343,11 +343,11 @@ if (playState.PositionTicks == null) { context.querySelector('.positionTime').innerHTML = '--:--'; } else { - context.querySelector('.positionTime').innerHTML = Dashboard.getDisplayTime(playState.PositionTicks); + context.querySelector('.positionTime').innerHTML = datetime.getDisplayRunningTime(playState.PositionTicks); } if (item && item.RunTimeTicks != null) { - context.querySelector('.runtime').innerHTML = Dashboard.getDisplayTime(item.RunTimeTicks); + context.querySelector('.runtime').innerHTML = datetime.getDisplayRunningTime(item.RunTimeTicks); } else { context.querySelector('.runtime').innerHTML = '--:--'; } @@ -733,7 +733,7 @@ ticks /= 100; ticks *= value; - this.pinValue = Dashboard.getDisplayTime(ticks); + this.pinValue = datetime.getDisplayRunningTime(ticks); }; context.addEventListener('click', onContextClick); diff --git a/dashboard-ui/scripts/dashboardpage.js b/dashboard-ui/scripts/dashboardpage.js index ec59e485ce..04a79b096c 100644 --- a/dashboard-ui/scripts/dashboardpage.js +++ b/dashboard-ui/scripts/dashboardpage.js @@ -411,7 +411,7 @@ if (session.TranscodingInfo && session.TranscodingInfo.Framerate) { - html += ' - '+session.TranscodingInfo.Framerate + ' fps'; + html += ' - ' + session.TranscodingInfo.Framerate + ' fps'; } } else if (session.PlayState.PlayMethod == 'DirectStream') { @@ -465,7 +465,7 @@ var html = ''; if (session.PlayState.PositionTicks) { - html += Dashboard.getDisplayTime(session.PlayState.PositionTicks); + html += datetime.getDisplayRunningTime(session.PlayState.PositionTicks); } else { html += '--:--:--'; } @@ -475,7 +475,7 @@ var nowPlayingItem = session.NowPlayingItem; if (nowPlayingItem && nowPlayingItem.RunTimeTicks) { - html += Dashboard.getDisplayTime(nowPlayingItem.RunTimeTicks); + html += datetime.getDisplayRunningTime(nowPlayingItem.RunTimeTicks); } else { html += '--:--:--'; } diff --git a/dashboard-ui/scripts/externalplayer.js b/dashboard-ui/scripts/externalplayer.js index 7f81c87aea..46b44339a1 100644 --- a/dashboard-ui/scripts/externalplayer.js +++ b/dashboard-ui/scripts/externalplayer.js @@ -1,4 +1,4 @@ -define(['appSettings', 'jQuery', 'paper-slider', 'paper-button'], function (appSettings, $) { +define(['appSettings', 'datetime', 'jQuery', 'paper-slider', 'paper-button'], function (appSettings, datetime, $) { function getDeviceProfile(serverAddress, deviceId, item, startPositionTicks, maxBitrate, mediaSourceId, audioStreamIndex, subtitleStreamIndex) { @@ -322,7 +322,7 @@ var time = item.RunTimeTicks * (Number(pct) * .01); - var tooltext = Dashboard.getDisplayTime(time); + var tooltext = datetime.getDisplayRunningTime(time); $('.sliderValue', elem).html(tooltext); diff --git a/dashboard-ui/scripts/itemdetailpage.js b/dashboard-ui/scripts/itemdetailpage.js index b3da6ae943..67515e9192 100644 --- a/dashboard-ui/scripts/itemdetailpage.js +++ b/dashboard-ui/scripts/itemdetailpage.js @@ -1,4 +1,4 @@ -define(['layoutManager', 'jQuery', 'scrollStyles'], function (layoutManager, $) { +define(['layoutManager', 'datetime', 'jQuery', 'scrollStyles'], function (layoutManager, datetime, $) { var currentItem; @@ -341,7 +341,7 @@ }); var itemsContainer = section.querySelector('.nextUpItems'); - + itemsContainer.innerHTML = html; ImageLoader.lazyChildren(itemsContainer); $(itemsContainer).createCardMenus(); @@ -1402,7 +1402,7 @@ html += '
'; html += '
' + chapterName + '
'; html += '
'; - html += Dashboard.getDisplayTime(chapter.StartPositionTicks); + html += datetime.getDisplayRunningTime(chapter.StartPositionTicks); html += '
'; //cardFooter @@ -1639,7 +1639,7 @@ html += '
' + item.Name + '
'; html += '
'; if (item.RunTimeTicks != "") { - html += Dashboard.getDisplayTime(item.RunTimeTicks); + html += datetime.getDisplayRunningTime(item.RunTimeTicks); } else { html += " "; diff --git a/dashboard-ui/scripts/librarybrowser.js b/dashboard-ui/scripts/librarybrowser.js index 9d9cdefcde..a27edbf702 100644 --- a/dashboard-ui/scripts/librarybrowser.js +++ b/dashboard-ui/scripts/librarybrowser.js @@ -3525,7 +3525,7 @@ if (item.Type == "Audio") { - miscInfo.push(Dashboard.getDisplayTime(item.RunTimeTicks)); + miscInfo.push(datetime.getDisplayRunningTime(item.RunTimeTicks)); } else { minutes = item.RunTimeTicks / 600000000; @@ -3538,7 +3538,7 @@ if (item.CumulativeRunTimeTicks && item.Type != "Series" && item.Type != "Season") { - miscInfo.push(Dashboard.getDisplayTime(item.CumulativeRunTimeTicks)); + miscInfo.push(datetime.getDisplayRunningTime(item.CumulativeRunTimeTicks)); } if (item.OfficialRating && item.Type !== "Season" && item.Type !== "Episode") { diff --git a/dashboard-ui/scripts/mediaplayer-video.js b/dashboard-ui/scripts/mediaplayer-video.js index a5ae0477f7..5dabfbcf35 100644 --- a/dashboard-ui/scripts/mediaplayer-video.js +++ b/dashboard-ui/scripts/mediaplayer-video.js @@ -1,4 +1,4 @@ -define(['appSettings', 'jQuery', 'scrollStyles'], function (appSettings, $) { +define(['appSettings', 'datetime', 'jQuery', 'scrollStyles'], function (appSettings, datetime, $) { function createVideoPlayer(self) { @@ -495,7 +495,7 @@ if (c.Name) { chapterHtml += '
' + c.Name + '
'; } - chapterHtml += '
' + Dashboard.getDisplayTime(c.StartPositionTicks) + '
'; + chapterHtml += '
' + datetime.getDisplayRunningTime(c.StartPositionTicks) + '
'; chapterHtml += '
'; chapterHtml += '
'; @@ -789,7 +789,7 @@ ticks /= 100; ticks *= value; - this.pinValue = Dashboard.getDisplayTime(ticks); + this.pinValue = datetime.getDisplayRunningTime(ticks); }; volumeSlider = $('.videoVolumeSlider', parent).on('change', function () { diff --git a/dashboard-ui/scripts/mediaplayer.js b/dashboard-ui/scripts/mediaplayer.js index b3efd6e214..6a5eee4617 100644 --- a/dashboard-ui/scripts/mediaplayer.js +++ b/dashboard-ui/scripts/mediaplayer.js @@ -1,4 +1,4 @@ -define(['appSettings', 'userSettings', 'appStorage'], function (appSettings, userSettings, appStorage) { +define(['appSettings', 'userSettings', 'appStorage', 'datetime'], function (appSettings, userSettings, appStorage, datetime) { function mediaPlayer() { @@ -44,216 +44,6 @@ define(['appSettings', 'userSettings', 'appStorage'], function (appSettings, use return targets; }; - function updateDeviceProfileForAndroid(profile) { - - // Just here as an easy escape out, if ever needed - var enableVlcVideo = true; - var enableVlcAudio = window.VlcAudio; - - if (enableVlcVideo) { - - profile.DirectPlayProfiles.push({ - Container: "m4v,3gp,ts,mpegts,mov,xvid,vob,mkv,wmv,asf,ogm,ogv,m2v,avi,mpg,mpeg,mp4,webm", - Type: 'Video', - AudioCodec: 'aac,aac_latm,mp3,ac3,wma,dca,pcm,PCM_S16LE,PCM_S24LE,opus,flac' - }); - - profile.CodecProfiles = profile.CodecProfiles.filter(function (i) { - return i.Type == 'Audio'; - }); - - profile.SubtitleProfiles = []; - profile.SubtitleProfiles.push({ - Format: 'srt', - Method: 'External' - }); - profile.SubtitleProfiles.push({ - Format: 'srt', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'subrip', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'ass', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'ssa', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'pgs', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'pgssub', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'dvdsub', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'vtt', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'sub', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'idx', - Method: 'Embed' - }); - profile.SubtitleProfiles.push({ - Format: 'smi', - Method: 'Embed' - }); - - // These don't play very well - profile.CodecProfiles.push({ - Type: 'VideoAudio', - Codec: 'dca', - Conditions: [ - { - Condition: 'LessThanEqual', - Property: 'AudioChannels', - Value: 6 - } - ] - }); - - profile.CodecProfiles.push({ - Type: 'VideoAudio', - Codec: 'aac,mp3', - Conditions: [ - { - Condition: 'LessThanEqual', - Property: 'AudioChannels', - Value: '6' - } - ] - }); - - profile.CodecProfiles.push({ - Type: 'Video', - Codec: 'h264', - Conditions: [ - { - Condition: 'EqualsAny', - Property: 'VideoProfile', - Value: 'high|main|baseline|constrained baseline' - }, - { - Condition: 'LessThanEqual', - Property: 'VideoLevel', - Value: '41' - }] - }); - - profile.TranscodingProfiles.filter(function (p) { - - return p.Type == 'Video' && p.CopyTimestamps == true; - - }).forEach(function (p) { - - // Vlc doesn't seem to handle this well - p.CopyTimestamps = false; - }); - - profile.TranscodingProfiles.filter(function (p) { - - return p.Type == 'Video' && p.VideoCodec == 'h264'; - - }).forEach(function (p) { - - p.AudioCodec += ',ac3'; - }); - } - - if (enableVlcAudio) { - - profile.DirectPlayProfiles.push({ - Container: "aac,mp3,mpa,wav,wma,mp2,ogg,oga,webma,ape,opus", - Type: 'Audio' - }); - - profile.CodecProfiles = profile.CodecProfiles.filter(function (i) { - return i.Type != 'Audio'; - }); - - profile.CodecProfiles.push({ - Type: 'Audio', - Conditions: [{ - Condition: 'LessThanEqual', - Property: 'AudioChannels', - Value: '2' - }] - }); - } - } - - function updateDeviceProfileForIOS(profile) { - - } - - self.getDeviceProfile = function (maxHeight) { - - return new Promise(function (resolve, reject) { - - require(['browserdeviceprofile', 'qualityoptions'], function (profileBuilder, qualityoptions) { - - var supportsCustomSeeking = false; - if (!browserInfo.mobile) { - supportsCustomSeeking = true; - } else if (AppInfo.isNativeApp && browserInfo.safari) { - if (navigator.userAgent.toLowerCase().indexOf('ipad') == -1) { - // Need to disable it in order to support picture in picture - supportsCustomSeeking = true; - } - } else if (AppInfo.isNativeApp) { - supportsCustomSeeking = true; - } - - var profile = profileBuilder({ - supportsCustomSeeking: supportsCustomSeeking - }); - - if (!(AppInfo.isNativeApp && browserInfo.android)) { - profile.SubtitleProfiles.push({ - Format: 'ass', - Method: 'External' - }); - profile.SubtitleProfiles.push({ - Format: 'ssa', - Method: 'External' - }); - } - - var bitrateSetting = appSettings.maxStreamingBitrate(); - - if (!maxHeight) { - maxHeight = qualityoptions.getVideoQualityOptions(bitrateSetting).filter(function (q) { - return q.selected; - })[0].maxHeight; - } - - if (AppInfo.isNativeApp && browserInfo.android) { - updateDeviceProfileForAndroid(profile); - } - else if (AppInfo.isNativeApp && browserInfo.safari) { - updateDeviceProfileForIOS(profile); - } - - profile.MaxStreamingBitrate = bitrateSetting; - - resolve(profile); - }); - }); - }; - var supportsTextTracks; self.supportsTextTracks = function () { @@ -378,7 +168,7 @@ define(['appSettings', 'userSettings', 'appStorage'], function (appSettings, use var playSessionId = getParameterByName('PlaySessionId', currentSrc); var liveStreamId = getParameterByName('LiveStreamId', currentSrc); - self.getDeviceProfile().then(function (deviceProfile) { + Dashboard.getDeviceProfile().then(function (deviceProfile) { var audioStreamIndex = params.AudioStreamIndex == null ? (getParameterByName('AudioStreamIndex', currentSrc) || null) : params.AudioStreamIndex; if (typeof (audioStreamIndex) == 'string') { @@ -481,12 +271,12 @@ define(['appSettings', 'userSettings', 'appStorage'], function (appSettings, use // Convert to ticks ticks = Math.floor(ticks); - var timeText = Dashboard.getDisplayTime(ticks); + var timeText = datetime.getDisplayRunningTime(ticks); var mediaRenderer = self.currentMediaRenderer; if (self.currentDurationTicks) { - timeText += " / " + Dashboard.getDisplayTime(self.currentDurationTicks); + timeText += " / " + datetime.getDisplayRunningTime(self.currentDurationTicks); if (positionSlider) { @@ -864,7 +654,7 @@ define(['appSettings', 'userSettings', 'appStorage'], function (appSettings, use } var onBitrateDetected = function () { - self.getDeviceProfile().then(function (deviceProfile) { + Dashboard.getDeviceProfile().then(function (deviceProfile) { playOnDeviceProfileCreated(deviceProfile, item, startPosition, callback); }); }; diff --git a/dashboard-ui/scripts/nowplayingbar.js b/dashboard-ui/scripts/nowplayingbar.js index 9a05ed36e9..9e43783987 100644 --- a/dashboard-ui/scripts/nowplayingbar.js +++ b/dashboard-ui/scripts/nowplayingbar.js @@ -1,4 +1,4 @@ -define(['jQuery'], function ($) { +define(['datetime', 'jQuery'], function (datetime, $) { var currentPlayer; @@ -247,7 +247,7 @@ ticks /= 100; ticks *= value; - this.pinValue = Dashboard.getDisplayTime(ticks); + this.pinValue = datetime.getDisplayRunningTime(ticks); }; }, 300); } @@ -375,11 +375,11 @@ } } - var timeText = Dashboard.getDisplayTime(playState.PositionTicks); + var timeText = datetime.getDisplayRunningTime(playState.PositionTicks); if (nowPlayingItem.RunTimeTicks) { - timeText += " / " + Dashboard.getDisplayTime(nowPlayingItem.RunTimeTicks); + timeText += " / " + datetime.getDisplayRunningTime(nowPlayingItem.RunTimeTicks); } diff --git a/dashboard-ui/scripts/site.js b/dashboard-ui/scripts/site.js index b35b010be2..9caf15df89 100644 --- a/dashboard-ui/scripts/site.js +++ b/dashboard-ui/scripts/site.js @@ -1101,44 +1101,6 @@ var Dashboard = { } }, - getDisplayTime: function (ticks) { - - var ticksPerHour = 36000000000; - var ticksPerMinute = 600000000; - var ticksPerSecond = 10000000; - - var parts = []; - - var hours = ticks / ticksPerHour; - hours = Math.floor(hours); - - if (hours) { - parts.push(hours); - } - - ticks -= (hours * ticksPerHour); - - var minutes = ticks / ticksPerMinute; - minutes = Math.floor(minutes); - - ticks -= (minutes * ticksPerMinute); - - if (minutes < 10 && hours) { - minutes = '0' + minutes; - } - parts.push(minutes); - - var seconds = ticks / ticksPerSecond; - seconds = Math.floor(seconds); - - if (seconds < 10) { - seconds = '0' + seconds; - } - parts.push(seconds); - - return parts.join(':'); - }, - getSupportedRemoteCommands: function () { // Full list @@ -1249,6 +1211,209 @@ var Dashboard = { exit: function () { Dashboard.logout(); + }, + + getDeviceProfile: function (maxHeight) { + + return new Promise(function (resolve, reject) { + + function updateDeviceProfileForAndroid(profile) { + + // Just here as an easy escape out, if ever needed + var enableVlcVideo = true; + var enableVlcAudio = window.VlcAudio; + + if (enableVlcVideo) { + + profile.DirectPlayProfiles.push({ + Container: "m4v,3gp,ts,mpegts,mov,xvid,vob,mkv,wmv,asf,ogm,ogv,m2v,avi,mpg,mpeg,mp4,webm", + Type: 'Video', + AudioCodec: 'aac,aac_latm,mp3,ac3,wma,dca,pcm,PCM_S16LE,PCM_S24LE,opus,flac' + }); + + profile.CodecProfiles = profile.CodecProfiles.filter(function (i) { + return i.Type == 'Audio'; + }); + + profile.SubtitleProfiles = []; + profile.SubtitleProfiles.push({ + Format: 'srt', + Method: 'External' + }); + profile.SubtitleProfiles.push({ + Format: 'srt', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'subrip', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'ass', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'ssa', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'pgs', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'pgssub', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'dvdsub', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'vtt', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'sub', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'idx', + Method: 'Embed' + }); + profile.SubtitleProfiles.push({ + Format: 'smi', + Method: 'Embed' + }); + + // These don't play very well + profile.CodecProfiles.push({ + Type: 'VideoAudio', + Codec: 'dca', + Conditions: [ + { + Condition: 'LessThanEqual', + Property: 'AudioChannels', + Value: 6 + } + ] + }); + + profile.CodecProfiles.push({ + Type: 'VideoAudio', + Codec: 'aac,mp3', + Conditions: [ + { + Condition: 'LessThanEqual', + Property: 'AudioChannels', + Value: '6' + } + ] + }); + + profile.CodecProfiles.push({ + Type: 'Video', + Codec: 'h264', + Conditions: [ + { + Condition: 'EqualsAny', + Property: 'VideoProfile', + Value: 'high|main|baseline|constrained baseline' + }, + { + Condition: 'LessThanEqual', + Property: 'VideoLevel', + Value: '41' + }] + }); + + profile.TranscodingProfiles.filter(function (p) { + + return p.Type == 'Video' && p.CopyTimestamps == true; + + }).forEach(function (p) { + + // Vlc doesn't seem to handle this well + p.CopyTimestamps = false; + }); + + profile.TranscodingProfiles.filter(function (p) { + + return p.Type == 'Video' && p.VideoCodec == 'h264'; + + }).forEach(function (p) { + + p.AudioCodec += ',ac3'; + }); + } + + if (enableVlcAudio) { + + profile.DirectPlayProfiles.push({ + Container: "aac,mp3,mpa,wav,wma,mp2,ogg,oga,webma,ape,opus", + Type: 'Audio' + }); + + profile.CodecProfiles = profile.CodecProfiles.filter(function (i) { + return i.Type != 'Audio'; + }); + + profile.CodecProfiles.push({ + Type: 'Audio', + Conditions: [{ + Condition: 'LessThanEqual', + Property: 'AudioChannels', + Value: '2' + }] + }); + } + } + + require(['browserdeviceprofile', 'qualityoptions', 'appSettings'], function (profileBuilder, qualityoptions, appSettings) { + + var supportsCustomSeeking = false; + if (!browserInfo.mobile) { + supportsCustomSeeking = true; + } else if (AppInfo.isNativeApp && browserInfo.safari) { + if (navigator.userAgent.toLowerCase().indexOf('ipad') == -1) { + // Need to disable it in order to support picture in picture + supportsCustomSeeking = true; + } + } else if (AppInfo.isNativeApp) { + supportsCustomSeeking = true; + } + + var profile = profileBuilder({ + supportsCustomSeeking: supportsCustomSeeking + }); + + if (!(AppInfo.isNativeApp && browserInfo.android)) { + profile.SubtitleProfiles.push({ + Format: 'ass', + Method: 'External' + }); + profile.SubtitleProfiles.push({ + Format: 'ssa', + Method: 'External' + }); + } + + var bitrateSetting = appSettings.maxStreamingBitrate(); + + if (!maxHeight) { + maxHeight = qualityoptions.getVideoQualityOptions(bitrateSetting).filter(function (q) { + return q.selected; + })[0].maxHeight; + } + + if (AppInfo.isNativeApp && browserInfo.android) { + updateDeviceProfileForAndroid(profile); + } + + profile.MaxStreamingBitrate = bitrateSetting; + + resolve(profile); + }); + }); } }; @@ -1377,9 +1542,7 @@ var AppInfo = {}; function getSyncProfile() { - return getRequirePromise(['scripts/mediaplayer']).then(function () { - return MediaPlayer.getDeviceProfile(Math.max(screen.height, screen.width)); - }); + return Dashboard.getDeviceProfile(Math.max(screen.height, screen.width)); } function onApiClientCreated(e, newApiClient) {