class Animepictures { baseUrl = "https://anime-pictures.net"; constructor() { this.type = "image-board"; this.version = "1.0" } async search(query = "thighs", page = 1, perPage = 42) { const url = `${this.baseUrl}/posts?page=${page - 1}&search_tag=${query}&order_by=date&lang=en`; const { result } = await this.scrape( url, async (page) => { return page.evaluate(() => { const items = document.querySelectorAll('.img-block.img-block-big'); const results = []; items.forEach(div => { const link = div.querySelector('a'); const img = div.querySelector('img'); if (!link || !img) return; const href = link.getAttribute('href') || ""; const idMatch = href.match(/\/posts\/(\d+)/); const id = idMatch ? idMatch[1] : null; const imgUrl = img.getAttribute('src'); const tagsRaw = img.getAttribute('alt') || ""; const tags = tagsRaw.trim().split(/\s+/).filter(Boolean); if (id && imgUrl) { results.push({ id: id, //full res image: imgUrl.replace("opreviews", "oimages").replace("_cp.avif", ".jpeg"), image: imgUrl, tags: tags, }); } }); const nextPageBtn = document.querySelector('.numeric_pages a.desktop_only'); const hasNextPage = !!nextPageBtn; return {results, hasNextPage}; }); }, { waitSelector: '.img-block.img-block-big', timeout: 15000 } ); return { results: result.results, hasNextPage: result.hasNextPage, page, //headers: { // "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36", // "Accept": "image/avif,image/webp,image/apng,image/*,*/*;q=0.8", // "Accept-Language": "en-US,en;q=0.9", // "Referer": "https://anime-pictures.net/", // "Sec-Fetch-Dest": "document", // "Sec-Fetch-Mode": "navigate", // "Sec-Fetch-Site": "none", // "Sec-Fetch-User": "?1" //} }; } async getInfo(id) { const url = `${this.baseUrl}/posts/${id}?lang=en`; const { result } = await this.scrape( url, async (page) => { return page.evaluate(() => { const img = document.querySelector('#big_preview'); const image = img ? img.src : null; const tagLinks = document.querySelectorAll('.tags li a'); const tags = [...tagLinks].map(a => a.textContent.trim()); return {image, tags}; }); }, { waitSelector: '#big_preview', timeout: 15000 } ); return { id, image: result.image, tags: result.tags, }; } } module.exports = Animepictures;