| 123456789101112131415161718192021222324252627282930313233343536373839 |
- #!/usr/bin/env node
- const https = require('https');
- function resolveOne(url) {
- return new Promise((r) => {
- const u = new URL(url);
- const req = https.request({
- hostname: u.hostname, path: u.pathname + u.search, method: 'GET',
- headers: {
- 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1',
- Accept: 'text/html,*/*',
- },
- }, (res) => {
- console.log(url, ' status=', res.statusCode, ' loc=', res.headers.location || '(no redirect)');
- const chunks = [];
- res.on('data', (c) => chunks.push(c));
- res.on('end', () => {
- const body = Buffer.concat(chunks).toString('utf-8');
- const m1 = (res.headers.location || '').match(/\/(?:share\/video|video)\/(\d+)/);
- const m2 = body.match(/video\/(\d{15,})/) || body.match(/"aweme_id"\s*:\s*"(\d+)"/) || body.match(/itemId=(\d+)/);
- console.log(' from loc:', m1 ? m1[1] : '-', '| from body:', m2 ? m2[1] : '-', '| body len:', body.length);
- r();
- });
- });
- req.on('error', (e) => { console.log(e.message); r(); });
- req.setTimeout(15000, () => { req.destroy(); r(); });
- req.end();
- });
- }
- (async () => {
- for (const u of [
- 'https://v.douyin.com/BMklXPTyiUM/',
- 'https://v.douyin.com/1eV76OP0FNM/',
- 'https://v.douyin.com/C3mMbhRYKHw/',
- ]) {
- await resolveOne(u);
- }
- })();
|