forked from jeckman/YouTube-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolkit.php
62 lines (55 loc) · 1.68 KB
/
Toolkit.php
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
<?php
/*
* PHP script for downloading videos from youtube
* Copyright (C) 2012-2018 John Eckman
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/>.
*/
namespace YoutubeDownloader;
use Exception;
use YoutubeDownloader\VideoInfo\VideoInfo;
/**
* Toolkit
*
* This class contains all functionallities that must be refactored.
*/
class Toolkit
{
/**
* @var string random IP
*/
private $outgoing_ip;
/**
* Select random IP from config
*
* If multipleIPs mode is enabled, select randomly one IP from
* the config IPs array and put it in $outgoing_ip variable.
*
* @param Config $config
*
* @return string|null The IP or null
*/
public function getRandomIp(Config $config)
{
if ($config->get('multipleIPs') !== true) {
return null;
}
if ($this->outgoing_ip === null) {
// randomly select an ip from the $config->get('IPs') array
$ips = $config->get('IPs');
$this->outgoing_ip = $ips[mt_rand(0, count($ips) - 1)];
}
return $this->outgoing_ip;
}
}