41
41
42
42
import java .io .File ;
43
43
import java .io .IOException ;
44
+ import java .text .DecimalFormat ;
44
45
import java .util .ArrayList ;
45
46
import java .util .List ;
46
47
import java .util .Objects ;
@@ -81,6 +82,8 @@ private void initializeBot() throws IOException {
81
82
Log .WINFO (this .workerName , this .workerColor , "Initializing. . ." );
82
83
this .proxies = new Proxies (this .workerName , this .apiKey , this .workerColor );
83
84
this .userAgent = new UserAgent (this .driverType );
85
+
86
+
84
87
switch (this .driverType .name () )
85
88
{
86
89
case Constants .FIREFOX :
@@ -129,7 +132,9 @@ private void setFirefoxDriver() {
129
132
FirefoxProfile profile = new FirefoxProfile ();
130
133
FirefoxBinary binary = new FirefoxBinary (this .driverLocation );
131
134
LoggingPreferences logPrefs = new LoggingPreferences ();
132
-
135
+ System .setProperty (FirefoxDriver .SystemProperty .DRIVER_USE_MARIONETTE ,"true" );
136
+ // hide firefox logs from console
137
+ System .setProperty (FirefoxDriver .SystemProperty .BROWSER_LOGFILE ,"/tmp/rust_" );
133
138
134
139
profile .setPreference ("media.volume_scale" , "0.0" );
135
140
profile .setPreference ("general.useragent.override" , userAgent .randomUA ());
@@ -148,8 +153,8 @@ private void setFirefoxDriver() {
148
153
options .setBinary (binary );
149
154
// options.setProxy(this.proxies.getCurrentProxy());
150
155
options .setCapability ("proxy" , this .proxies .getCurrentProxy ());
151
-
152
156
this .webDriver = new FirefoxDriver (options );
157
+
153
158
Log .WINFO (this .workerName , this .workerColor , "Firefox Driver Set" );
154
159
}
155
160
@@ -161,8 +166,13 @@ private void setFirefoxDriver() {
161
166
* @throws ElementClickInterceptedException
162
167
* @throws NoSuchTitleException Our page doesnt end with YouTube, maybe there is an incorrect URL
163
168
*/
164
- private int setVideo () throws ElementClickInterceptedException , NoSuchTitleException {
169
+ private int setVideo () throws ElementClickInterceptedException {
170
+
165
171
this .webDriver .get (this .videoUrl );
172
+ String a = this .webDriver .getCurrentUrl ();
173
+ String j = this .webDriver .getTitle ();
174
+ System .out .println ("Your page title Is : " +j );
175
+ System .out .println ("Current URL Is : " +a );
166
176
167
177
if ( this .webDriver .getTitle ().endsWith ("YouTube" ) )
168
178
{
@@ -179,9 +189,41 @@ private int setVideo() throws ElementClickInterceptedException, NoSuchTitleExcep
179
189
if (this .watchLength == -1 ) {
180
190
return calculateWatchTime ( currentVideoTime , totalVideoTime );
181
191
} else {
182
- return this .watchLength * 1000 ;
192
+ // Randomize watch duration every visits,
193
+ int w = this .watchLength * 1000 ;
194
+ int max = w + 5000 ;
195
+ int min = w ;
196
+ int range = max - min + min ;
197
+ int rand = (int ) (Math .random ()* range ) + (min / 2 );
198
+ String pattern = "#,##,###.#" ;
199
+ DecimalFormat decimalFormat = new DecimalFormat (pattern );
200
+ String format = decimalFormat .format (rand / 1000 );
201
+
202
+ System .out .println ("Watch durtion: " +format +" Seconds" );
203
+ Log .WINFO (this .workerName , this .workerColor , "Bot Watching now...." );
204
+ return rand ;
205
+
183
206
}
184
- } else {
207
+ } else {
208
+ Log .WINFO (this .workerName , this .workerColor , "reCaptcha Showing!!" );
209
+ // STILL NOT WORKING FOR SOLVING RECAPTCHA PROBLEM, NEED RESTART VPS TO SOLVE THIS.
210
+ try {
211
+ // new WebDriverWait(this.webDriver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@name, 'a-') and starts-with(@src, 'https://www.google.com/recaptcha')]")));
212
+ // new WebDriverWait(this.webDriver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.recaptcha-checkbox-checkmark"))).click();
213
+ // WebElement iFrame = this.webDriver.findElement(By.xpath("html/body/div[1]/div[3]/div[2]/form/div[5]/div"));
214
+ // this.webDriver.switchTo().frame(iFrame);
215
+ Log .WINFO (this .workerName , this .workerColor , "iframe found!" );
216
+ }catch (Exception e ){
217
+ System .out .println ("ERROR: " +e );
218
+ }
219
+
220
+
221
+ // WebDriverWait(this.webDriver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "span#recaptcha-anchor"))).click()
222
+ // this.webDriver.switch_to.default_content()
223
+ // WebDriverWait(this.webDriver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[title='recaptcha challenge']")))
224
+ // WebDriverWait(this.webDriver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#recaptcha-audio-button"))).click()
225
+
226
+
185
227
throw new NoSuchTitleException (String .format ("Title does not end with YouTube, please ensure you have " +
186
228
"provided the correct URL to the video. Actual title: %s" , this .webDriver .getTitle ()));
187
229
}
@@ -195,6 +237,7 @@ private int setVideo() throws ElementClickInterceptedException, NoSuchTitleExcep
195
237
* @param videoLength The total lengtht of the video
196
238
* @return watchTime in millis
197
239
*/
240
+
198
241
private Integer calculateWatchTime ( String currentTime , String videoLength )
199
242
{
200
243
int [] curHMS = Stream .of (currentTime .split (":" )).mapToInt (Integer ::parseInt ).toArray ();
0 commit comments