Uhhy commited on
Commit
9e9ea88
·
verified ·
1 Parent(s): 1fa5297

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -184
app.py CHANGED
@@ -29,30 +29,22 @@ class Proxy(BaseModel):
29
 
30
  class VisitRequest(BaseModel):
31
  url: str
32
- platform: str
33
  count: int
34
  delay: int
35
  parallel_processes: int
36
 
37
  def get_random_proxy():
38
  try:
39
- options = webdriver.ChromeOptions()
40
- options.add_argument('--headless')
41
- options.add_argument('--disable-gpu')
42
- options.add_argument('--no-sandbox')
43
- driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
44
- driver.get("https://uhhy-fsfsfs.hf.space/valid")
45
- WebDriverWait(driver, 10).until(
46
- EC.presence_of_element_located((By.CSS_SELECTOR, "table tbody tr"))
47
- )
48
- proxy_elements = driver.find_elements(By.CSS_SELECTOR, "table tbody tr")
49
  proxies = []
50
- for element in proxy_elements:
51
- ip = element.find_element(By.CSS_SELECTOR, "td:nth-child(1)").text
52
- port = element.find_element(By.CSS_SELECTOR, "td:nth-child(2)").text
53
- proxy_type = element.find_element(By.CSS_SELECTOR, "td:nth-child(3)").text.lower()
 
54
  proxies.append(Proxy(ip=ip, port=port, type=proxy_type))
55
- driver.quit()
56
  if proxies:
57
  return random.choice(proxies)
58
  else:
@@ -107,7 +99,7 @@ def extract_video_id(url: str, platform: str) -> str:
107
  if match:
108
  return match.group(1)
109
  else:
110
- raise ValueError("Invalid URL format")
111
 
112
  def instagram_login(username: str, password: str):
113
  login_url = "https://www.instagram.com/accounts/login/ajax/"
@@ -195,88 +187,30 @@ def spotify_login(username: str, password: str):
195
  else:
196
  raise HTTPError("Authentication failed")
197
 
198
- def simulate_instagram_view(video_id: str, proxy: Proxy, session: Client):
199
- try:
200
- fake = Faker()
201
- fake_ipv4 = fake.ipv4()
202
- headers = {
203
- "User-Agent": fake.user_agent(),
204
- "X-Forwarded-For": fake_ipv4,
205
- "Client-IP": fake_ipv4,
206
- "X-Real-IP": fake_ipv4
207
- }
208
- view_url = f"https://www.instagram.com/reel/{video_id}"
209
-
210
- if proxy.type == "http" or proxy.type == "https":
211
- session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"})
212
- time.sleep(rand(10, 20))
213
- return True
214
- except Exception as e:
215
- print(f"Error in simulate_instagram_view: {e}")
216
- return False
217
-
218
- def simulate_tiktok_view(video_id: str, proxy: Proxy, session: Client):
219
- try:
220
- fake = Faker()
221
- fake_ipv4 = fake.ipv4()
222
- headers = {
223
- "User-Agent": fake.user_agent(),
224
- "X-Forwarded-For": fake_ipv4,
225
- "Client-IP": fake_ipv4,
226
- "X-Real-IP": fake_ipv4
227
- }
228
- view_url = f"https://www.tiktok.com/@user/video/{video_id}"
229
-
230
- if proxy.type == "http" or proxy.type == "https":
231
- session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"})
232
-
233
- time.sleep(rand(10, 20))
234
- return True
235
- except Exception as e:
236
- print(f"Error in simulate_tiktok_view: {e}")
237
- return False
238
-
239
- def simulate_youtube_view(video_id: str, proxy: Proxy, session: Client):
240
- try:
241
- fake = Faker()
242
- fake_ipv4 = fake.ipv4()
243
- headers = {
244
- "User-Agent": fake.user_agent(),
245
- "X-Forwarded-For": fake_ipv4,
246
- "Client-IP": fake_ipv4,
247
- "X-Real-IP": fake_ipv4
248
- }
249
- view_url = f"https://www.youtube.com/watch?v={video_id}"
250
-
251
- if proxy.type == "http" or proxy.type == "https":
252
- session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"})
253
- time.sleep(rand(10, 20))
254
- return True
255
- except Exception as e:
256
- print(f"Error in simulate_youtube_view: {e}")
257
- return False
258
-
259
- def simulate_facebook_view(video_id: str, proxy: Proxy, session: Client):
260
- try:
261
- fake = Faker()
262
- fake_ipv4 = fake.ipv4()
263
- headers = {
264
- "User-Agent": fake.user_agent(),
265
- "X-Forwarded-For": fake_ipv4,
266
- "Client-IP": fake_ipv4,
267
- "X-Real-IP": fake_ipv4
268
- }
269
- view_url = f"https://www.facebook.com/{video_id}"
270
-
271
- if proxy.type == "http" or proxy.type == "https":
272
- session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"})
273
- time.sleep(rand(10, 20))
274
- return True
275
- except Exception as e:
276
- print(f"Error in simulate_facebook_view: {e}")
277
- return False
278
 
279
- def simulate_twitch_view(video_id: str, proxy: Proxy, session: Client):
280
  try:
281
  fake = Faker()
282
  fake_ipv4 = fake.ipv4()
@@ -286,39 +220,30 @@ def simulate_twitch_view(video_id: str, proxy: Proxy, session: Client):
286
  "Client-IP": fake_ipv4,
287
  "X-Real-IP": fake_ipv4
288
  }
289
- view_url = f"https://www.twitch.tv/videos/{video_id}"
290
 
291
  if proxy.type == "http" or proxy.type == "https":
292
- session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"})
293
- time.sleep(rand(10, 20))
294
- return True
295
- except Exception as e:
296
- print(f"Error in simulate_twitch_view: {e}")
297
- return False
298
 
299
- def simulate_spotify_view(video_id: str, proxy: Proxy, session: Client):
300
- try:
301
- fake = Faker()
302
- fake_ipv4 = fake.ipv4()
303
- headers = {
304
- "User-Agent": fake.user_agent(),
305
- "X-Forwarded-For": fake_ipv4,
306
- "Client-IP": fake_ipv4,
307
- "X-Real-IP": fake_ipv4
308
- }
309
- view_url = f"https://open.spotify.com/track/{video_id}"
310
 
311
- if proxy.type == "http" or proxy.type == "https":
312
- session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"})
 
 
 
 
 
 
313
 
314
- time.sleep(rand(10, 20))
315
  return True
316
  except Exception as e:
317
- print(f"Error in simulate_spotify_view: {e}")
318
  return False
 
 
319
 
320
- def simulate_views_background(url: str, platform: str, count: int, delay: int, session: Client = None):
321
- video_id = extract_video_id(url, platform)
322
  proxy = get_random_proxy()
323
  if not proxy:
324
  print("No proxy available.")
@@ -329,18 +254,7 @@ def simulate_views_background(url: str, platform: str, count: int, delay: int, s
329
  with tqdm(total=count, desc=f"Simulating views for {url}") as pbar:
330
  for i in range(count):
331
  try:
332
- if platform == "instagram":
333
- success = simulate_instagram_view(video_id, proxy, session)
334
- elif platform == "tiktok":
335
- success = simulate_tiktok_view(video_id, proxy, session)
336
- elif platform == "youtube":
337
- success = simulate_youtube_view(video_id, proxy, session)
338
- elif platform == "facebook":
339
- success = simulate_facebook_view(video_id, proxy, session)
340
- elif platform == "twitch":
341
- success = simulate_twitch_view(video_id, proxy, session)
342
- elif platform == "spotify":
343
- success = simulate_spotify_view(video_id, proxy, session)
344
 
345
  if success:
346
  successful_views += 1
@@ -350,7 +264,6 @@ def simulate_views_background(url: str, platform: str, count: int, delay: int, s
350
  pbar.update(1)
351
  remaining_views = count - i - 1
352
  pbar.set_postfix({"Successful": successful_views, "Failed": failed_views, "Remaining": remaining_views, "Time Remaining": pbar.format_interval(pbar.remaining_time)})
353
- time.sleep(delay)
354
  except Exception as e:
355
  failed_views += 1
356
  pbar.update(1)
@@ -360,14 +273,10 @@ def simulate_views_background(url: str, platform: str, count: int, delay: int, s
360
  def simulate_views_endpoint(request: VisitRequest):
361
  try:
362
  session = None
363
- if os.getenv(f'{request.platform.upper()}_USER') and os.getenv(f'{request.platform.upper()}_PASSWORD'):
364
- session = authenticate(os.getenv(f'{request.platform.upper()}_USER'), os.getenv(f'{request.platform.upper()}_PASSWORD'), request.platform)
365
-
366
  threading.Thread(
367
  target=simulate_views_background,
368
  args=(
369
  request.url,
370
- request.platform,
371
  request.count,
372
  request.delay,
373
  session,
@@ -379,41 +288,15 @@ def simulate_views_endpoint(request: VisitRequest):
379
  except Exception as e:
380
  return str(e)
381
 
382
- def authenticate(username: str, password: str, platform: str):
383
- if platform == "instagram":
384
- return instagram_login(username, password)
385
- elif platform == "tiktok":
386
- return tiktok_login(username, password)
387
- elif platform == "youtube":
388
- return youtube_login(username, password)
389
- elif platform == "facebook":
390
- return facebook_login(username, password)
391
- elif platform == "twitch":
392
- return twitch_login(username, password)
393
- elif platform == "spotify":
394
- return spotify_login(username, password)
395
- else:
396
- raise ValueError("Invalid platform")
397
-
398
- def login(username: str, password: str, platform: str):
399
- try:
400
- session = authenticate(username, password, platform)
401
- return f"Authenticated on {platform}"
402
- except Exception as e:
403
- return str(e)
404
-
405
- def simulate(urls: str, platform: str, count: int, delay: int, parallel_processes: int):
406
  try:
407
  session = None
408
- if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
409
- session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
410
  for url in urls.split("\n"):
411
  for _ in range(parallel_processes):
412
  threading.Thread(
413
  target=simulate_views_background,
414
  args=(
415
  url,
416
- platform,
417
  count,
418
  delay,
419
  session
@@ -484,21 +367,13 @@ with gr.Blocks(css="""
484
  }
485
  }
486
  """) as interface:
487
- gr.Markdown("""
 
488
  <div class="container">
489
- <h1>Video Views Simulator</h1>
490
  <form action="/simulate" method="post">
491
- <label for="urls">Video URLs (one per line):</label><br>
492
  <textarea id="urls" name="urls"></textarea><br><br>
493
- <label for="platform">Platform:</label><br>
494
- <select id="platform" name="platform">
495
- <option value="instagram">Instagram</option>
496
- <option value="tiktok">TikTok</option>
497
- <option value="youtube">YouTube</option>
498
- <option value="facebook">Facebook</option>
499
- <option value="twitch">Twitch</option>
500
- <option value="spotify">Spotify</option>
501
- </select><br><br>
502
  <label for="count">Number of Views:</label><br>
503
  <input type="number" id="count" name="count" value="1"><br><br>
504
  <label for="delay">Delay (seconds):</label><br>
@@ -510,11 +385,7 @@ with gr.Blocks(css="""
510
  </div>
511
  """)
512
  with gr.Row():
513
- urls = gr.Textbox(label="Video URLs (one per line)")
514
- platform = gr.Dropdown(
515
- ["instagram", "tiktok", "youtube", "facebook", "twitch", "spotify"],
516
- label="Platform",
517
- )
518
  with gr.Row():
519
  count = gr.Number(label="Number of Views", value=1)
520
  delay = gr.Number(label="Delay (seconds)", value=1)
@@ -524,7 +395,7 @@ with gr.Blocks(css="""
524
 
525
  simulate_btn.click(
526
  fn=simulate,
527
- inputs=[urls, platform, count, delay, parallel_processes],
528
  outputs=output,
529
  )
530
 
 
29
 
30
  class VisitRequest(BaseModel):
31
  url: str
 
32
  count: int
33
  delay: int
34
  parallel_processes: int
35
 
36
  def get_random_proxy():
37
  try:
38
+ response = requests.get("https://uhhy-fsfsfs.hf.space/valid")
39
+ soup = BeautifulSoup(response.text, 'html.parser')
40
+ proxy_rows = soup.find_all('tr')[1:]
 
 
 
 
 
 
 
41
  proxies = []
42
+ for row in proxy_rows:
43
+ columns = row.find_all('td')
44
+ ip = columns[0].text
45
+ port = columns[1].text
46
+ proxy_type = columns[2].text.lower()
47
  proxies.append(Proxy(ip=ip, port=port, type=proxy_type))
 
48
  if proxies:
49
  return random.choice(proxies)
50
  else:
 
99
  if match:
100
  return match.group(1)
101
  else:
102
+ return None
103
 
104
  def instagram_login(username: str, password: str):
105
  login_url = "https://www.instagram.com/accounts/login/ajax/"
 
187
  else:
188
  raise HTTPError("Authentication failed")
189
 
190
+ def simulate_view(url: str, proxy: Proxy, session: Client, delay: int):
191
+ webdriver.DesiredCapabilities.CHROME['proxy'] = {
192
+ "httpProxy": f"{proxy.ip}:{proxy.port}",
193
+ "ftpProxy": f"{proxy.ip}:{proxy.port}",
194
+ "sslProxy": f"{proxy.ip}:{proxy.port}",
195
+ "proxyType": "MANUAL",
196
+ }
197
+ options = webdriver.ChromeOptions()
198
+ options.add_argument("--headless")
199
+ options.add_argument("--disable-blink-features=AutomationControlled")
200
+ options.add_argument("--disable-popup-blocking")
201
+ options.add_argument("--disable-infobars")
202
+ options.add_argument("--disable-web-security")
203
+ options.add_argument("--ignore-certificate-errors")
204
+ options.add_argument("--disable-notifications")
205
+ options.add_argument("--disable-extensions")
206
+ options.add_argument("--disable-gpu")
207
+ options.add_argument("--no-sandbox")
208
+ options.add_argument("--disable-dev-shm-usage")
209
+ options.add_argument("--mute-audio")
210
+ options.add_argument('--ignore-ssl-errors=yes')
211
+ options.add_argument('--ignore-certificate-errors')
212
+ driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
213
 
 
214
  try:
215
  fake = Faker()
216
  fake_ipv4 = fake.ipv4()
 
220
  "Client-IP": fake_ipv4,
221
  "X-Real-IP": fake_ipv4
222
  }
 
223
 
224
  if proxy.type == "http" or proxy.type == "https":
225
+ session.get(url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"})
 
 
 
 
 
226
 
227
+ driver.get(url)
 
 
 
 
 
 
 
 
 
 
228
 
229
+ try:
230
+ not_now = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'mt3GC')))
231
+ a = not_now.find_elements(By.TAG_NAME, "button")[1]
232
+ actions = ActionChains(driver)
233
+ actions.click(a)
234
+ actions.perform()
235
+ except:
236
+ pass
237
 
238
+ time.sleep(delay)
239
  return True
240
  except Exception as e:
241
+ print(f"Error simulating view: {e}")
242
  return False
243
+ finally:
244
+ driver.quit()
245
 
246
+ def simulate_views_background(url: str, count: int, delay: int, session: Client = None):
 
247
  proxy = get_random_proxy()
248
  if not proxy:
249
  print("No proxy available.")
 
254
  with tqdm(total=count, desc=f"Simulating views for {url}") as pbar:
255
  for i in range(count):
256
  try:
257
+ success = simulate_view(url, proxy, session, delay)
 
 
 
 
 
 
 
 
 
 
 
258
 
259
  if success:
260
  successful_views += 1
 
264
  pbar.update(1)
265
  remaining_views = count - i - 1
266
  pbar.set_postfix({"Successful": successful_views, "Failed": failed_views, "Remaining": remaining_views, "Time Remaining": pbar.format_interval(pbar.remaining_time)})
 
267
  except Exception as e:
268
  failed_views += 1
269
  pbar.update(1)
 
273
  def simulate_views_endpoint(request: VisitRequest):
274
  try:
275
  session = None
 
 
 
276
  threading.Thread(
277
  target=simulate_views_background,
278
  args=(
279
  request.url,
 
280
  request.count,
281
  request.delay,
282
  session,
 
288
  except Exception as e:
289
  return str(e)
290
 
291
+ def simulate(urls: str, count: int, delay: int, parallel_processes: int):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  try:
293
  session = None
 
 
294
  for url in urls.split("\n"):
295
  for _ in range(parallel_processes):
296
  threading.Thread(
297
  target=simulate_views_background,
298
  args=(
299
  url,
 
300
  count,
301
  delay,
302
  session
 
367
  }
368
  }
369
  """) as interface:
370
+ with gr.Row():
371
+ gr.HTML("""
372
  <div class="container">
373
+ <h1>Website Traffic Simulator</h1>
374
  <form action="/simulate" method="post">
375
+ <label for="urls">Website URLs or IP addresses (one per line):</label><br>
376
  <textarea id="urls" name="urls"></textarea><br><br>
 
 
 
 
 
 
 
 
 
377
  <label for="count">Number of Views:</label><br>
378
  <input type="number" id="count" name="count" value="1"><br><br>
379
  <label for="delay">Delay (seconds):</label><br>
 
385
  </div>
386
  """)
387
  with gr.Row():
388
+ urls = gr.Textbox(label="Website URLs or IP addresses (one per line)")
 
 
 
 
389
  with gr.Row():
390
  count = gr.Number(label="Number of Views", value=1)
391
  delay = gr.Number(label="Delay (seconds)", value=1)
 
395
 
396
  simulate_btn.click(
397
  fn=simulate,
398
+ inputs=[urls, count, delay, parallel_processes],
399
  outputs=output,
400
  )
401