Skip to content

Commit

Permalink
Second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xylish7 committed Feb 9, 2018
1 parent 1cbab69 commit d76c37d
Show file tree
Hide file tree
Showing 19 changed files with 7,021 additions and 0 deletions.
122 changes: 122 additions & 0 deletions assets/css/main.css
@@ -0,0 +1,122 @@
@font-face {
font-family: titleFont;
src: url(../fonts/Keep_Singing.ttf);
}

*:focus {
outline: none !important;
}

body {
user-select: none;
-webkit-user-select: none;
cursor: context-menu;
overflow:hidden;
font-family: "Courier New";
width: 600;
height: 600;
}

body::-webkit-scrollbar{
display: none;
}

article {
margin-top: 10px;
}

progress {
width: 100%;
margin-top: 6px;
}

.container {
margin: 0 20px
}

.fa.fa-folder-open-o {
color: hsl(348, 100%, 61%);
}
.log {
max-height: 180px;
min-height: 25px;
overflow-y: scroll;
margin: 0 15px 15px;
padding: 5px 10px;
border-style: solid;
border-color: hsl(348, 100%, 61%);
border-width: 1px;
border-radius: 5px;
overflow-x: hidden;
}

.customized-scrollbar::-webkit-scrollbar {
width: 9px;
height: 8px;
border-radius: 5px
}

.customized-scrollbar::-webkit-scrollbar-thumb {
background: lightgray;
border-radius: 20px;
}

.columns.is-mobile.is-gapless {
margin: 0
}

.video-title {
white-space: nowrap;
width: 150px;
overflow: hidden;
text-overflow: ellipsis;
}

.video-number {
font-size: 13px;
}

.conversion-number {
font-size: 13px;
}

.percent-progress{
margin-left: 10px;
}

.notification {
padding: 5px 0px 5px 10px;
display: none;
text-align: center;
margin: auto;
}

#title {
color: hsl(348, 100%, 61%);
font-size: 22px;
font-family: titleFont;
}

#url-input {
border:1px solid lightgray;
background-image:none;
background-color:transparent;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
outline: none;
}

#url-input:hover {
border: 1px solid #b5b5b5
}

#openFolder {
border-color: hsl(348, 100%, 61%);
}

#button-message {
width: 112px;
height: 18;

}
3,081 changes: 3,081 additions & 0 deletions assets/fontawesome/fontawesome-all.js

Large diffs are not rendered by default.

Binary file added assets/fonts/Keep_Singing.ttf
Binary file not shown.
Binary file added assets/icons/icon.ico
Binary file not shown.
Binary file added assets/icons/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions main.js
@@ -0,0 +1,66 @@
// Modules
require ('hazardous') // module required when creating installed
const {app, ipcMain} = require('electron')
const ytdl = require('youtube-dl')
const path = require('path')
const fs = require('fs')


// Internal Modules
const mainWindow = require('./main/windows/mainWindow')
const mp3converter = require('./main/conversion/mp3Converter')
const dlPlaylist = require('./main/ytdl/download-playlist')
const menuBar = require('./main/menu/menu-bar')
const onExit = require('./main/kill-processes/on-exit')

// require('electron-reload')(__dirname);
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', () => {
// Create windows
var windows = {
mainWindow: mainWindow.createWindow()
}

// Create context menu
windows.mainWindow.webContents.on('context-menu', (e, params) => {
menuBar.contextMenu.popup(windows.mainWindow, params.x, params.y)
})

// Send window object to download video
dlPlaylist.staticInfo.win = windows.mainWindow

// Show notification if processes are in progress
windows.mainWindow.on('close', (e) => {
e.preventDefault()

windows.mainWindow.webContents.send('close-window')

})
ipcMain.on('close-window-response', (event, messageKey) => {
onExit.confirmExit(windows.mainWindow, messageKey)
})

// Start new download
ipcMain.on('new-playlist', (event, downloadInfo) =>{
dlPlaylist.ipcEvent.downloadInfo = downloadInfo
dlPlaylist.ipcEvent.event = event
dlPlaylist.staticInfo.downloadFinished = false
dlPlaylist.playlist(downloadInfo.url)
});

})

// Quit when all windows are closed.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})

app.on('activate', () => {
if (mainWindow === null) mainWindow.createWindow()
})




26 changes: 26 additions & 0 deletions main/conversion/ffmpegOutput.js
@@ -0,0 +1,26 @@
class Output {
constructor () {
this.string
this._raw_duration
this.seconds
}

get searchTime () {
return this.string.search("time=")
}

get duration () {
return this.string.substring(this.searchTime + 5, this.searchTime + 13)
}

rawDuration () {
var hms = this.duration.split(':')
return this.seconds = (+hms[0]) * 60 * 60 + (+hms[1]) * 60 + (+hms[2]);
}

get percent () {
return (100*this.rawDuration()/this._raw_duration).toFixed(2)
}
}

module.exports = Output
110 changes: 110 additions & 0 deletions main/conversion/mp3Converter.js
@@ -0,0 +1,110 @@
var fs = require('fs')
var path = require('path')
var spawn = require('cross-spawn-async');
var Output = require('./ffmpegOutput.js');

exports.childProcesses = []

var pendingProcesses = []
exports.convertVideo = (playlistInfo, downloadInfo) => {
var spawnAttributes = {
ffmpeg_path: path.resolve(__dirname, '..', '..', 'node_modules', 'youtube-dl', 'bin', 'ffmpeg.exe'),
args: [
'-i',
`${downloadInfo.savePath}\\${playlistInfo.dynamic.title}.webm`,
'-map', '0:a:0',
'-b:a', '96k',
'-y',
`${downloadInfo.savePath}\\${playlistInfo.dynamic.title}.mp3`
],
options: {
detached: false
}
}


if (!checkAvailability()) {
var processAttributes = {
spawnAttributes,
playlistInfo,
downloadInfo
}
pendingProcesses.push(processAttributes)

}
else {
if (!checkPending()) {
spawnChild(spawnAttributes, playlistInfo, downloadInfo)
}
else {
spawnChild(pendingProcesses.shift(), playlistInfo, downloadInfo)
}

}
}

var spawnChild = (spawnAttributes, playlistInfo, downloadInfo) => {
let ffmpegOutput = new Output()

var sendData = {
conversionFinished: false
}

// Spawn new child process
var {ffmpeg_path, args, options} = spawnAttributes
var ffmpeg = spawn(ffmpeg_path, args, options);
this.childProcesses.push(ffmpeg.pid)


sendData.playlist_index = playlistInfo.dynamic.playlist_index
sendData.isPlaylist = playlistInfo.static.isPlaylist
sendData.title = playlistInfo.dynamic.title

ffmpeg.stderr.on('data', (data) => {

ffmpegOutput.string = data.toString()
ffmpegOutput._raw_duration = playlistInfo.dynamic._raw_duration
sendData.percent = ffmpegOutput.percent

if (!isNaN(sendData.percent)) {
playlistInfo.static.win.webContents.send('conversion-percent', sendData)
}

});

ffmpeg.on('exit', (code) => {
if (sendData.playlist_index == playlistInfo.static.n_entries) {
sendData.conversionFinished = true;
}

if (code == 0)
if (playlistInfo.static.keepFiles == 'false'){
fs.unlinkSync(`${downloadInfo.savePath}\\${sendData.title}.webm`);
}

// Remove pid from child array
removeChild(ffmpeg.pid)

// Start a pending process
if (checkPending()) {
var pendingProcess = pendingProcesses.shift()
spawnChild(pendingProcess.spawnAttributes, pendingProcess.playlistInfo, pendingProcess.downloadInfo)
}

playlistInfo.static.win.webContents.send('conversion-done', sendData)
});
}

var removeChild = (childPid) => {
this.childProcesses = this.childProcesses.filter(pid => pid != childPid)
}

var checkAvailability = (pendingVideo) => {
if (this.childProcesses.length == 4) return false
else return true
}

var checkPending = () => {
if (pendingProcesses.length == 0) return false
else return true
}
56 changes: 56 additions & 0 deletions main/kill-processes/app-notifications.js
@@ -0,0 +1,56 @@
var mp3Converter = require('../conversion/mp3Converter')

var kill = require('tree-kill')

// Variables for wich notification message should be shown
exports.exitMessages = {
download: null,
conversion: null,
}

// Value to show that now process is active
exports.noProcessActive = null

// Messages to show when closing the apliction if any process is active
exports.messages = {
download: 'Download in progress. Are you sure you want to quit?',
conversion: 'Conversion in progress. Are you sure you want to quit?'
}

// Notification options
exports.options = {
type: 'question',
buttons: ['Yes', 'No'],
title: 'Confirm',
message: ''
}

// Reset notification variables
exports.resetValues = () => {
this.exitMessages.download = null,
this.exitMessages.conversion = null,
this.noProcessActive = null
}

exports.killAllProcesses = (callback) => {

if (mp3Converter.childProcesses.length == 0) {
if (callback && typeof(callback) === "function") callback();
} else {
var initialLength = mp3Converter.childProcesses.length
var index = mp3Converter.childProcesses.length
var conditionLength = 0

while (index--) {

kill(mp3Converter.childProcesses[index], () => {
mp3Converter.childProcesses.splice(index, 1);
conditionLength++

if (conditionLength == initialLength)
if (callback && typeof(callback) === "function") callback();
})
}
}
}

0 comments on commit d76c37d

Please sign in to comment.