diff options
| author | 8cy <[email protected]> | 2020-06-11 06:25:53 -0700 |
|---|---|---|
| committer | 8cy <[email protected]> | 2020-06-11 06:25:53 -0700 |
| commit | d36a54b61f8aaa0e946d9326917e8dac3a10d8fc (patch) | |
| tree | 5afa376c1c331dae84f6bf8c9de28f6dd3d04a5d /server.js | |
| parent | make readme look "good" (diff) | |
| download | twittlet-d36a54b61f8aaa0e946d9326917e8dac3a10d8fc.tar.xz twittlet-d36a54b61f8aaa0e946d9326917e8dac3a10d8fc.zip | |
big update, read desc
you can check the updates below or see a more in-depth summary at the end.
big stuff:
- made a new api made which i then made the main mode and made the old mode the api mode )
- DARK MODE (using prefers colour scheme)
not so big stuff:
- made default err msg more tidy
- tidy up code and old debug stuff
- made error handling a little better
- changed all branding to twittlet to match the github repo
- added twitter waifu icon >_<
- different button text for different modes (why am i listing this ... )
so originally i was making a "api mode" which was not really api related, it was just a cleaner, better way of fetching the data without being redirected to the api. but once i finished that i made the old mode the api mode and made the new api mode the old mode/ main mode.
standard mode; grabs the four data types which the twitter api returns; three different sized mp4 files and a .m3u8 file. at the moment i havent added a handling method that displays the file sizes and/ or removes the m3u8 file from the listing (bc i its pretty useless). will be a target soon though probably.
api mode: just a gui to direct you to the api, kinda useless but there none-the-less.
Diffstat (limited to 'server.js')
| -rw-r--r-- | server.js | 72 |
1 files changed, 58 insertions, 14 deletions
@@ -2,6 +2,7 @@ const express = require('express'); const app = express(); const path = require('path'); const vul = require('video-url-link'); +const { default: Axios } = require('axios'); // side-note: this is best used with a api testing service like postman for now. reason being; when actually performing a query, // the page just spits out a bunch of json shit so it not super readable for now. @@ -15,34 +16,77 @@ app.set('view engine', 'ejs'); app.use(express.urlencoded({ extended: false })); app.set('json spaces', 2); +const defaultErrorMsg = 'This mode currently returns 4 different videos, once of which being a .m3u8 file. At the moment I haven\'t added a way to filter out this .m3u8 file. Honestly I don\'t know why Twitter doesn\'t have a consistent API standard, but that\'s beyond the point. Anyways, 4 files are returned, and of the three video mp4s, they are all different resolutions. I haven\'t added a way to detect the resolution of the video but that is probably simple enough and might be added later, for now, just hover over the links and check after the /vid/ area.'; + app.get('/', (req, res) => { - res.render('index', { error: '' }); + return res.render('index', { + error: defaultErrorMsg, + tAddon: '', + modeRef: '<a href="/api">API Mode</a>', + modeAction: '/download', + videoLinks: '', + buttonContext: 'Download Video' + }); +}); + +app.get('/api', (req, res) => { + return res.render('index', { + error: 'API mode basically just returns all the JSON data of your given URL.', + tAddon: '- API Mode', + modeRef: '<a href="/">Standard Mode</a>', + modeAction: '/submitData', + videoLinks: '', + buttonContext: 'Get API Data' + }); }); app.post('/submitData', (req, res) => { - //console.log(req.body.urlInput); let twitterPostURL = req.body.urlInput; if (twitterPostURL.length < 40) return res.redirect('/'); // 40 chars is the length of the entire twitter url without the protocol nor the user's handle let localURL = req.protocol + '://' + req.get('host'); // + req.originalUrl; - //console.log(localURL); - res.redirect(localURL + '/api/v1?video=' + twitterPostURL); + return res.redirect(localURL + '/api/v1?video=' + twitterPostURL); +}); + +app.post('/download', async (req, res) => { + let twitterPostURL = req.body.urlInput; + + if (twitterPostURL.length < 40) return res.redirect('/'); + // 40 chars is the length of the entire twitter url without the protocol nor the user's handle + + let localURL = req.protocol + '://' + req.get('host'); + + let APIDataRe = await Axios.get(localURL + '/api/v1?video=' + twitterPostURL); + let TwitterEndpoint = await APIDataRe.data.videoURLs; + + let videoList = '<ul>'; + let videoNum = 0; + TwitterEndpoint.forEach(video => { + videoList += '<li><a href="' + TwitterEndpoint[videoNum].url + '" target="_blank">Download Video ' + (videoNum + 1) + '</a></li>'; + videoNum++; + }); + videoList += '</ul>'; + + return res.render('index', { + error: defaultErrorMsg, + tAddon: '', + modeRef: '<a href="/api">API Mode</a>', + modeAction: '/download', + videoLinks: videoList, + buttonContext: 'Download Video' + }); }); app.get('/api/v1', (req, res) => { let videoURL = req.query.video; - //let video = 'https://twitter.com/threatenedcats/status/1269917580497522689'; - vul.twitter.getInfo(videoURL, {}, (error, info) => { - if (error) return console.log(error); + if (error) return res.redirect('/'); - //console.log(info.full_text); - //console.log(info.variants); - res.json({ + return res.json({ _comment: 'This is a link to the same Twitter post, except short.', videoURLShort: info.full_text, _comment2: 'These are links to the Twitter post media in various different formats.', @@ -55,10 +99,10 @@ app.get('/api/v1', (req, res) => { }); }); -// app.get('*', (req, res) => { -// res.redirect('/'); -// }); +app.get('*', (req, res) => { + return res.redirect('/'); +}); app.listen(1337, () => { console.log('Listening on port 1337'); -});
\ No newline at end of file +}); |