diff --git a/app.js b/app.js index 22e422d..552bbd7 100755 --- a/app.js +++ b/app.js @@ -46,7 +46,7 @@ app.on('ready', function () { }) ipc.on('open-file-dialog', function () { - var files = dialog.showOpenDialog({ properties: [ 'openFile', 'multiSelections' ]}) + var files = dialog.showOpenDialog({ properties: [ 'openFile', 'multiSelections' ] }) if (files) { files.forEach(app.addRecentDocument) win.send('add-to-playlist', files) @@ -110,11 +110,8 @@ app.on('ready', function () { globalShortcut.register('MediaPreviousTrack', function () { win.send('media-previous-track') }) - }) app.on('will-quit', function () { - globalShortcut.unregisterAll() - }) diff --git a/index.js b/index.js index 6a0c078..2c70927 100644 --- a/index.js +++ b/index.js @@ -196,12 +196,12 @@ $('#controls-timeline').on('click', function (e) { media.time(time) }) -function updateTimelineTooltip(e) { +function updateTimelineTooltip (e) { var tooltip = $('#controls-timeline-tooltip')[0] var percentage = e.pageX / $('#controls-timeline')[0].offsetWidth - var time = formatTime(percentage * media.duration) + var time = formatTime(percentage * media.duration) tooltip.innerHTML = time - tooltip.style.left = (e.pageX - tooltip.offsetWidth / 2) + "px" + tooltip.style.left = (e.pageX - tooltip.offsetWidth / 2) + 'px' } $('#controls-timeline').on('mousemove', function (e) { @@ -222,20 +222,20 @@ $('#controls-timeline').on('mouseout', function (e) { var isVolumeSliderClicked = false var isPbrateSliderClicked = false -function updateAudioVolume(value) { +function updateAudioVolume (value) { media.volume(value) } -function updateVolumeSlider(volume) { +function updateVolumeSlider (volume) { var val = volume.value * 100 volume.style.background = '-webkit-gradient(linear, left top, right top, color-stop(' + val.toString() + '%, #31A357), color-stop(' + val.toString() + '%, #727374))' } -function updatePlaybackRate(value) { +function updatePlaybackRate (value) { media.playbackRate(value) } -function updatePlaybackRateSlider(volume) { +function updatePlaybackRateSlider (volume) { var min = 0.5 var max = 4 var scaled = (volume.value - min) / (max - min) @@ -243,6 +243,13 @@ function updatePlaybackRateSlider(volume) { volume.style.background = '-webkit-gradient(linear, left top, right top, color-stop(' + val.toString() + '%, #31A357), color-stop(' + val.toString() + '%, #727374))' } +function defaultPlaybackRate () { + updatePlaybackRate(1) + var volume = $('#controls-pbrate-slider')[0] + volume.value = 1 + updatePlaybackRateSlider(volume) +} + $('#controls-volume-slider').on('mousemove', function (e) { if (isVolumeSliderClicked) { var volume = $('#controls-volume-slider')[0] @@ -281,6 +288,10 @@ $('#controls-pbrate-slider').on('mouseup', function (e) { isPbrateSliderClicked = false }) +$('#controls-pbrate').on('dblclick', function () { + defaultPlaybackRate() +}) + $(document).on('keydown', function (e) { if (e.keyCode === 27 && isFullscreen) return onfullscreentoggle(e) if (e.keyCode === 13 && e.metaKey) return onfullscreentoggle(e) @@ -442,7 +453,7 @@ var appmenu_template = [ submenu: [ { label: 'About Playback', - click: function() { ipc.send('open-url-in-external', 'https://mafintosh.github.io/playback/') } + click: function () { ipc.send('open-url-in-external', 'https://mafintosh.github.io/playback/') } }, { type: 'separator' @@ -450,7 +461,7 @@ var appmenu_template = [ { label: 'Quit', accelerator: 'Command+Q', - click: function() { ipc.send('close') } + click: function () { ipc.send('close') } } ] }, @@ -460,7 +471,7 @@ var appmenu_template = [ { label: 'Add media', accelerator: 'Command+O', - click: function() { ipc.send('open-file-dialog') } + click: function () { ipc.send('open-file-dialog') } }, { label: 'Add link from clipboard', @@ -475,7 +486,7 @@ var appmenu_template = [ { label: 'Minimize', accelerator: 'Command+M', - click: function() { ipc.send('minimize') } + click: function () { ipc.send('minimize') } }, { label: 'Toggle Full Screen', @@ -489,18 +500,18 @@ var appmenu_template = [ submenu: [ { label: 'Report Issue', - click: function() { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback/issues') } + click: function () { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback/issues') } }, { label: 'View Source Code on GitHub', - click: function() { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback') } + click: function () { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback') } }, { type: 'separator' }, { label: 'Releases', - click: function() { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback/releases') } + click: function () { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback/releases') } } ] } @@ -585,7 +596,7 @@ var server = http.createServer(function (req, res) { var stringify = JSONStream.stringify() var onseek = function () { - stringify.write({type: 'seek', time: media.time() }) + stringify.write({ type: 'seek', time: media.time() }) } var onsubs = function (data) { @@ -593,7 +604,7 @@ var server = http.createServer(function (req, res) { } stringify.pipe(res) - stringify.write({type: 'open', url: 'http://' + network() + ':' + server.address().port + '/' + list.selected.id, time: media.time() }) + stringify.write({ type: 'open', url: 'http://' + network() + ':' + server.address().port + '/' + list.selected.id, time: media.time() }) media.on('subtitles', onsubs) media.on('seek', onseek) @@ -640,7 +651,7 @@ server.listen(0, function () { }) if (argv.follow) { - mdns.on('response', function onresponse(response) { + mdns.on('response', function onresponse (response) { response.answers.forEach(function (a) { if (a.name !== 'playback') return clearInterval(interval) @@ -701,17 +712,17 @@ server.listen(0, function () { }) var volumeSlider = $('#controls-volume-slider')[0] -volumeSlider.setAttribute("value", 0.5) -volumeSlider.setAttribute("min", 0) -volumeSlider.setAttribute("max", 1) -volumeSlider.setAttribute("step", 0.05) +volumeSlider.setAttribute('value', 0.5) +volumeSlider.setAttribute('min', 0) +volumeSlider.setAttribute('max', 1) +volumeSlider.setAttribute('step', 0.05) updateAudioVolume(0.5) updateVolumeSlider(volumeSlider) var pbrateSlider = $('#controls-pbrate-slider')[0] -pbrateSlider.setAttribute("value", 1) -pbrateSlider.setAttribute("min", 0.5) -pbrateSlider.setAttribute("max", 4) -pbrateSlider.setAttribute("step", 0.25) +pbrateSlider.setAttribute('value', 1) +pbrateSlider.setAttribute('min', 0.5) +pbrateSlider.setAttribute('max', 4) +pbrateSlider.setAttribute('step', 0.25) updatePlaybackRate(1) updatePlaybackRateSlider(pbrateSlider) diff --git a/player.js b/player.js index b0e0548..f349e90 100644 --- a/player.js +++ b/player.js @@ -80,7 +80,7 @@ module.exports = function ($video) { $video.addEventListener('loadedmetadata', function () { if (chromecast) return that.width = $video.videoWidth - that.height = $video.videoHeight + that.height = $video.videoHeight that.ratio = that.width / that.height that.duration = $video.duration that.emit('metadata') @@ -117,7 +117,7 @@ module.exports = function ($video) { var subsUrl = mediaUrl.replace(/(:\/\/.+)\/.*/, '$1/subtitles') var subsList = [] for (var i = 0; i < 100; i++) subsList.push(subsUrl) - chromecast.play(mediaUrl, {title: 'Playback', seek: time || 0, subtitles: subsList, autoSubtitles: !!subs }, onmetadata) + chromecast.play(mediaUrl, { title: 'Playback', seek: time || 0, subtitles: subsList, autoSubtitles: !!subs }, onmetadata) } else { chromecast.resume() } @@ -164,7 +164,7 @@ module.exports = function ($video) { if (!buf) return null var $track = document.createElement('track') $track.setAttribute('default', 'default') - $track.setAttribute('src', 'data:text/vtt;base64,'+buf.toString('base64')) + $track.setAttribute('src', 'data:text/vtt;base64,' + buf.toString('base64')) $track.setAttribute('label', 'Subtitles') $track.setAttribute('kind', 'subtitles') $video.appendChild($track) diff --git a/playlist.js b/playlist.js index 5e666b9..1d4f272 100644 --- a/playlist.js +++ b/playlist.js @@ -28,7 +28,7 @@ module.exports = function () { torrent.files.forEach(function (f) { if (/\.(vtt|srt)$/i.test(f.name)) { - subtitles[f.name] = f; + subtitles[f.name] = f } }) @@ -41,12 +41,11 @@ module.exports = function () { var basename = f.name.substr(0, f.name.lastIndexOf('.')) var subtitle = subtitles[basename + '.srt'] || subtitles[basename + '.vtt'] if (subtitle) { - subtitle.createReadStream().pipe(vtt()).pipe(concat(function(data) { - f.subtitles = data + subtitle.createReadStream().pipe(vtt()).pipe(concat(function (data) { + f.subtitles = data })) } } - }) setInterval(function () { @@ -111,22 +110,21 @@ module.exports = function () { return +a.itag - +b.itag }) - var vidFmt formats.forEach(function (fmt) { // prefer webm - if (fmt.itag === '46') return vidFmt = fmt - if (fmt.itag === '45') return vidFmt = fmt - if (fmt.itag === '44') return vidFmt = fmt - if (fmt.itag === '43') return vidFmt = fmt + if (fmt.itag === '46') return (vidFmt = fmt) + if (fmt.itag === '45') return (vidFmt = fmt) + if (fmt.itag === '44') return (vidFmt = fmt) + if (fmt.itag === '43') return (vidFmt = fmt) // otherwise h264 - if (fmt.itag === '38') return vidFmt = fmt - if (fmt.itag === '37') return vidFmt = fmt - if (fmt.itag === '22') return vidFmt = fmt - if (fmt.itag === '18') return vidFmt = fmt + if (fmt.itag === '38') return (vidFmt = fmt) + if (fmt.itag === '37') return (vidFmt = fmt) + if (fmt.itag === '22') return (vidFmt = fmt) + if (fmt.itag === '18') return (vidFmt = fmt) }) - if (!vidFmt) return cb (new Error('No suitable video format found')) + if (!vidFmt) return cb(new Error('No suitable video format found')) cb(null, {info: info, fmt: vidFmt}) }) @@ -157,9 +155,9 @@ module.exports = function () { var ext = extensions.shift() if (!ext) return ondone() - fs.exists(basename + '.' + ext, function(exists) { + fs.exists(basename + '.' + ext, function (exists) { if (!exists) return next() - fs.createReadStream(basename + '.' + ext).pipe(vtt()).pipe(concat(function(data) { + fs.createReadStream(basename + '.' + ext).pipe(vtt()).pipe(concat(function (data) { file.subtitles = data ondone() })) @@ -199,11 +197,11 @@ module.exports = function () { } var onipfslink = function (link, cb) { - if (link[0] != '/') link = "/" + link // / may be stripped in add + if (link[0] !== '/') link = '/' + link // / may be stripped in add var local = 'localhost:8080' // todo: make this configurable var gateway = 'gateway.ipfs.io' - var file = {} + var file = { } // first, try the local http gateway var u = 'http://' + local + link diff --git a/splash.gif b/splash.gif index 9b72e87..bd727cc 100644 Binary files a/splash.gif and b/splash.gif differ