forked from elrebelde21/LoliBot-MD
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62101ee
commit fe482ca
Showing
1 changed file
with
69 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |