Skip to content

Commit

Permalink
Player de musica, mudança de icone
Browse files Browse the repository at this point in the history
  • Loading branch information
Iago Cavalcante committed Jul 24, 2018
1 parent 19df13f commit 6dcf950
Show file tree
Hide file tree
Showing 14 changed files with 303 additions and 71 deletions.
Binary file not shown.
18 changes: 12 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "ytdown",
"name": "qtube",
"version": "1.0.0",
"description": "App to copy link and paste, download from youtube",
"productName": "YoTDownload",
"cordovaId": "org.cordova.quasar.app",
"productName": "QTube",
"cordovaId": "br.com.qtube.app",
"author": "Iago Cavalcante <[email protected]>",
"private": true,
"scripts": {
Expand All @@ -16,6 +16,7 @@
"cors": "^2.8.4",
"electron-store": "^2.0.0",
"express": "^4.16.3",
"fluent-ffmpeg": "^2.1.2",
"request": "^2.87.0",
"video.js": "^7.0.5",
"vue-i18n": "^7.3.3",
Expand Down
4 changes: 2 additions & 2 deletions quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function (ctx) {
return {
// app plugins (/src/plugins)
plugins: [
'i18n',
// 'i18n',
'axios',
'video-player'
],
Expand Down Expand Up @@ -84,7 +84,7 @@ module.exports = function (ctx) {
'Notify'
],
// iconSet: ctx.theme.mat ? 'material-icons' : 'ionicons'
i18n: 'pt-Br' // Quasar language
// i18n: 'pt-Br' // Quasar language
},
// animations: 'all' --- includes all animations
animations: [
Expand Down
Binary file modified src-electron/icons/linux-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 18 additions & 14 deletions src-electron/main-process/electron-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ if (process.env.PROD) {
global.__statics = require('path').join(__dirname, 'statics').replace(/\\/g, '\\\\')
}

const path = `${app.getPath('documents')}/Ytdown/`.replace(/\\/g, '/')
const defaultPath = `${app.getPath('downloads')}/Ytdown/`.replace(/\\/g, '/')

let mainWindow

function createWindow () {
Expand All @@ -33,7 +34,7 @@ function createWindow () {
mainWindow = null
})

server.listen(path)
server.listen(defaultPath)
}

ipcMain.on('close-app', (event) => {
Expand All @@ -47,9 +48,6 @@ ipcMain.on('minimize', (event) => {
})

ipcMain.on('createYtDownFolder', function (event) {
//check if the default folder exists
let defaultPath = app.getPath('documents') + '/Ytdown'
defaultPath = defaultPath.replace(/\\/g, '/') //replaces "frontlaces" with backslashes

if (!fs.existsSync(defaultPath)) { //check if default folder already exists
fs.mkdirSync(defaultPath, '0o765')
Expand All @@ -61,8 +59,7 @@ ipcMain.on('createYtDownFolder', function (event) {
})

ipcMain.on('createVideosFolder', function (event) {
let videosPath = app.getPath('documents') + '/Ytdown/videos'
videosPath = videosPath.replace(/\\/g, '/') //replaces "frontlaces" with backslashes
const videosPath = `${defaultPath}/videos`.replace(/\\/g, '/')
if (!fs.existsSync(videosPath)) { //check if default folder already exists
fs.mkdirSync(videosPath, '0o765')
event.returnValue = videosPath
Expand All @@ -72,8 +69,7 @@ ipcMain.on('createVideosFolder', function (event) {
})

ipcMain.on('createDatabaseFolder', function (event) {
let databasePath = app.getPath('documents') + '/Ytdown/database'
databasePath = databasePath.replace(/\\/g, '/') //replaces "frontlaces" with backslashes
const databasePath = `${defaultPath}/database`.replace(/\\/g, '/')
if (!fs.existsSync(databasePath)) { //check if default folder already exists
fs.mkdirSync(databasePath, '0o765')
event.returnValue = databasePath
Expand All @@ -82,12 +78,22 @@ ipcMain.on('createDatabaseFolder', function (event) {
}
})

ipcMain.on('createMusicFolder', function (event) {
const musicsPath = `${defaultPath}/musics`.replace(/\\/g, '/')
if (!fs.existsSync(musicsPath)) { //check if default folder already exists
fs.mkdirSync(musicsPath, '0o765')
event.returnValue = musicsPath
} else {
event.returnValue = musicsPath
}
})

ipcMain.on('createFileDatabase', function (event) {
let databasePath = app.getPath('documents') + '/Ytdown/database'
databasePath = databasePath.replace(/\\/g, '/') //replaces "frontlaces" with backslashes
const databasePath = `${defaultPath}/database`.replace(/\\/g, '/')
if (!fs.existsSync(`${databasePath}/ytdown.json`)) {
const yt = {
ytdown: []
videos: [],
musics: [],
}
fs.writeFileSync(`${databasePath}/ytdown.json`, JSON.stringify(yt))
event.returnValue = `${databasePath}/ytdown.json`
Expand All @@ -97,8 +103,6 @@ ipcMain.on('createFileDatabase', function (event) {
})

ipcMain.on('getFolderApp', (event) => {
let defaultPath = app.getPath('documents') + '/Ytdown'
defaultPath = defaultPath.replace(/\\/g, '/') //replaces "frontlaces" with backslashes
event.returnValue = defaultPath
})

Expand Down
100 changes: 88 additions & 12 deletions src-electron/main-process/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ const { promisify } = require('util')
const cors = require('cors')
const getInfoVideo = promisify(ytdl.getInfo)
const modules = require('./modules')
const request = require('request');

const request = require('request')
const ffmpeg = require('fluent-ffmpeg')
export const listen = (__statics) => {
const app = express()

app.use(bodyParser.json({ limit: '250mb' }));
app.use(bodyParser.urlencoded({ limit: '250mb', extended: true }));
app.use(cors())
app.use(express.static(path.join(__statics, 'videos')))

app.post('/api/download', async (req, res) => {
try {
const info = await getInfoVideo(req.body.youtubeUrl.replace('https://www.youtube.com/watch?v=', ''))
Expand All @@ -32,7 +32,77 @@ export const listen = (__statics) => {
res.status(500).json(err)
}
})


app.post('/api/download-mp3', async (req, res) => {
try {
const videoId = req.body.youtubeUrl.replace('https://www.youtube.com/watch?v=', '')
const info = await getInfoVideo(videoId)
const title = info.title.replace(/[!?@#$%^&*|\.\;]/g, "")
modules.manipulateFiles.createDir(path.join(__statics, `musics/${title}/`))
const stream = ytdl(videoId, {
quality: 'highestaudio',
filter: 'audioonly',
})
ffmpeg(stream)
.audioBitrate(128)
.save(path.join(__statics, `musics/${title}/${title}.mp3`))
.on('progress', (p) => {
console.log(`${p.targetSize}kb downloaded`);
})
.on('end', () => {
request.post('http://localhost:3000/api/thumbnail', { form: { info: info, type: 'mp3' } })
res.status(200).json({ musicLink: path.join(__statics, `musics/${title}/${title}.mp3`) })
})
} catch (err) {
res.status(500).json(err)
}
})

app.post('/api/download-playlist', async (req, res) => {
try {
const videoId = req.body.youtubeUrl
const info = await getInfoVideo(videoId)
const title = info.title.replace(/[!?@#$%^&*|\.\;]/g, "")
modules.manipulateFiles.createDir(path.join(__statics, `musics/${title}/`))
playlist(videoId, title)
res.status(200).json({ musicLink: path.join(__statics, `musics/${title}/${title}.mp3`) })
} catch (err) {
res.status(500).json(err)
}
})

const playlist = (videoId, title) => {
const stream = ytdl(videoId, {
quality: 'highestaudio',
filter: 'audioonly',
})

stream.on('error', function error(err) {
console.log(err.stack);
});

var size = 0;
stream.on('info', function (info) {
size = info.size;
var output = path.join(__statics, `musics/${title}/${title}.mp3`);
stream.pipe(fs.createWriteStream(output));
});

var pos = 0;
stream.on('data', function data(chunk) {
pos += chunk.length;
// `size` should not be 0 here.
if (size) {
var percent = (pos / size * 100).toFixed(2);
process.stdout.cursorTo(0);
process.stdout.clearLine(1);
process.stdout.write(percent + '%');
}
});

stream.on('next', playlist);
}

app.get('/api/infos', (req, res) => {
fs.readFile(path.join(__statics, 'database/ytdown.json'), function (err, content) {
if (err) console.log(err)
Expand All @@ -41,32 +111,38 @@ export const listen = (__statics) => {
res.status(200).json(yt)
})
})

app.post('/api/thumbnail', (req, res) => {
const info = req.body.info
const type = req.body.type
const title = info.title.replace(/[!?@#$%^&*|\.\;]/g, "")
request.get(info.thumbnail_url).pipe(fs.createWriteStream(path.join(__statics, `videos/${title}/${title}.jpg`)))
const filePath = type === 'mp3' ? path.join(__statics, `musics/${title}/${title}.jpg`) : path.join(__statics, `videos/${title}/${title}.jpg`)
request.get(info.thumbnail_url).pipe(fs.createWriteStream(filePath))
.on('finish', () => {
request.post('http://localhost:3000/api/insert', { form: { info: info } })
request.post('http://localhost:3000/api/insert', { form: { info: info, type: type } })
res.status(200).json({ img: `ok` })
})
})

app.post('/api/insert', (req, res) => {
const info = req.body.info
const type = req.body.type
const title = info.title.replace(/[!?@#$%^&*|\.\;]/g, "")
const ytdown = {
title: title,
description: info.description,
thumbnail: `videos/${title}/${title}.jpg`,
src: `videos/${title}/${title}.mp4`
thumbnail: type === 'mp3' ? `musics/${title}/${title}.jpg` : `videos/${title}/${title}.jpg`,
src: type === 'mp3' ? `musics/${title}/${title}.mp3` : `videos/${title}/${title}.mp4`
}
let yt = {}
fs.readFile(path.join(__statics, 'database/ytdown.json'), function (err, content) {
if (err) console.log(err)
// if (err) res.status(500).json({ error: 'impossible insert data' })
yt = JSON.parse(content)
yt.ytdown.push(ytdown)
if (type === 'mp3')
yt.musics.push(ytdown)
else
yt.videos.push(ytdown)
fs.writeFile(path.join(__statics, 'database/ytdown.json'), JSON.stringify(yt), function (err) {
// if (err) res.status(500).json({ error: 'impossible insert data' })
if (err) console.log(err)
Expand Down
10 changes: 7 additions & 3 deletions src/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
>
<q-route-tab slot="title" to="/index" icon="get_app" replace label="Download" />
<q-route-tab slot="title" to="/videos" icon="perm_media" replace label="Videos" />
<q-route-tab slot="title" to="/musics" icon="queue_music" replace label="Musics" />
<q-route-tab slot="title" :to="path" icon="theaters" replace label="Player" />
<q-tab class="minimize" slot="title" @click="minimizeApp()" icon="minimize" replace label="Minimize" />
<q-tab class="absolute-right" slot="title" @click="closeApp()" icon="power_settings_new" replace label="Poweroff" />
Expand Down Expand Up @@ -46,13 +47,16 @@ export default {
ipcRenderer.send('minimize')
},
videoSelected () {
const selected = JSON.parse(window.localStorage.getItem('video'))
this.path.params.src = selected.src
this.path.params.img = selected.thumbnail
const selected = JSON.parse(window.localStorage.getItem('media'))
if (selected) {
this.path.params.src = selected.src
this.path.params.img = selected.thumbnail
}
},
initialize () {
ipcRenderer.sendSync('createYtDownFolder')
ipcRenderer.sendSync('createVideosFolder')
ipcRenderer.sendSync('createMusicFolder')
ipcRenderer.sendSync('createDatabaseFolder')
ipcRenderer.sendSync('createFileDatabase')
}
Expand Down
Loading

0 comments on commit 6dcf950

Please sign in to comment.