Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import requests
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
-
from
|
| 4 |
-
from fastapi.responses import PlainTextResponse, HTMLResponse
|
| 5 |
-
from fastapi.staticfiles import StaticFiles
|
| 6 |
from pydantic import BaseModel
|
| 7 |
import re
|
| 8 |
import urllib.parse
|
|
@@ -18,14 +16,12 @@ from selenium.webdriver.support import expected_conditions as EC
|
|
| 18 |
from selenium.webdriver.common.action_chains import ActionChains
|
| 19 |
import time
|
| 20 |
from webdriver_manager.chrome import ChromeDriverManager
|
| 21 |
-
from fastapi import BackgroundTasks
|
| 22 |
from tqdm import tqdm
|
| 23 |
import asyncio
|
|
|
|
| 24 |
|
| 25 |
load_dotenv()
|
| 26 |
|
| 27 |
-
app = FastAPI()
|
| 28 |
-
|
| 29 |
class Proxy(BaseModel):
|
| 30 |
ip: str
|
| 31 |
port: str
|
|
@@ -38,8 +34,6 @@ class VisitRequest(BaseModel):
|
|
| 38 |
delay: int
|
| 39 |
parallel_processes: int
|
| 40 |
|
| 41 |
-
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 42 |
-
|
| 43 |
def get_random_proxy():
|
| 44 |
try:
|
| 45 |
options = webdriver.ChromeOptions()
|
|
@@ -66,7 +60,6 @@ def get_random_proxy():
|
|
| 66 |
except Exception as e:
|
| 67 |
return None
|
| 68 |
|
| 69 |
-
@app.get("/get_proxies", response_class=PlainTextResponse)
|
| 70 |
def get_proxies():
|
| 71 |
try:
|
| 72 |
proxies = []
|
|
@@ -76,9 +69,8 @@ def get_proxies():
|
|
| 76 |
proxies.append(f"{proxy.ip}:{proxy.port} ({proxy.type})")
|
| 77 |
return "\n".join(proxies)
|
| 78 |
except Exception as e:
|
| 79 |
-
return
|
| 80 |
|
| 81 |
-
@app.get("/rotate_ip", response_class=PlainTextResponse)
|
| 82 |
def rotate_ip():
|
| 83 |
try:
|
| 84 |
fake = Faker()
|
|
@@ -90,10 +82,10 @@ def rotate_ip():
|
|
| 90 |
}
|
| 91 |
proxy = get_random_proxy()
|
| 92 |
if not proxy:
|
| 93 |
-
return
|
| 94 |
-
return
|
| 95 |
except Exception as e:
|
| 96 |
-
return
|
| 97 |
|
| 98 |
def extract_video_id(url: str, platform: str) -> str:
|
| 99 |
url = urllib.parse.unquote(url)
|
|
@@ -116,93 +108,93 @@ def extract_video_id(url: str, platform: str) -> str:
|
|
| 116 |
else:
|
| 117 |
raise ValueError("Invalid URL format")
|
| 118 |
|
| 119 |
-
def instagram_login(username: str, password: str):
|
| 120 |
login_url = "https://www.instagram.com/accounts/login/ajax/"
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
|
| 140 |
-
def tiktok_login(username: str, password: str):
|
| 141 |
login_url = "https://www.tiktok.com/login/"
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
|
| 153 |
-
def youtube_login(username: str, password: str):
|
| 154 |
login_url = "https://accounts.google.com/ServiceLogin"
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
|
| 166 |
-
def facebook_login(username: str, password: str):
|
| 167 |
login_url = "https://www.facebook.com/login"
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
|
| 179 |
-
def twitch_login(username: str, password: str):
|
| 180 |
login_url = "https://www.twitch.tv/login"
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
|
| 192 |
-
def spotify_login(username: str, password: str):
|
| 193 |
login_url = "https://accounts.spotify.com/api/token"
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
|
| 205 |
-
def simulate_instagram_view(video_id: str, proxy: Proxy, session:
|
| 206 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 207 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 208 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -238,7 +230,7 @@ def simulate_instagram_view(video_id: str, proxy: Proxy, session: requests.Sessi
|
|
| 238 |
view_url = f"https://www.instagram.com/reel/{video_id}"
|
| 239 |
|
| 240 |
if proxy.type == "http" or proxy.type == "https":
|
| 241 |
-
|
| 242 |
|
| 243 |
driver.get(view_url)
|
| 244 |
|
|
@@ -257,7 +249,7 @@ def simulate_instagram_view(video_id: str, proxy: Proxy, session: requests.Sessi
|
|
| 257 |
finally:
|
| 258 |
driver.quit()
|
| 259 |
|
| 260 |
-
def simulate_tiktok_view(video_id: str, proxy: Proxy, session:
|
| 261 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 262 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 263 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -293,7 +285,7 @@ def simulate_tiktok_view(video_id: str, proxy: Proxy, session: requests.Session)
|
|
| 293 |
view_url = f"https://www.tiktok.com/@user/video/{video_id}"
|
| 294 |
|
| 295 |
if proxy.type == "http" or proxy.type == "https":
|
| 296 |
-
|
| 297 |
|
| 298 |
driver.get(view_url)
|
| 299 |
|
|
@@ -312,7 +304,7 @@ def simulate_tiktok_view(video_id: str, proxy: Proxy, session: requests.Session)
|
|
| 312 |
finally:
|
| 313 |
driver.quit()
|
| 314 |
|
| 315 |
-
def simulate_youtube_view(video_id: str, proxy: Proxy, session:
|
| 316 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 317 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 318 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -348,7 +340,7 @@ def simulate_youtube_view(video_id: str, proxy: Proxy, session: requests.Session
|
|
| 348 |
view_url = f"https://www.youtube.com/watch?v={video_id}"
|
| 349 |
|
| 350 |
if proxy.type == "http" or proxy.type == "https":
|
| 351 |
-
|
| 352 |
|
| 353 |
driver.get(view_url)
|
| 354 |
|
|
@@ -367,7 +359,7 @@ def simulate_youtube_view(video_id: str, proxy: Proxy, session: requests.Session
|
|
| 367 |
finally:
|
| 368 |
driver.quit()
|
| 369 |
|
| 370 |
-
def simulate_facebook_view(video_id: str, proxy: Proxy, session:
|
| 371 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 372 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 373 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -403,7 +395,7 @@ def simulate_facebook_view(video_id: str, proxy: Proxy, session: requests.Sessio
|
|
| 403 |
view_url = f"https://www.facebook.com/{video_id}"
|
| 404 |
|
| 405 |
if proxy.type == "http" or proxy.type == "https":
|
| 406 |
-
|
| 407 |
|
| 408 |
driver.get(view_url)
|
| 409 |
|
|
@@ -422,7 +414,7 @@ def simulate_facebook_view(video_id: str, proxy: Proxy, session: requests.Sessio
|
|
| 422 |
finally:
|
| 423 |
driver.quit()
|
| 424 |
|
| 425 |
-
def simulate_twitch_view(video_id: str, proxy: Proxy, session:
|
| 426 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 427 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 428 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -458,7 +450,7 @@ def simulate_twitch_view(video_id: str, proxy: Proxy, session: requests.Session)
|
|
| 458 |
view_url = f"https://www.twitch.tv/videos/{video_id}"
|
| 459 |
|
| 460 |
if proxy.type == "http" or proxy.type == "https":
|
| 461 |
-
|
| 462 |
|
| 463 |
driver.get(view_url)
|
| 464 |
|
|
@@ -477,7 +469,7 @@ def simulate_twitch_view(video_id: str, proxy: Proxy, session: requests.Session)
|
|
| 477 |
finally:
|
| 478 |
driver.quit()
|
| 479 |
|
| 480 |
-
def simulate_spotify_view(video_id: str, proxy: Proxy, session:
|
| 481 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 482 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 483 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -513,7 +505,7 @@ def simulate_spotify_view(video_id: str, proxy: Proxy, session: requests.Session
|
|
| 513 |
view_url = f"https://open.spotify.com/track/{video_id}"
|
| 514 |
|
| 515 |
if proxy.type == "http" or proxy.type == "https":
|
| 516 |
-
|
| 517 |
|
| 518 |
driver.get(view_url)
|
| 519 |
|
|
@@ -532,12 +524,11 @@ def simulate_spotify_view(video_id: str, proxy: Proxy, session: requests.Session
|
|
| 532 |
finally:
|
| 533 |
driver.quit()
|
| 534 |
|
| 535 |
-
|
| 536 |
-
def simulate_views_background(url: str, platform: str, count: int, delay: int, parallel_processes: int, session: requests.Session = None):
|
| 537 |
for _ in range(parallel_processes):
|
| 538 |
asyncio.run(simulate_one_view_process(url, platform, count, delay, session))
|
| 539 |
|
| 540 |
-
async def simulate_one_view_process(url: str, platform: str, count: int, delay: int, session:
|
| 541 |
video_id = extract_video_id(url, platform)
|
| 542 |
proxy = get_random_proxy()
|
| 543 |
if not proxy:
|
|
@@ -561,176 +552,95 @@ async def simulate_one_view_process(url: str, platform: str, count: int, delay:
|
|
| 561 |
except Exception as e:
|
| 562 |
pass
|
| 563 |
|
| 564 |
-
|
| 565 |
-
async def simulate_views_endpoint(request: VisitRequest, background_tasks: BackgroundTasks):
|
| 566 |
try:
|
| 567 |
session = None
|
| 568 |
if os.getenv(f'{request.platform.upper()}_USER') and os.getenv(f'{request.platform.upper()}_PASSWORD'):
|
| 569 |
-
session = authenticate(os.getenv(f'{request.platform.upper()}_USER'), os.getenv(f'{request.platform.upper()}_PASSWORD'), request.platform)
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
simulate_views_background
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
|
|
|
| 579 |
)
|
| 580 |
|
| 581 |
-
return
|
| 582 |
|
| 583 |
except Exception as e:
|
| 584 |
-
return
|
| 585 |
|
| 586 |
-
def authenticate(username: str, password: str, platform: str):
|
| 587 |
if platform == "instagram":
|
| 588 |
-
return instagram_login(username, password)
|
| 589 |
elif platform == "tiktok":
|
| 590 |
-
return tiktok_login(username, password)
|
| 591 |
elif platform == "youtube":
|
| 592 |
-
return youtube_login(username, password)
|
| 593 |
elif platform == "facebook":
|
| 594 |
-
return facebook_login(username, password)
|
| 595 |
elif platform == "twitch":
|
| 596 |
-
return twitch_login(username, password)
|
| 597 |
elif platform == "spotify":
|
| 598 |
-
return spotify_login(username, password)
|
| 599 |
else:
|
| 600 |
-
raise
|
| 601 |
|
| 602 |
-
|
| 603 |
-
async def login(username: str = Form(...), password: str = Form(...), platform: str = Form(...)):
|
| 604 |
try:
|
| 605 |
-
session = authenticate(username, password, platform)
|
| 606 |
-
return
|
| 607 |
-
except
|
| 608 |
-
return e
|
| 609 |
|
| 610 |
-
|
| 611 |
-
async def simulate(background_tasks: BackgroundTasks, urls: str = Form(...), platform: str = Form(...), count: int = Form(...), delay: int = Form(...), parallel_processes: int = Form(...)):
|
| 612 |
try:
|
| 613 |
session = None
|
| 614 |
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 615 |
-
session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 616 |
|
| 617 |
for index, url in enumerate(urls.split("\n")):
|
| 618 |
-
|
| 619 |
-
simulate_views_background
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
|
|
|
| 626 |
)
|
| 627 |
-
return
|
| 628 |
|
| 629 |
except Exception as e:
|
| 630 |
-
return
|
| 631 |
-
|
| 632 |
-
@app.get("/")
|
| 633 |
-
async def main_page():
|
| 634 |
-
return HTMLResponse(
|
| 635 |
-
"""
|
| 636 |
-
<!DOCTYPE html>
|
| 637 |
-
<html>
|
| 638 |
-
<head>
|
| 639 |
-
<title>Video Views Simulator</title>
|
| 640 |
-
<style>
|
| 641 |
-
body {
|
| 642 |
-
background-color: #f0f0f0;
|
| 643 |
-
font-family: sans-serif;
|
| 644 |
-
display: flex;
|
| 645 |
-
justify-content: center;
|
| 646 |
-
align-items: center;
|
| 647 |
-
min-height: 100vh;
|
| 648 |
-
}
|
| 649 |
-
.container {
|
| 650 |
-
background-color: #fff;
|
| 651 |
-
padding: 30px;
|
| 652 |
-
border-radius: 10px;
|
| 653 |
-
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
| 654 |
-
text-align: center;
|
| 655 |
-
animation: fadeIn 1s ease-in-out;
|
| 656 |
-
}
|
| 657 |
-
h1 {
|
| 658 |
-
color: #333;
|
| 659 |
-
margin-bottom: 20px;
|
| 660 |
-
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
| 661 |
-
}
|
| 662 |
-
form {
|
| 663 |
-
display: flex;
|
| 664 |
-
flex-direction: column;
|
| 665 |
-
width: 350px;
|
| 666 |
-
}
|
| 667 |
-
label {
|
| 668 |
-
margin-bottom: 5px;
|
| 669 |
-
font-weight: bold;
|
| 670 |
-
}
|
| 671 |
-
input[type="text"],
|
| 672 |
-
textarea,
|
| 673 |
-
select,
|
| 674 |
-
input[type="number"] {
|
| 675 |
-
padding: 10px;
|
| 676 |
-
margin-bottom: 15px;
|
| 677 |
-
border: 1px solid #ddd;
|
| 678 |
-
border-radius: 5px;
|
| 679 |
-
}
|
| 680 |
-
input[type="submit"] {
|
| 681 |
-
background-color: #007bff;
|
| 682 |
-
color: #fff;
|
| 683 |
-
border: none;
|
| 684 |
-
padding: 12px 20px;
|
| 685 |
-
border-radius: 5px;
|
| 686 |
-
cursor: pointer;
|
| 687 |
-
transition: background-color 0.3s;
|
| 688 |
-
}
|
| 689 |
-
input[type="submit"]:hover {
|
| 690 |
-
background-color: #0056b3;
|
| 691 |
-
}
|
| 692 |
-
@keyframes fadeIn {
|
| 693 |
-
from {
|
| 694 |
-
opacity: 0;
|
| 695 |
-
}
|
| 696 |
-
to {
|
| 697 |
-
opacity: 1;
|
| 698 |
-
}
|
| 699 |
-
}
|
| 700 |
-
</style>
|
| 701 |
-
</head>
|
| 702 |
-
<body>
|
| 703 |
-
<div class="container">
|
| 704 |
-
<h1>Video Views Simulator</h1>
|
| 705 |
-
<form action="/simulate" method="post">
|
| 706 |
-
<label for="urls">Video URLs (one per line):</label><br>
|
| 707 |
-
<textarea id="urls" name="urls"></textarea><br><br>
|
| 708 |
-
<label for="platform">Platform:</label><br>
|
| 709 |
-
<select id="platform" name="platform">
|
| 710 |
-
<option value="instagram">Instagram</option>
|
| 711 |
-
<option value="tiktok">TikTok</option>
|
| 712 |
-
<option value="youtube">YouTube</option>
|
| 713 |
-
<option value="facebook">Facebook</option>
|
| 714 |
-
<option value="twitch">Twitch</option>
|
| 715 |
-
<option value="spotify">Spotify</option>
|
| 716 |
-
</select><br><br>
|
| 717 |
-
<label for="count">Number of Views:</label><br>
|
| 718 |
-
<input type="number" id="count" name="count" value="1"><br><br>
|
| 719 |
-
<label for="delay">Delay (seconds):</label><br>
|
| 720 |
-
<input type="number" id="delay" name="delay" value="1"><br><br>
|
| 721 |
-
<label for="parallel_processes">Parallel Processes:</label><br>
|
| 722 |
-
<input type="number" id="parallel_processes" name="parallel_processes" value="1"><br><br>
|
| 723 |
-
<input type="submit" value="Simulate">
|
| 724 |
-
</form>
|
| 725 |
-
</div>
|
| 726 |
-
</body>
|
| 727 |
-
</html>
|
| 728 |
-
"""
|
| 729 |
-
)
|
| 730 |
|
| 731 |
def rand(min, max):
|
| 732 |
return random.randint(min, max)
|
| 733 |
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
+
from httpx import AsyncClient, HTTPError
|
|
|
|
|
|
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import re
|
| 6 |
import urllib.parse
|
|
|
|
| 16 |
from selenium.webdriver.common.action_chains import ActionChains
|
| 17 |
import time
|
| 18 |
from webdriver_manager.chrome import ChromeDriverManager
|
|
|
|
| 19 |
from tqdm import tqdm
|
| 20 |
import asyncio
|
| 21 |
+
import gradio as gr
|
| 22 |
|
| 23 |
load_dotenv()
|
| 24 |
|
|
|
|
|
|
|
| 25 |
class Proxy(BaseModel):
|
| 26 |
ip: str
|
| 27 |
port: str
|
|
|
|
| 34 |
delay: int
|
| 35 |
parallel_processes: int
|
| 36 |
|
|
|
|
|
|
|
| 37 |
def get_random_proxy():
|
| 38 |
try:
|
| 39 |
options = webdriver.ChromeOptions()
|
|
|
|
| 60 |
except Exception as e:
|
| 61 |
return None
|
| 62 |
|
|
|
|
| 63 |
def get_proxies():
|
| 64 |
try:
|
| 65 |
proxies = []
|
|
|
|
| 69 |
proxies.append(f"{proxy.ip}:{proxy.port} ({proxy.type})")
|
| 70 |
return "\n".join(proxies)
|
| 71 |
except Exception as e:
|
| 72 |
+
return str(e)
|
| 73 |
|
|
|
|
| 74 |
def rotate_ip():
|
| 75 |
try:
|
| 76 |
fake = Faker()
|
|
|
|
| 82 |
}
|
| 83 |
proxy = get_random_proxy()
|
| 84 |
if not proxy:
|
| 85 |
+
return "No proxy available."
|
| 86 |
+
return f"{proxy.ip}:{proxy.port} ({proxy.type})"
|
| 87 |
except Exception as e:
|
| 88 |
+
return str(e)
|
| 89 |
|
| 90 |
def extract_video_id(url: str, platform: str) -> str:
|
| 91 |
url = urllib.parse.unquote(url)
|
|
|
|
| 108 |
else:
|
| 109 |
raise ValueError("Invalid URL format")
|
| 110 |
|
| 111 |
+
async def instagram_login(username: str, password: str):
|
| 112 |
login_url = "https://www.instagram.com/accounts/login/ajax/"
|
| 113 |
+
async with AsyncClient() as session:
|
| 114 |
+
response = await session.get("https://www.instagram.com/", headers={"User-Agent": "Mozilla/5.0"})
|
| 115 |
+
soup = BeautifulSoup(response.text, "html.parser")
|
| 116 |
+
csrf_token = soup.find("meta", {"name": "csrf-token"})["content"]
|
| 117 |
+
login_data = {
|
| 118 |
+
"username": username,
|
| 119 |
+
"enc_password": f"#PWD_INSTAGRAM_BROWSER:0:&:{password}"
|
| 120 |
+
}
|
| 121 |
+
headers = {
|
| 122 |
+
"User-Agent": "Mozilla/5.0",
|
| 123 |
+
"X-CSRFToken": csrf_token,
|
| 124 |
+
"X-Requested-With": "XMLHttpRequest"
|
| 125 |
+
}
|
| 126 |
+
response = await session.post(login_url, data=login_data, headers=headers)
|
| 127 |
+
if response.status_code == 200 and response.json().get("authenticated"):
|
| 128 |
+
return session
|
| 129 |
+
else:
|
| 130 |
+
raise HTTPError("Authentication failed")
|
| 131 |
|
| 132 |
+
async def tiktok_login(username: str, password: str):
|
| 133 |
login_url = "https://www.tiktok.com/login/"
|
| 134 |
+
async with AsyncClient() as session:
|
| 135 |
+
login_data = {
|
| 136 |
+
"username": username,
|
| 137 |
+
"password": password
|
| 138 |
+
}
|
| 139 |
+
response = await session.post(login_url, data=login_data)
|
| 140 |
+
if response.status_code == 200:
|
| 141 |
+
return session
|
| 142 |
+
else:
|
| 143 |
+
raise HTTPError("Authentication failed")
|
| 144 |
|
| 145 |
+
async def youtube_login(username: str, password: str):
|
| 146 |
login_url = "https://accounts.google.com/ServiceLogin"
|
| 147 |
+
async with AsyncClient() as session:
|
| 148 |
+
login_data = {
|
| 149 |
+
"username": username,
|
| 150 |
+
"password": password
|
| 151 |
+
}
|
| 152 |
+
response = await session.post(login_url, data=login_data)
|
| 153 |
+
if response.status_code == 200:
|
| 154 |
+
return session
|
| 155 |
+
else:
|
| 156 |
+
raise HTTPError("Authentication failed")
|
| 157 |
|
| 158 |
+
async def facebook_login(username: str, password: str):
|
| 159 |
login_url = "https://www.facebook.com/login"
|
| 160 |
+
async with AsyncClient() as session:
|
| 161 |
+
login_data = {
|
| 162 |
+
"email": username,
|
| 163 |
+
"pass": password
|
| 164 |
+
}
|
| 165 |
+
response = await session.post(login_url, data=login_data)
|
| 166 |
+
if response.status_code == 200:
|
| 167 |
+
return session
|
| 168 |
+
else:
|
| 169 |
+
raise HTTPError("Authentication failed")
|
| 170 |
|
| 171 |
+
async def twitch_login(username: str, password: str):
|
| 172 |
login_url = "https://www.twitch.tv/login"
|
| 173 |
+
async with AsyncClient() as session:
|
| 174 |
+
login_data = {
|
| 175 |
+
"login": username,
|
| 176 |
+
"password": password
|
| 177 |
+
}
|
| 178 |
+
response = await session.post(login_url, data=login_data)
|
| 179 |
+
if response.status_code == 200:
|
| 180 |
+
return session
|
| 181 |
+
else:
|
| 182 |
+
raise HTTPError("Authentication failed")
|
| 183 |
|
| 184 |
+
async def spotify_login(username: str, password: str):
|
| 185 |
login_url = "https://accounts.spotify.com/api/token"
|
| 186 |
+
async with AsyncClient() as session:
|
| 187 |
+
login_data = {
|
| 188 |
+
"username": username,
|
| 189 |
+
"password": password
|
| 190 |
+
}
|
| 191 |
+
response = await session.post(login_url, data=login_data)
|
| 192 |
+
if response.status_code == 200:
|
| 193 |
+
return session
|
| 194 |
+
else:
|
| 195 |
+
raise HTTPError("Authentication failed")
|
| 196 |
|
| 197 |
+
def simulate_instagram_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
| 198 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 199 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 200 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
|
|
| 230 |
view_url = f"https://www.instagram.com/reel/{video_id}"
|
| 231 |
|
| 232 |
if proxy.type == "http" or proxy.type == "https":
|
| 233 |
+
asyncio.run(session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"}))
|
| 234 |
|
| 235 |
driver.get(view_url)
|
| 236 |
|
|
|
|
| 249 |
finally:
|
| 250 |
driver.quit()
|
| 251 |
|
| 252 |
+
def simulate_tiktok_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
| 253 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 254 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 255 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
|
|
| 285 |
view_url = f"https://www.tiktok.com/@user/video/{video_id}"
|
| 286 |
|
| 287 |
if proxy.type == "http" or proxy.type == "https":
|
| 288 |
+
asyncio.run(session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"}))
|
| 289 |
|
| 290 |
driver.get(view_url)
|
| 291 |
|
|
|
|
| 304 |
finally:
|
| 305 |
driver.quit()
|
| 306 |
|
| 307 |
+
def simulate_youtube_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
| 308 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 309 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 310 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
|
|
| 340 |
view_url = f"https://www.youtube.com/watch?v={video_id}"
|
| 341 |
|
| 342 |
if proxy.type == "http" or proxy.type == "https":
|
| 343 |
+
asyncio.run(session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"}))
|
| 344 |
|
| 345 |
driver.get(view_url)
|
| 346 |
|
|
|
|
| 359 |
finally:
|
| 360 |
driver.quit()
|
| 361 |
|
| 362 |
+
def simulate_facebook_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
| 363 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 364 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 365 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
|
|
| 395 |
view_url = f"https://www.facebook.com/{video_id}"
|
| 396 |
|
| 397 |
if proxy.type == "http" or proxy.type == "https":
|
| 398 |
+
asyncio.run(session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"}))
|
| 399 |
|
| 400 |
driver.get(view_url)
|
| 401 |
|
|
|
|
| 414 |
finally:
|
| 415 |
driver.quit()
|
| 416 |
|
| 417 |
+
def simulate_twitch_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
| 418 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 419 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 420 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
|
|
| 450 |
view_url = f"https://www.twitch.tv/videos/{video_id}"
|
| 451 |
|
| 452 |
if proxy.type == "http" or proxy.type == "https":
|
| 453 |
+
asyncio.run(session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"}))
|
| 454 |
|
| 455 |
driver.get(view_url)
|
| 456 |
|
|
|
|
| 469 |
finally:
|
| 470 |
driver.quit()
|
| 471 |
|
| 472 |
+
def simulate_spotify_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
| 473 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 474 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 475 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
|
|
| 505 |
view_url = f"https://open.spotify.com/track/{video_id}"
|
| 506 |
|
| 507 |
if proxy.type == "http" or proxy.type == "https":
|
| 508 |
+
asyncio.run(session.get(view_url, headers=headers, proxies={"http": f"http://{proxy.ip}:{proxy.port}", "https": f"https://{proxy.ip}:{proxy.port}"}))
|
| 509 |
|
| 510 |
driver.get(view_url)
|
| 511 |
|
|
|
|
| 524 |
finally:
|
| 525 |
driver.quit()
|
| 526 |
|
| 527 |
+
def simulate_views_background(url: str, platform: str, count: int, delay: int, parallel_processes: int, session: AsyncClient = None):
|
|
|
|
| 528 |
for _ in range(parallel_processes):
|
| 529 |
asyncio.run(simulate_one_view_process(url, platform, count, delay, session))
|
| 530 |
|
| 531 |
+
async def simulate_one_view_process(url: str, platform: str, count: int, delay: int, session: AsyncClient = None):
|
| 532 |
video_id = extract_video_id(url, platform)
|
| 533 |
proxy = get_random_proxy()
|
| 534 |
if not proxy:
|
|
|
|
| 552 |
except Exception as e:
|
| 553 |
pass
|
| 554 |
|
| 555 |
+
async def simulate_views_endpoint(request: VisitRequest):
|
|
|
|
| 556 |
try:
|
| 557 |
session = None
|
| 558 |
if os.getenv(f'{request.platform.upper()}_USER') and os.getenv(f'{request.platform.upper()}_PASSWORD'):
|
| 559 |
+
session = await authenticate(os.getenv(f'{request.platform.upper()}_USER'), os.getenv(f'{request.platform.upper()}_PASSWORD'), request.platform)
|
| 560 |
+
|
| 561 |
+
asyncio.create_task(
|
| 562 |
+
simulate_views_background(
|
| 563 |
+
url=request.url,
|
| 564 |
+
platform=request.platform,
|
| 565 |
+
count=request.count,
|
| 566 |
+
delay=request.delay,
|
| 567 |
+
parallel_processes=request.parallel_processes,
|
| 568 |
+
session=session
|
| 569 |
+
)
|
| 570 |
)
|
| 571 |
|
| 572 |
+
return "Views simulation started in the background."
|
| 573 |
|
| 574 |
except Exception as e:
|
| 575 |
+
return str(e)
|
| 576 |
|
| 577 |
+
async def authenticate(username: str, password: str, platform: str):
|
| 578 |
if platform == "instagram":
|
| 579 |
+
return await instagram_login(username, password)
|
| 580 |
elif platform == "tiktok":
|
| 581 |
+
return await tiktok_login(username, password)
|
| 582 |
elif platform == "youtube":
|
| 583 |
+
return await youtube_login(username, password)
|
| 584 |
elif platform == "facebook":
|
| 585 |
+
return await facebook_login(username, password)
|
| 586 |
elif platform == "twitch":
|
| 587 |
+
return await twitch_login(username, password)
|
| 588 |
elif platform == "spotify":
|
| 589 |
+
return await spotify_login(username, password)
|
| 590 |
else:
|
| 591 |
+
raise ValueError("Invalid platform")
|
| 592 |
|
| 593 |
+
async def login(username: str, password: str, platform: str):
|
|
|
|
| 594 |
try:
|
| 595 |
+
session = await authenticate(username, password, platform)
|
| 596 |
+
return f"Authenticated on {platform}"
|
| 597 |
+
except Exception as e:
|
| 598 |
+
return str(e)
|
| 599 |
|
| 600 |
+
async def simulate(urls: str, platform: str, count: int, delay: int, parallel_processes: int):
|
|
|
|
| 601 |
try:
|
| 602 |
session = None
|
| 603 |
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 604 |
+
session = await authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 605 |
|
| 606 |
for index, url in enumerate(urls.split("\n")):
|
| 607 |
+
asyncio.create_task(
|
| 608 |
+
simulate_views_background(
|
| 609 |
+
url=url,
|
| 610 |
+
platform=platform,
|
| 611 |
+
count=count,
|
| 612 |
+
delay=delay,
|
| 613 |
+
parallel_processes=parallel_processes,
|
| 614 |
+
session=session
|
| 615 |
+
)
|
| 616 |
)
|
| 617 |
+
return "Simulations started in the background."
|
| 618 |
|
| 619 |
except Exception as e:
|
| 620 |
+
return str(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 621 |
|
| 622 |
def rand(min, max):
|
| 623 |
return random.randint(min, max)
|
| 624 |
|
| 625 |
+
with gr.Blocks() as interface:
|
| 626 |
+
gr.Markdown("<h1>Video Views Simulator</h1>")
|
| 627 |
+
with gr.Row():
|
| 628 |
+
urls = gr.Textbox(label="Video URLs (one per line)")
|
| 629 |
+
platform = gr.Dropdown(
|
| 630 |
+
["instagram", "tiktok", "youtube", "facebook", "twitch", "spotify"],
|
| 631 |
+
label="Platform",
|
| 632 |
+
)
|
| 633 |
+
with gr.Row():
|
| 634 |
+
count = gr.Number(label="Number of Views", value=1)
|
| 635 |
+
delay = gr.Number(label="Delay (seconds)", value=1)
|
| 636 |
+
parallel_processes = gr.Number(label="Parallel Processes", value=1)
|
| 637 |
+
simulate_btn = gr.Button("Simulate")
|
| 638 |
+
output = gr.Textbox(label="Output")
|
| 639 |
+
|
| 640 |
+
simulate_btn.click(
|
| 641 |
+
fn=simulate,
|
| 642 |
+
inputs=[urls, platform, count, delay, parallel_processes],
|
| 643 |
+
outputs=output,
|
| 644 |
+
)
|
| 645 |
+
|
| 646 |
+
interface.launch(server_name="0.0.0.0", server_port=7860)
|