rynn-k / gists
android1.js javascript
const axios = require('axios');
const cheerio = require('cheerio');

class Android1 {
    search = async function (query) {
        try {
            if (!query) throw new Error('Query is required.');
            
            const { data } = await axios.get(`https://an1.com/?story=${encodeURIComponent(query)}&do=search&subaction=search`);
            const $ = cheerio.load(data);
            const items = [];
            
            $('.item .item_app').each((_, el) => {
                items.push({
                    name: $(el).find('.name a span').text().trim(),
                    developer: $(el).find('.developer').text().trim(),
                    rating: parseFloat($(el).find('.current-rating').css('width')) / 20 || 0,
                    icon: $(el).find('.img img').attr('src') || null,
                    url: $(el).find('.name a').attr('href') || null,
                });
            });
            
            return items;
        } catch (error) {
            throw new Error(error.message);
        }
    }
    
    detail = async function (url) {
        try {
            if (!url?.includes('an1.com')) throw new Error('Invalid url.');
            
            const { data } = await axios.get(url);
            const $ = cheerio.load(data);
            
            const ratingLayerId = $('[id^="ratig-layer-"]').attr('id');
            const appId = ratingLayerId?.replace('ratig-layer-', '');
            
            const screenshots = [];
            $('.app_screens_list a img').each((_, el) => {
                const src = $(el).attr('src');
                if (src) screenshots.push(src.replace('/thumbs/', '/'));
            });
            
            return {
                title: $('h1[itemprop="headline"]').text().trim() || 'N/A',
                icon: $('figure.img img').attr('src') || null,
                developer: $('[itemprop="publisher"] [itemprop="name"]').text().trim() || 'N/A',
                description: $('[itemprop="description"]').text().trim() || 'N/A',
                version: $('[itemprop="softwareVersion"]').text().trim() || 'N/A',
                file_size: $('[itemprop="fileSize"]').text().trim() || 'N/A',
                operating_system: $('[itemprop="operatingSystem"]').text().trim() || 'N/A',
                rating: parseFloat($(`#ratig-layer-${appId} .current-rating`).css('width')) / 20 || 0,
                rating_count: $(`#vote-num-id-${appId}`).text().trim() || '0',
                updated: $('time[itemprop="datePublished"]').text().trim() || 'N/A',
                screenshots,
                download_page: 'https://an1.com' + ($('.download_line.green').attr('href') || ''),
            };
        } catch (error) {
            throw new Error(error.message);
        }
    }
    
    download = async function (url) {
        try {
            if (!url?.includes('an1.com')) throw new Error('Invalid url.');
            
            const { data } = await axios.get(url);
            const $ = cheerio.load(data);
            
            const dlPath = $('.download_line.green').attr('href');
            if (!dlPath) throw new Error('Download link not found.');
            
            const { data: dlPage } = await axios.get('https://an1.com' + dlPath);
            const $$ = cheerio.load(dlPage);
            
            return {
                filename: $$('h1.title').text().trim() || 'N/A',
                icon: $$('.box-file-img img').attr('src') || null,
                version: $$('h1.title').text().match(/[\d.]+\.apk/)?.[0]?.replace('.apk', '') || 'N/A',
                download_url: $$('#pre_download').attr('href') || 'N/A',
            };
        } catch (error) {
            throw new Error(error.message);
        }
    }
}

// Usage:
const a = new Android1();
a.download('https://an1.com/4683-subway-surfers-mod-apk-8.html').then(console.log);
3873 bytes ยท Updated Mar 10, 2026