Skip to content

Commit 6a93c46

Browse files
author
Mark Tripoli
authored
Merge pull request #10 from h4ckm3-id/JYTB-Linux-Firefox
Jytb linux firefox - LGTM.
2 parents 3a4fcd7 + 4dffaab commit 6a93c46

File tree

3 files changed

+83
-20
lines changed

3 files changed

+83
-20
lines changed

src/main/java/com/triippztech/app/models/Proxies.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import java.io.IOException;
3434
import java.util.*;
35+
import java.util.logging.Level;
3536

3637
public class Proxies {
3738
private final String protoType = "https";
@@ -96,26 +97,36 @@ private void refreshProxies()
9697
this.proxies = null;
9798
this.generateProxies();
9899
}
99-
100-
private void loadNewProxy()
101-
{
100+
// fix randomproxy problem
101+
private void loadNewProxy() {
102+
Log.WWARN(workerName, workerColor,"Load new proxies");
102103
this.usedProxies.add(this.getCurrentProxyModel());
103104
Datum proxy = randomProxy();
104-
if ( isUsed(proxy) )
105-
this.loadNewProxy();
106-
else {
107-
this.setCurrentProxyModel(proxy);
108-
this.setCurrentProxy(proxy);
109-
}
105+
if ( isUsed(proxy) ) {
106+
try {
107+
Log.WWARN(workerName, workerColor,"proxy already used");
108+
Thread.sleep(3000);
109+
Log.WWARN(workerName, workerColor,"Refreshing Proxy list...");
110+
this.refreshProxies();
111+
} catch (InterruptedException e) {
112+
e.printStackTrace();
113+
}
114+
}
115+
else {
116+
this.setCurrentProxyModel(proxy);
117+
this.setCurrentProxy(proxy);
118+
}
119+
110120
}
111121

122+
123+
112124
private Boolean isUsed(Datum proxy)
113125
{
114126
return usedProxies.contains(proxy);
115127
}
116128

117-
private Datum randomProxy()
118-
{
129+
private Datum randomProxy() {
119130
return proxies.getData().get(new Random().nextInt(proxies.getData().size()));
120131
}
121132

src/main/java/com/triippztech/app/services/BotWorker.java

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
import java.io.File;
4343
import java.io.IOException;
44+
import java.text.DecimalFormat;
4445
import java.util.ArrayList;
4546
import java.util.List;
4647
import java.util.Objects;
@@ -81,6 +82,8 @@ private void initializeBot() throws IOException {
8182
Log.WINFO(this.workerName, this.workerColor, "Initializing. . .");
8283
this.proxies = new Proxies(this.workerName, this.apiKey, this.workerColor);
8384
this.userAgent = new UserAgent(this.driverType);
85+
86+
8487
switch (this.driverType.name() )
8588
{
8689
case Constants.FIREFOX:
@@ -129,7 +132,9 @@ private void setFirefoxDriver() {
129132
FirefoxProfile profile = new FirefoxProfile();
130133
FirefoxBinary binary = new FirefoxBinary(this.driverLocation);
131134
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_");
133138

134139
profile.setPreference("media.volume_scale", "0.0");
135140
profile.setPreference("general.useragent.override", userAgent.randomUA());
@@ -148,8 +153,8 @@ private void setFirefoxDriver() {
148153
options.setBinary(binary);
149154
// options.setProxy(this.proxies.getCurrentProxy());
150155
options.setCapability("proxy", this.proxies.getCurrentProxy());
151-
152156
this.webDriver = new FirefoxDriver(options);
157+
153158
Log.WINFO(this.workerName, this.workerColor, "Firefox Driver Set");
154159
}
155160

@@ -161,8 +166,13 @@ private void setFirefoxDriver() {
161166
* @throws ElementClickInterceptedException
162167
* @throws NoSuchTitleException Our page doesnt end with YouTube, maybe there is an incorrect URL
163168
*/
164-
private int setVideo() throws ElementClickInterceptedException, NoSuchTitleException {
169+
private int setVideo() throws ElementClickInterceptedException {
170+
165171
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);
166176

167177
if ( this.webDriver.getTitle().endsWith("YouTube") )
168178
{
@@ -179,9 +189,41 @@ private int setVideo() throws ElementClickInterceptedException, NoSuchTitleExcep
179189
if (this.watchLength == -1) {
180190
return calculateWatchTime( currentVideoTime, totalVideoTime );
181191
} 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+
183206
}
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+
185227
throw new NoSuchTitleException(String.format("Title does not end with YouTube, please ensure you have " +
186228
"provided the correct URL to the video. Actual title: %s", this.webDriver.getTitle()));
187229
}
@@ -195,6 +237,7 @@ private int setVideo() throws ElementClickInterceptedException, NoSuchTitleExcep
195237
* @param videoLength The total lengtht of the video
196238
* @return watchTime in millis
197239
*/
240+
198241
private Integer calculateWatchTime ( String currentTime, String videoLength )
199242
{
200243
int[] curHMS = Stream.of(currentTime.split(":")).mapToInt(Integer::parseInt).toArray();

src/main/java/com/triippztech/app/services/DriverConfiguration.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
public class DriverConfiguration {
2828
// macOS
29-
private final static String FIREFOX_MAC = "/Applications/Firefox.app/Contents/MacOS/firefox";
29+
private final static String FIREFOX_MAC = "Applications/firefox.app";
3030
private final static String CHROME_MAC = "/Applications/Google Chrome.app";
3131
private final static String OPERA_MAC = "/Applications/Opera.app";
3232
private final static String SAFARI_MAC = "/Applications/Safari.app";
@@ -42,6 +42,8 @@ public class DriverConfiguration {
4242
private final static String OPERA_WIN_32 = "";
4343

4444
// LINUX
45+
private final static String FIREFOX_LINUX = "/usr/bin/firefox";
46+
private final static String CHROME_LINUX = "/usr/bin/chromium";
4547

4648
@SuppressWarnings("Duplicates")
4749
public static void validateDriver(Driver driverType)
@@ -54,15 +56,15 @@ public static void validateDriver(Driver driverType)
5456
else if (SystemUtils.IS_OS_WINDOWS)
5557
driverExists(FIREFOX_WIN_32, FIREFOX_WIN_64);
5658
else
57-
//
59+
driverExists(FIREFOX_LINUX);
5860
break;
5961
case Constants.CHROME:
6062
if (SystemUtils.IS_OS_MAC_OSX)
6163
driverExists(CHROME_MAC);
6264
else if (SystemUtils.IS_OS_WINDOWS)
6365
driverExists(CHROME_WIN_32, CHROME_WIN_64);
6466
else
65-
//
67+
driverExists(CHROME_LINUX);
6668
break;
6769
case Constants.SAFARI:
6870
case Constants.OPERA:
@@ -86,7 +88,14 @@ private static Boolean driverExists(String location1, String location2)
8688

8789
public static File getDriver()
8890
{
89-
return new File(FIREFOX_MAC);
91+
// return new File(FIREFOX_LINUX);
92+
//
93+
if (SystemUtils.IS_OS_MAC_OSX)
94+
return new File(FIREFOX_MAC);
95+
else if (SystemUtils.IS_OS_WINDOWS)
96+
return new File(FIREFOX_WIN_32, FIREFOX_WIN_64);
97+
else
98+
return new File(FIREFOX_LINUX);
9099
}
91100

92101
// public static File getFirefoxDriver()

0 commit comments

Comments
 (0)