Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
import requests
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
-
from httpx import
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import re
|
| 6 |
import urllib.parse
|
|
@@ -17,7 +17,7 @@ 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
|
| 21 |
import gradio as gr
|
| 22 |
|
| 23 |
load_dotenv()
|
|
@@ -108,93 +108,93 @@ def extract_video_id(url: str, platform: str) -> str:
|
|
| 108 |
else:
|
| 109 |
raise ValueError("Invalid URL format")
|
| 110 |
|
| 111 |
-
|
| 112 |
login_url = "https://www.instagram.com/accounts/login/ajax/"
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
|
| 132 |
-
|
| 133 |
login_url = "https://www.tiktok.com/login/"
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
| 146 |
login_url = "https://accounts.google.com/ServiceLogin"
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
|
| 158 |
-
|
| 159 |
login_url = "https://www.facebook.com/login"
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
|
| 171 |
-
|
| 172 |
login_url = "https://www.twitch.tv/login"
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
|
| 184 |
-
|
| 185 |
login_url = "https://accounts.spotify.com/api/token"
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
|
| 197 |
-
def simulate_instagram_view(video_id: str, proxy: Proxy, session:
|
| 198 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 199 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 200 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -230,7 +230,7 @@ def simulate_instagram_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 230 |
view_url = f"https://www.instagram.com/reel/{video_id}"
|
| 231 |
|
| 232 |
if proxy.type == "http" or proxy.type == "https":
|
| 233 |
-
|
| 234 |
|
| 235 |
driver.get(view_url)
|
| 236 |
|
|
@@ -249,7 +249,7 @@ def simulate_instagram_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 249 |
finally:
|
| 250 |
driver.quit()
|
| 251 |
|
| 252 |
-
def simulate_tiktok_view(video_id: str, proxy: Proxy, session:
|
| 253 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 254 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 255 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -285,7 +285,7 @@ def simulate_tiktok_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 285 |
view_url = f"https://www.tiktok.com/@user/video/{video_id}"
|
| 286 |
|
| 287 |
if proxy.type == "http" or proxy.type == "https":
|
| 288 |
-
|
| 289 |
|
| 290 |
driver.get(view_url)
|
| 291 |
|
|
@@ -304,7 +304,7 @@ def simulate_tiktok_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 304 |
finally:
|
| 305 |
driver.quit()
|
| 306 |
|
| 307 |
-
def simulate_youtube_view(video_id: str, proxy: Proxy, session:
|
| 308 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 309 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 310 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -340,7 +340,7 @@ def simulate_youtube_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 340 |
view_url = f"https://www.youtube.com/watch?v={video_id}"
|
| 341 |
|
| 342 |
if proxy.type == "http" or proxy.type == "https":
|
| 343 |
-
|
| 344 |
|
| 345 |
driver.get(view_url)
|
| 346 |
|
|
@@ -359,7 +359,7 @@ def simulate_youtube_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 359 |
finally:
|
| 360 |
driver.quit()
|
| 361 |
|
| 362 |
-
def simulate_facebook_view(video_id: str, proxy: Proxy, session:
|
| 363 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 364 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 365 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -395,7 +395,7 @@ def simulate_facebook_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 395 |
view_url = f"https://www.facebook.com/{video_id}"
|
| 396 |
|
| 397 |
if proxy.type == "http" or proxy.type == "https":
|
| 398 |
-
|
| 399 |
|
| 400 |
driver.get(view_url)
|
| 401 |
|
|
@@ -414,7 +414,7 @@ def simulate_facebook_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 414 |
finally:
|
| 415 |
driver.quit()
|
| 416 |
|
| 417 |
-
def simulate_twitch_view(video_id: str, proxy: Proxy, session:
|
| 418 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 419 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 420 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -450,7 +450,7 @@ def simulate_twitch_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 450 |
view_url = f"https://www.twitch.tv/videos/{video_id}"
|
| 451 |
|
| 452 |
if proxy.type == "http" or proxy.type == "https":
|
| 453 |
-
|
| 454 |
|
| 455 |
driver.get(view_url)
|
| 456 |
|
|
@@ -469,7 +469,7 @@ def simulate_twitch_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 469 |
finally:
|
| 470 |
driver.quit()
|
| 471 |
|
| 472 |
-
def simulate_spotify_view(video_id: str, proxy: Proxy, session:
|
| 473 |
webdriver.DesiredCapabilities.CHROME['proxy'] = {
|
| 474 |
"httpProxy": f"{proxy.ip}:{proxy.port}",
|
| 475 |
"ftpProxy": f"{proxy.ip}:{proxy.port}",
|
|
@@ -505,7 +505,7 @@ def simulate_spotify_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 505 |
view_url = f"https://open.spotify.com/track/{video_id}"
|
| 506 |
|
| 507 |
if proxy.type == "http" or proxy.type == "https":
|
| 508 |
-
|
| 509 |
|
| 510 |
driver.get(view_url)
|
| 511 |
|
|
@@ -524,11 +524,7 @@ def simulate_spotify_view(video_id: str, proxy: Proxy, session: AsyncClient):
|
|
| 524 |
finally:
|
| 525 |
driver.quit()
|
| 526 |
|
| 527 |
-
def simulate_views_background(url: str, platform: str, count: int, delay: int,
|
| 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:
|
|
@@ -548,72 +544,73 @@ async def simulate_one_view_process(url: str, platform: str, count: int, delay:
|
|
| 548 |
simulate_twitch_view(video_id, proxy, session)
|
| 549 |
elif platform == "spotify":
|
| 550 |
simulate_spotify_view(video_id, proxy, session)
|
| 551 |
-
|
| 552 |
except Exception as e:
|
| 553 |
pass
|
| 554 |
|
| 555 |
-
|
| 556 |
try:
|
| 557 |
session = None
|
| 558 |
if os.getenv(f'{request.platform.upper()}_USER') and os.getenv(f'{request.platform.upper()}_PASSWORD'):
|
| 559 |
-
session =
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
simulate_views_background
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
session
|
| 569 |
)
|
| 570 |
-
)
|
| 571 |
|
| 572 |
return "Views simulation started in the background."
|
| 573 |
|
| 574 |
except Exception as e:
|
| 575 |
return str(e)
|
| 576 |
|
| 577 |
-
|
| 578 |
if platform == "instagram":
|
| 579 |
-
return
|
| 580 |
elif platform == "tiktok":
|
| 581 |
-
return
|
| 582 |
elif platform == "youtube":
|
| 583 |
-
return
|
| 584 |
elif platform == "facebook":
|
| 585 |
-
return
|
| 586 |
elif platform == "twitch":
|
| 587 |
-
return
|
| 588 |
elif platform == "spotify":
|
| 589 |
-
return
|
| 590 |
else:
|
| 591 |
raise ValueError("Invalid platform")
|
| 592 |
|
| 593 |
-
|
| 594 |
try:
|
| 595 |
-
session =
|
| 596 |
return f"Authenticated on {platform}"
|
| 597 |
except Exception as e:
|
| 598 |
return str(e)
|
| 599 |
|
| 600 |
-
|
| 601 |
try:
|
| 602 |
session = None
|
| 603 |
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 604 |
-
session =
|
| 605 |
-
|
| 606 |
-
for
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
|
|
|
| 617 |
return "Simulations started in the background."
|
| 618 |
|
| 619 |
except Exception as e:
|
|
@@ -622,8 +619,88 @@ async def simulate(urls: str, platform: str, count: int, delay: int, parallel_pr
|
|
| 622 |
def rand(min, max):
|
| 623 |
return random.randint(min, max)
|
| 624 |
|
| 625 |
-
with gr.Blocks(
|
| 626 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 627 |
with gr.Row():
|
| 628 |
urls = gr.Textbox(label="Video URLs (one per line)")
|
| 629 |
platform = gr.Dropdown(
|
|
|
|
| 1 |
import requests
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
+
from httpx import Client, HTTPError
|
| 4 |
from pydantic import BaseModel
|
| 5 |
import re
|
| 6 |
import urllib.parse
|
|
|
|
| 17 |
import time
|
| 18 |
from webdriver_manager.chrome import ChromeDriverManager
|
| 19 |
from tqdm import tqdm
|
| 20 |
+
import threading
|
| 21 |
import gradio as gr
|
| 22 |
|
| 23 |
load_dotenv()
|
|
|
|
| 108 |
else:
|
| 109 |
raise ValueError("Invalid URL format")
|
| 110 |
|
| 111 |
+
def instagram_login(username: str, password: str):
|
| 112 |
login_url = "https://www.instagram.com/accounts/login/ajax/"
|
| 113 |
+
session = requests.Session()
|
| 114 |
+
response = 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 = 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 |
+
def tiktok_login(username: str, password: str):
|
| 133 |
login_url = "https://www.tiktok.com/login/"
|
| 134 |
+
session = requests.Session()
|
| 135 |
+
login_data = {
|
| 136 |
+
"username": username,
|
| 137 |
+
"password": password
|
| 138 |
+
}
|
| 139 |
+
response = 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 |
+
def youtube_login(username: str, password: str):
|
| 146 |
login_url = "https://accounts.google.com/ServiceLogin"
|
| 147 |
+
session = requests.Session()
|
| 148 |
+
login_data = {
|
| 149 |
+
"username": username,
|
| 150 |
+
"password": password
|
| 151 |
+
}
|
| 152 |
+
response = 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 |
+
def facebook_login(username: str, password: str):
|
| 159 |
login_url = "https://www.facebook.com/login"
|
| 160 |
+
session = requests.Session()
|
| 161 |
+
login_data = {
|
| 162 |
+
"email": username,
|
| 163 |
+
"pass": password
|
| 164 |
+
}
|
| 165 |
+
response = 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 |
+
def twitch_login(username: str, password: str):
|
| 172 |
login_url = "https://www.twitch.tv/login"
|
| 173 |
+
session = requests.Session()
|
| 174 |
+
login_data = {
|
| 175 |
+
"login": username,
|
| 176 |
+
"password": password
|
| 177 |
+
}
|
| 178 |
+
response = 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 |
+
def spotify_login(username: str, password: str):
|
| 185 |
login_url = "https://accounts.spotify.com/api/token"
|
| 186 |
+
session = requests.Session()
|
| 187 |
+
login_data = {
|
| 188 |
+
"username": username,
|
| 189 |
+
"password": password
|
| 190 |
+
}
|
| 191 |
+
response = 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: Client):
|
| 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 |
+
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: Client):
|
| 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 |
+
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: Client):
|
| 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 |
+
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: Client):
|
| 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 |
+
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: Client):
|
| 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 |
+
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: Client):
|
| 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 |
+
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, session: Client = None):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 528 |
video_id = extract_video_id(url, platform)
|
| 529 |
proxy = get_random_proxy()
|
| 530 |
if not proxy:
|
|
|
|
| 544 |
simulate_twitch_view(video_id, proxy, session)
|
| 545 |
elif platform == "spotify":
|
| 546 |
simulate_spotify_view(video_id, proxy, session)
|
| 547 |
+
time.sleep(delay)
|
| 548 |
except Exception as e:
|
| 549 |
pass
|
| 550 |
|
| 551 |
+
def simulate_views_endpoint(request: VisitRequest):
|
| 552 |
try:
|
| 553 |
session = None
|
| 554 |
if os.getenv(f'{request.platform.upper()}_USER') and os.getenv(f'{request.platform.upper()}_PASSWORD'):
|
| 555 |
+
session = authenticate(os.getenv(f'{request.platform.upper()}_USER'), os.getenv(f'{request.platform.upper()}_PASSWORD'), request.platform)
|
| 556 |
+
|
| 557 |
+
threading.Thread(
|
| 558 |
+
target=simulate_views_background,
|
| 559 |
+
args=(
|
| 560 |
+
request.url,
|
| 561 |
+
request.platform,
|
| 562 |
+
request.count,
|
| 563 |
+
request.delay,
|
| 564 |
+
session,
|
| 565 |
)
|
| 566 |
+
).start()
|
| 567 |
|
| 568 |
return "Views simulation started in the background."
|
| 569 |
|
| 570 |
except Exception as e:
|
| 571 |
return str(e)
|
| 572 |
|
| 573 |
+
def authenticate(username: str, password: str, platform: str):
|
| 574 |
if platform == "instagram":
|
| 575 |
+
return instagram_login(username, password)
|
| 576 |
elif platform == "tiktok":
|
| 577 |
+
return tiktok_login(username, password)
|
| 578 |
elif platform == "youtube":
|
| 579 |
+
return youtube_login(username, password)
|
| 580 |
elif platform == "facebook":
|
| 581 |
+
return facebook_login(username, password)
|
| 582 |
elif platform == "twitch":
|
| 583 |
+
return twitch_login(username, password)
|
| 584 |
elif platform == "spotify":
|
| 585 |
+
return spotify_login(username, password)
|
| 586 |
else:
|
| 587 |
raise ValueError("Invalid platform")
|
| 588 |
|
| 589 |
+
def login(username: str, password: str, platform: str):
|
| 590 |
try:
|
| 591 |
+
session = authenticate(username, password, platform)
|
| 592 |
return f"Authenticated on {platform}"
|
| 593 |
except Exception as e:
|
| 594 |
return str(e)
|
| 595 |
|
| 596 |
+
def simulate(urls: str, platform: str, count: int, delay: int, parallel_processes: int):
|
| 597 |
try:
|
| 598 |
session = None
|
| 599 |
if os.getenv(f'{platform.upper()}_USER') and os.getenv(f'{platform.upper()}_PASSWORD'):
|
| 600 |
+
session = authenticate(os.getenv(f'{platform.upper()}_USER'), os.getenv(f'{platform.upper()}_PASSWORD'), platform)
|
| 601 |
+
|
| 602 |
+
for url in urls.split("\n"):
|
| 603 |
+
for _ in range(parallel_processes):
|
| 604 |
+
threading.Thread(
|
| 605 |
+
target=simulate_views_background,
|
| 606 |
+
args=(
|
| 607 |
+
url,
|
| 608 |
+
platform,
|
| 609 |
+
count,
|
| 610 |
+
delay,
|
| 611 |
+
session
|
| 612 |
+
)
|
| 613 |
+
).start()
|
| 614 |
return "Simulations started in the background."
|
| 615 |
|
| 616 |
except Exception as e:
|
|
|
|
| 619 |
def rand(min, max):
|
| 620 |
return random.randint(min, max)
|
| 621 |
|
| 622 |
+
with gr.Blocks(css="""
|
| 623 |
+
body {
|
| 624 |
+
background-color: #f0f0f0;
|
| 625 |
+
font-family: sans-serif;
|
| 626 |
+
}
|
| 627 |
+
.container {
|
| 628 |
+
background-color: #fff;
|
| 629 |
+
padding: 30px;
|
| 630 |
+
border-radius: 10px;
|
| 631 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
| 632 |
+
text-align: center;
|
| 633 |
+
animation: fadeIn 1s ease-in-out;
|
| 634 |
+
}
|
| 635 |
+
h1 {
|
| 636 |
+
color: #333;
|
| 637 |
+
margin-bottom: 20px;
|
| 638 |
+
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
|
| 639 |
+
}
|
| 640 |
+
form {
|
| 641 |
+
display: flex;
|
| 642 |
+
flex-direction: column;
|
| 643 |
+
width: 350px;
|
| 644 |
+
}
|
| 645 |
+
label {
|
| 646 |
+
margin-bottom: 5px;
|
| 647 |
+
font-weight: bold;
|
| 648 |
+
}
|
| 649 |
+
input[type="text"],
|
| 650 |
+
textarea,
|
| 651 |
+
select,
|
| 652 |
+
input[type="number"] {
|
| 653 |
+
padding: 10px;
|
| 654 |
+
margin-bottom: 15px;
|
| 655 |
+
border: 1px solid #ddd;
|
| 656 |
+
border-radius: 5px;
|
| 657 |
+
}
|
| 658 |
+
input[type="submit"] {
|
| 659 |
+
background-color: #007bff;
|
| 660 |
+
color: #fff;
|
| 661 |
+
border: none;
|
| 662 |
+
padding: 12px 20px;
|
| 663 |
+
border-radius: 5px;
|
| 664 |
+
cursor: pointer;
|
| 665 |
+
transition: background-color 0.3s;
|
| 666 |
+
}
|
| 667 |
+
input[type="submit"]:hover {
|
| 668 |
+
background-color: #0056b3;
|
| 669 |
+
}
|
| 670 |
+
@keyframes fadeIn {
|
| 671 |
+
from {
|
| 672 |
+
opacity: 0;
|
| 673 |
+
}
|
| 674 |
+
to {
|
| 675 |
+
opacity: 1;
|
| 676 |
+
}
|
| 677 |
+
}
|
| 678 |
+
""") as interface:
|
| 679 |
+
gr.Markdown("""
|
| 680 |
+
<div class="container">
|
| 681 |
+
<h1>Video Views Simulator</h1>
|
| 682 |
+
<form action="/simulate" method="post">
|
| 683 |
+
<label for="urls">Video URLs (one per line):</label><br>
|
| 684 |
+
<textarea id="urls" name="urls"></textarea><br><br>
|
| 685 |
+
<label for="platform">Platform:</label><br>
|
| 686 |
+
<select id="platform" name="platform">
|
| 687 |
+
<option value="instagram">Instagram</option>
|
| 688 |
+
<option value="tiktok">TikTok</option>
|
| 689 |
+
<option value="youtube">YouTube</option>
|
| 690 |
+
<option value="facebook">Facebook</option>
|
| 691 |
+
<option value="twitch">Twitch</option>
|
| 692 |
+
<option value="spotify">Spotify</option>
|
| 693 |
+
</select><br><br>
|
| 694 |
+
<label for="count">Number of Views:</label><br>
|
| 695 |
+
<input type="number" id="count" name="count" value="1"><br><br>
|
| 696 |
+
<label for="delay">Delay (seconds):</label><br>
|
| 697 |
+
<input type="number" id="delay" name="delay" value="1"><br><br>
|
| 698 |
+
<label for="parallel_processes">Parallel Processes:</label><br>
|
| 699 |
+
<input type="number" id="parallel_processes" name="parallel_processes" value="1"><br><br>
|
| 700 |
+
<input type="submit" value="Simulate">
|
| 701 |
+
</form>
|
| 702 |
+
</div>
|
| 703 |
+
""")
|
| 704 |
with gr.Row():
|
| 705 |
urls = gr.Textbox(label="Video URLs (one per line)")
|
| 706 |
platform = gr.Dropdown(
|