Skip to content

Commit

Permalink
adding filesize for videos done
Browse files Browse the repository at this point in the history
  • Loading branch information
sndrjhlncgr committed Jun 27, 2020
1 parent c753160 commit ca4a72d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 35 deletions.
14 changes: 8 additions & 6 deletions routes/_utils/processClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,21 @@ const convertVideoAndAudio = async (url,videoFormats,res) => {
}
}

const mergeVideoAndAudio = async (tempFilename, filename, response) => {
const mergeVideoAndAudio = async (formats, response) => {
const {filename,videoFilename, video_formats: {qualityLabel}} = formats
const fullVid = new ffmpeg()
.addInput(Path.resolve(`./routes/api/files/${tempFilename}.mp4`))
.addInput(Path.resolve(`./routes/api/files/${tempFilename}.mp3`))
.saveToFile(Path.resolve(`./routes/api/files/${filename}.mp4`))
.addInput(Path.resolve(`./routes/api/files/${filename}.mp4`))
.addInput(Path.resolve(`./routes/api/files/${filename}.mp3`))
.saveToFile(Path.resolve(`./routes/api/files/${videoFilename}.mp4`))

await new Promise((resolve, reject) => {
fullVid.on('end', () => {
resolve(JSON.stringify({
type: 'MERGE_AUDIO_AND_VIDEO_SUCCESSFULLY',
payload: {
filePath: Path.resolve(`./routes/api/files/${filename}.mp4`),
filename: `${filename}.mp4`
filePath: Path.resolve(`./routes/api/files/${videoFilename}.mp4`),
filename: `${videoFilename}.mp4`,
quality: qualityLabel
},
}))
})
Expand Down
7 changes: 4 additions & 3 deletions routes/api/ytdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
const getFilesizeInBytes = async (filename) => {
let file = Fs.statSync(filename)
let bytes = file["size"]
var size = (bytes / 1000000.0) - 1.1
var size = bytes / 1000000.0 - 1.1
return size
}

Expand Down Expand Up @@ -47,7 +47,7 @@ router.get('/download/mp4', async (req, res) => {
})
}

await mergeVideoAndAudio(videoFormats.filename,videoFormats.videoFilename, async (response) => {
await mergeVideoAndAudio(videoFormats, async (response) => {
const action = JSON.parse(response)
switch(action.type) {
case 'MERGE_AUDIO_AND_VIDEO_SUCCESSFULLY':
Expand All @@ -57,7 +57,8 @@ router.get('/download/mp4', async (req, res) => {
type: action.type,
filename: action.payload.filename,
size: fileSize,
link: `/download/video/${action.payload.filename}`
link: `/download/video/${action.payload.filename}`,
quality: action.payload.quality,
})
} catch(err) {
res.json({
Expand Down
55 changes: 29 additions & 26 deletions src/components/types/videoList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class VideoList extends Component {
link: '',
filename:'',
type:'',
size: 0
size: 0,
quality: ''
}

render() {
Expand All @@ -35,31 +36,33 @@ class VideoList extends Component {
.{format.container}
</td>
<td>
{this.state.type.length === 0 ? <button type="button" className="btn btn-success btn-sm download-button" onClick={e => {
e.preventDefault();
const {url, info} = this.props
downloadMp4(url,format,info, (res) => {
switch(res.data.type) {
case 'MERGE_AUDIO_AND_VIDEO_SUCCESSFULLY':
this.setState({
link: res.data.link,
filename:res.data.filename,
type: res.data.type,
size: res.data.size
})
break;
default:
return ''
}
})
}}>Download <FontAwesomeIcon className="ml-1" icon={faChevronCircleDown}/></button>
:
<button onClick={(e) => {
e.preventDefault()
console.log(this.state)
window.location.href= `http://localhost:3000/api/download/video/${this.state.filename}`
}}>Download Link</button>
}
{this.state.quality !== format.qualityLabel ?
<button type="button" className="btn btn-success btn-sm download-button" onClick={e => {
e.preventDefault();
const {url, info} = this.props
downloadMp4(url,format,info, (res) => {
switch(res.data.type) {
case 'MERGE_AUDIO_AND_VIDEO_SUCCESSFULLY':
this.setState({
link: res.data.link,
filename:res.data.filename,
type: res.data.type,
size: res.data.size,
quality: res.data.quality
})
break;
default:
return ''
}
})
}}>Download <FontAwesomeIcon className="ml-1" icon={faChevronCircleDown}/></button>
:
<button onClick={(e) => {
e.preventDefault()
console.log(this.state)
// window.location.href= `http://localhost:3000/api/download/video/${this.state.filename}`
}}>Download Link</button>
}
</td>
</tr>
)
Expand Down

0 comments on commit ca4a72d

Please sign in to comment.