Comments (2)
@kudlav I tried to implement this feature.
I added this code section to controllers/apiController.js
.
const download = require('download');
...
exports.projectRemoteFilePOST = (req, res, next) => {
let url = req.body.url;
let filename = url.split('/');
filename = filename[filename.length - 1];
const fileID = nanoid();
const extension = path.extname(filename);
let filepath = path.join(config.projectPath, req.params.projectID, fileID);
if (extension.length > 1) filepath += extension;
log.info(`Save of "${filename}" from "${url}" started`);
console.log('save remote file ', url);
// // Create a write stream of the new file
let mimeType = 'video/mp4';
const fstream = fs.createWriteStream(filepath);
fstream.on('finish', () => {
log.info(`Save of "${filename}" from "${url}" finished`);
console.log('download finished');
fileManager.getDuration(filepath, mimeType).then(
length => {
projectManager.load(req.params.projectID, 'w').then(
([document, , release]) => {
const node = document.createElement('producer');
node.id = 'producer' + fileID;
node.innerHTML = `<property name="resource">${path.resolve(filepath)}</property>`;
node.innerHTML += `<property name="musecut:mime_type">${mimeType}</property>`;
node.innerHTML += `<property name="musecut:name">${filename}</property>`;
if (length !== null) {
if (timeManager.isValidDuration(length))
node.innerHTML += `<property name="length">${length}</property>`;
else {
length = null;
log.fatal(`Unable to get duration of ${mimeType}: ${filepath}`);
}
}
const root = document.getElementsByTagName('mlt').item(0);
root.prepend(node);
projectManager.save(req.params.projectID, root.outerHTML, release).then(
() => res.json({
msg: `Upload of "${filename}" OK`,
resource_id: fileID,
resource_mime: mimeType,
length: length,
}),
err => next(err)
);
},
err => fileErr(err, res)
);
}
);
})
fstream.on('error', () => errorResponse(error.projectNotFound404, res));
try {
download(url).pipe(fstream);
} catch (_) {
console.log('download failed')
}
};
And I added route
router.post('/api/project/:projectID/url', apiController.projectRemoteFilePOST);
I can't confirm that this way is absolutely right.
Anyway, it works properly.
from videoeditor.
Hi @pegasus1982, thanks for the code. It looks simply, with some changes I will implement it. I would rather use "node-fetch" library as I already have this library as dev-dependency and it allow me to access Content-Type header containing mime-type (you have mime-type hardcoded to 'video/mp4').
from videoeditor.
Related Issues (20)
- Show percentage progress when rendering HOT 1
- Use custom modal for image length input
- Ability to remove project according to GDPR
- Use Web sockets for getting data
- Improve React/JS eslint rules, use CI HOT 1
- Timeline is completely broken due v5 changes HOT 1
- Show sprites on timeline HOT 5
- Translate API response strings into English, allow to use Czech via param
- some issue on first installation HOT 5
- Issue on click video HOT 1
- Have problems when build your project
- Anyone have Docker container for this project ??
- Multiple RW access of same project cause collision HOT 1
- musecut:filter is parameter, not filter attribute HOT 1
- Add React props declaration according ESLint rule
- Logs without console.log, make messages clear
- Firefox freezes when finishing file upload
- Zoom to all objects only when adding new item HOT 1
- Video preview HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from videoeditor.