* chore(deps-dev): bump eslint-plugin-unicorn from 65.0.1 to 66.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 65.0.1 to 66.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v65.0.1...v66.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 66.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * style: fix unicorn-js/prefer-url-href * style: oxlint disable * style: fix unicorn-js/no-useless-else * style: no-unsafe-string-replacement * style: fix no-duplicate-loops * style: fix prefer-number-is-safe-integer * style: fix prefer-single-array-predicate * style: fix no-object-methods-with-collections * style: fix no-useless-boolean-cast * style: fix no-useless-template-literals * style: fix no-negated-array-predicate * style: fix prefer-direct-iteration * style: fix consistent-optional-chaining * style: fix prefer-simple-sort-comparator * style: fix prefer-global-number-constants * style: fix prefer-type-literal-last * style: fix require-array-sort-compare. * style: fix prefer-early-return * style: fix prefer-short-arrow-method * style: fix prefer-array-from-map * style: fix prefer-scoped-selector * style: fix no-global-object-property-assignment * style: fix no-unnecessary-global-this * style: fix no-unreadable-object-destructuring * style: fix no-invalid-argument-count * style: fix prefer-smaller-scope * style: fix prefer-iterator-to-array. * style: fix prefer-object-iterable-methods * style: fix typo * style: fix max-nested-calls * style: fix no-incorrect-template-string-interpolation * style: fix no-break-in-nested-loop * style: fix prefer-await * style: fix no-computed-property-existence-check * style: fix prefer-number-coercion * style: fix no-empty-file * style: update eslint unicorn v66 recommended preset * style: add unicorn/prefer-spread to oxlint-disable comments * style: fix no-array-reduce * style: delete github/no-then as it's covered by unicorn/prefer-await --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
137 lines
4.7 KiB
TypeScript
137 lines
4.7 KiB
TypeScript
import { load } from 'cheerio';
|
|
|
|
import type { Route } from '@/types';
|
|
import { ViewType } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import logger from '@/utils/logger';
|
|
import { parseRelativeDate } from '@/utils/parse-date';
|
|
import playwright from '@/utils/playwright';
|
|
|
|
export const route: Route = {
|
|
path: '/user/:id/:type?',
|
|
categories: ['social-media'],
|
|
example: '/picnob/user/xlisa_olivex',
|
|
parameters: {
|
|
id: 'Instagram id',
|
|
type: 'Type of profile page (profile or tagged)',
|
|
},
|
|
features: {
|
|
requireConfig: false,
|
|
requirePuppeteer: true,
|
|
antiCrawler: false,
|
|
supportBT: false,
|
|
supportPodcast: false,
|
|
supportScihub: false,
|
|
},
|
|
radar: [
|
|
{
|
|
source: ['www.picnob.com/profile/:id'],
|
|
target: '/user/:id',
|
|
},
|
|
{
|
|
source: ['www.picnob.com/profile/:id/tagged'],
|
|
target: '/user/:id/tagged',
|
|
},
|
|
],
|
|
name: 'User Profile - Picnob',
|
|
maintainers: ['TonyRL', 'micheal-death', 'AiraNadih', 'DIYgod', 'hyoban', 'Rongronggg9'],
|
|
handler,
|
|
view: ViewType.Pictures,
|
|
};
|
|
|
|
async function handler(ctx) {
|
|
const baseUrl = 'https://www.picnob.com';
|
|
const id = ctx.req.param('id');
|
|
const type = ctx.req.param('type') ?? 'profile';
|
|
const profileUrl = `${baseUrl}/profile/${id}/${type === 'tagged' ? 'tagged/' : ''}`;
|
|
|
|
const context = await playwright();
|
|
|
|
const page = await context.newPage();
|
|
await page.route('**/*', (route) => {
|
|
const request = route.request();
|
|
request.resourceType() === 'document' ? route.continue() : route.abort();
|
|
});
|
|
|
|
await page.goto(profileUrl, {
|
|
waitUntil: 'domcontentloaded',
|
|
});
|
|
logger.http(`Requesting ${profileUrl}`);
|
|
const html = await page.content();
|
|
const $ = load(html);
|
|
|
|
const list = $('.post_box')
|
|
.toArray()
|
|
.map((item) => {
|
|
const $item = $(item);
|
|
const coverLink = $item.find('.cover_link').attr('href');
|
|
const image = $item.find('.cover .cover_link img');
|
|
const alt = image.attr('alt') || '';
|
|
const sum = $item.find('.sum');
|
|
const title = sum.text().split('\n', 1)[0] || alt;
|
|
const content = sum.html()?.replaceAll('\n', '<br>') || alt;
|
|
|
|
return {
|
|
title,
|
|
description: `<img src="${image.attr('data-src')}"><br>${content}`,
|
|
link: `${baseUrl}${coverLink}`,
|
|
guid: coverLink?.split('/', 3)?.[2],
|
|
pubDate: parseRelativeDate($item.find('.time .txt').text()),
|
|
slideOrVideo: $item.find('.corner').length,
|
|
};
|
|
});
|
|
|
|
const items = await Promise.all(
|
|
list.map((item) =>
|
|
cache.tryGet(item.link, async () => {
|
|
let media = '';
|
|
|
|
if (item.slideOrVideo) {
|
|
const page = await context.newPage();
|
|
await page.route('**/*', (route) => {
|
|
const request = route.request();
|
|
request.resourceType() === 'document' ? route.continue() : route.abort();
|
|
});
|
|
|
|
await page.goto(item.link, {
|
|
waitUntil: 'domcontentloaded',
|
|
});
|
|
logger.http(`Requesting ${item.link}`);
|
|
const html = await page.content();
|
|
const $ = load(html);
|
|
|
|
media = $('.slide-item').length
|
|
? $('.slide-item div:first-of-type')
|
|
.toArray()
|
|
.map((item) => {
|
|
const $item = $(item);
|
|
if ($item.hasClass('video')) {
|
|
return $item.find('video').prop('outerHTML');
|
|
}
|
|
// $item.hasClass('pic')
|
|
$item.find('img').attr('src', $item.find('img').attr('data-src'));
|
|
$item.find('img').removeAttr('data-src');
|
|
return $item.html() || '';
|
|
})
|
|
.join('')
|
|
: $('.view .video').html() || '';
|
|
|
|
item.description = `${media}<br>${item.description}`;
|
|
}
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
await context.close();
|
|
|
|
return {
|
|
title: `${$('h1.fullname').text()} (@${id}) ${type === 'tagged' ? 'tagged' : 'public'} posts - Picnob`,
|
|
description: $('.info .sum').text(),
|
|
link: profileUrl,
|
|
image: $('.ava .pic img').attr('src'),
|
|
item: items,
|
|
};
|
|
}
|