Skip to content

Commit

Permalink
𝙇𝙤𝙡𝙞𝘽𝙤𝙩
Browse files Browse the repository at this point in the history
  • Loading branch information
elrebelde21 authored Feb 24, 2024
1 parent 62101ee commit fe482ca
Showing 1 changed file with 69 additions and 55 deletions.
124 changes: 69 additions & 55 deletions lib/webp2mp4.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,79 @@
import fetch from 'node-fetch';
import {FormData, Blob} from 'formdata-node';
import {JSDOM} from 'jsdom';
import {
FormData,
Blob
} from 'formdata-node';
import {
JSDOM
} from 'jsdom';
/**
*
* @param {Buffer|String} source
*
* @param {Buffer|String} source
*/
async function webp2mp4(source) {
const form = new FormData();
const isUrl = typeof source === 'string' && /https?:\/\//.test(source);
const blob = !isUrl && new Blob([source.toArrayBuffer()]);
form.append('new-image-url', isUrl ? blob : '');
form.append('new-image', isUrl ? '' : blob, 'image.webp');
const res = await fetch('https://s6.ezgif.com/webp-to-mp4', {
method: 'POST',
body: form,
});
const html = await res.text();
const {document} = new JSDOM(html).window;
const form2 = new FormData();
const obj = {};
for (const input of document.querySelectorAll('form input[name]')) {
obj[input.name] = input.value;
form2.append(input.name, input.value);
}
const res2 = await fetch('https://ezgif.com/webp-to-mp4/' + obj.file, {
method: 'POST',
body: form2,
});
const html2 = await res2.text();
const {document: document2} = new JSDOM(html2).window;
return new URL(document2.querySelector('div#output > p.outfile > video > source').src, res2.url).toString();
let form = new FormData()
let isUrl = typeof source === 'string' && /https?:\/\//.test(source)
const blob = !isUrl && new Blob([source.toArrayBuffer()])
form.append('new-image-url', isUrl ? blob : '')
form.append('new-image', isUrl ? '' : blob, 'image.webp')
let res = await fetch('https://ezgif.com/webp-to-mp4', {
method: 'POST',
body: form
})
let html = await res.text()
let {
document
} = new JSDOM(html).window
let form2 = new FormData()
let obj = {}
for (let input of document.querySelectorAll('form input[name]')) {
obj[input.name] = input.value
form2.append(input.name, input.value)
}
let res2 = await fetch('https://ezgif.com/webp-to-mp4/' + obj.file, {
method: 'POST',
body: form2
})
let html2 = await res2.text()
let {
document: document2
} = new JSDOM(html2).window
return new URL(document2.querySelector('div#output > p.outfile > video > source').src, res2.url).toString()
}

async function webp2png(source) {
const form = new FormData();
const isUrl = typeof source === 'string' && /https?:\/\//.test(source);
const blob = !isUrl && new Blob([source.toArrayBuffer()]);
form.append('new-image-url', isUrl ? blob : '');
form.append('new-image', isUrl ? '' : blob, 'image.webp');
const res = await fetch('https://s6.ezgif.com/webp-to-png', {
method: 'POST',
body: form,
});
const html = await res.text();
const {document} = new JSDOM(html).window;
const form2 = new FormData();
const obj = {};
for (const input of document.querySelectorAll('form input[name]')) {
obj[input.name] = input.value;
form2.append(input.name, input.value);
}
const res2 = await fetch('https://ezgif.com/webp-to-png/' + obj.file, {
method: 'POST',
body: form2,
});
const html2 = await res2.text();
const {document: document2} = new JSDOM(html2).window;
return new URL(document2.querySelector('div#output > p.outfile > img').src, res2.url).toString();
let form = new FormData()
let isUrl = typeof source === 'string' && /https?:\/\//.test(source)
const blob = !isUrl && new Blob([source.toArrayBuffer()])
form.append('new-image-url', isUrl ? blob : '')
form.append('new-image', isUrl ? '' : blob, 'image.webp')
let res = await fetch('https://ezgif.com/webp-to-png', {
method: 'POST',
body: form
})
let html = await res.text()
let {
document
} = new JSDOM(html).window
let form2 = new FormData()
let obj = {}
for (let input of document.querySelectorAll('form input[name]')) {
obj[input.name] = input.value
form2.append(input.name, input.value)
}
let res2 = await fetch('https://ezgif.com/webp-to-png/' + obj.file, {
method: 'POST',
body: form2
})
let html2 = await res2.text()
let {
document: document2
} = new JSDOM(html2).window
return new URL(document2.querySelector('div#output > p.outfile > img').src, res2.url).toString()
}

export {
webp2mp4,
webp2png,
};
webp2mp4,
webp2png
}
// By @nm9h

0 comments on commit fe482ca

Please sign in to comment.