File size: 2,741 Bytes
a7bb3b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Proxy Configuration for yt-dlp
const proxyConfig = {
    enabled: false, // Tắt proxy theo yêu cầu
    
    // Single proxy - Proxy mới của chủ
    single: {
        type: 'socks5',
        host: '74.226.201.156',
        port: 1080,
        username: 'dunn',
        password: '1234',
    },
    
    // Proxy pool cho load balancing - Bao gồm proxy mới
    pool: [
        'socks5://dunn:[email protected]:1080', // Proxy mới của chủ
        'socks5://user1:[email protected]:1080',
        'socks5://user2:[email protected]:1080',
        'http://user3:[email protected]:8080',
        // Thêm nhiều proxy khác...
    ],
    
    // Cấu hình retry
    retry: {
        maxAttempts: 3,
        rotateOnFailure: true
    },
    
    // Proxy cho từng platform - Sử dụng proxy mới
    platformSpecific: {
        'youtube.com': 'socks5://dunn:[email protected]:1080',
        'facebook.com': 'socks5://dunn:[email protected]:1080',
        'instagram.com': 'socks5://dunn:[email protected]:1080',
        'tiktok.com': 'socks5://dunn:[email protected]:1080'
    },
    
    // Geo-targeting
    regions: {
        'US': ['socks5://us1.proxy.com:1080', 'socks5://us2.proxy.com:1080'],
        'EU': ['socks5://eu1.proxy.com:1080', 'socks5://eu2.proxy.com:1080'],
        'ASIA': ['socks5://asia1.proxy.com:1080', 'socks5://asia2.proxy.com:1080']
    }
};

// Utility functions
function getProxyUrl(config) {
    if (!config) return null;
    
    const auth = config.username && config.password 
        ? `${config.username}:${config.password}@` 
        : '';
    
    return `${config.type}://${auth}${config.host}:${config.port}`;
}

function getRandomProxy(pool) {
    if (!pool || pool.length === 0) return null;
    return pool[Math.floor(Math.random() * pool.length)];
}

function getProxyForUrl(url) {
    if (!proxyConfig.enabled) return null;
    
    // Kiểm tra platform-specific proxy
    for (const [platform, proxy] of Object.entries(proxyConfig.platformSpecific)) {
        if (url.includes(platform)) {
            return proxy;
        }
    }
    
    // Dùng proxy pool hoặc single proxy
    if (proxyConfig.pool && proxyConfig.pool.length > 0) {
        return getRandomProxy(proxyConfig.pool);
    }
    
    return getProxyUrl(proxyConfig.single);
}

function validateProxy(proxyUrl) {
    // Basic validation
    const proxyRegex = /^(socks5|http|https):\/\/(?:([^:]+):([^@]+)@)?([^:]+):(\d+)$/;
    return proxyRegex.test(proxyUrl);
}

module.exports = {
    proxyConfig,
    getProxyUrl,
    getRandomProxy,
    getProxyForUrl,
    validateProxy
};