Ffftdtd5dtft commited on
Commit
37649a3
·
verified ·
1 Parent(s): c5ae5c7

Create main.py

Browse files
Files changed (1) hide show
  1. main.py +233 -0
main.py ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, BackgroundTasks, HTTPException, Form
2
+ from fastapi.responses import PlainTextResponse, HTMLResponse
3
+ from fastapi.staticfiles import StaticFiles
4
+ from pydantic import BaseModel
5
+ import requests
6
+ from requests.exceptions import ProxyError, ConnectTimeout
7
+ from faker import Faker
8
+ import re
9
+ from concurrent.futures import ThreadPoolExecutor
10
+ import urllib.parse
11
+ import time
12
+ import gradio as gr
13
+
14
+ app = FastAPI()
15
+ fake = Faker()
16
+
17
+ class Proxy(BaseModel):
18
+ ip: str
19
+ port: str
20
+
21
+ class VisitRequest(BaseModel):
22
+ url: str
23
+ platform: str
24
+ count: int
25
+ delay: int
26
+ parallel_processes: int
27
+
28
+ app.mount("/static", StaticFiles(directory="static"), name="static")
29
+
30
+ def get_random_proxy():
31
+ pubproxy_url = "http://pubproxy.com/api/proxy?limit=1"
32
+ response = requests.get(pubproxy_url, verify=False)
33
+ data = response.json()
34
+ if data['data']:
35
+ proxy_data = data['data'][0]
36
+ return f"{proxy_data['ip']}:{proxy_data['port']}"
37
+ return None
38
+
39
+ @app.get("/get_proxies", response_class=PlainTextResponse)
40
+ def get_proxies():
41
+ try:
42
+ proxies = []
43
+ pubproxy_url = "http://pubproxy.com/api/proxy?limit=5"
44
+ response = requests.get(pubproxy_url, verify=False)
45
+ data = response.json()
46
+
47
+ for proxy_data in data['data']:
48
+ ip, port = proxy_data['ipPort'].split(":")
49
+ proxy = f"{ip}:{port}"
50
+ proxies.append(proxy)
51
+
52
+ return "\n".join(proxies)
53
+ except Exception as e:
54
+ return PlainTextResponse(str(e), status_code=500)
55
+
56
+ @app.get("/rotate_ip", response_class=PlainTextResponse)
57
+ def rotate_ip():
58
+ try:
59
+ random_ip = fake.ipv4()
60
+
61
+ headers = {
62
+ "X-Forwarded-For": random_ip,
63
+ "Client-IP": random_ip,
64
+ "X-Real-IP": random_ip
65
+ }
66
+
67
+ test_url = "http://pubproxy.com/api/proxy?limit=1&type=http&https=true&speed=60"
68
+ response = requests.get(test_url, headers=headers, verify=False)
69
+ data = response.json()
70
+
71
+ proxies = []
72
+ for proxy_data in data['data']:
73
+ ip, port = proxy_data['ipPort'].split(":")
74
+ proxy = f"{ip}:{port}"
75
+ proxies.append(proxy)
76
+
77
+ return "\n".join(proxies)
78
+ except ProxyError as e:
79
+ return PlainTextResponse(f"ProxyError: {str(e)}", status_code=500)
80
+ except ConnectTimeout as e:
81
+ return PlainTextResponse(f"ConnectTimeoutError: {str(e)}", status_code=500)
82
+ except Exception as e:
83
+ return PlainTextResponse(str(e), status_code=500)
84
+
85
+ def extract_video_id(url: str, platform: str) -> str:
86
+ url = urllib.parse.unquote(url) # Decode the URL
87
+ if platform == "instagram":
88
+ match = re.search(r"instagram\.com/reel/([^/?]+)", url)
89
+ elif platform == "tiktok":
90
+ match = re.search(r"tiktok\.com/@[^/]+/video/(\d+)", url)
91
+ elif platform == "youtube":
92
+ match = re.search(r"youtube\.com/watch\?v=([^&]+)", url)
93
+ elif platform == "facebook":
94
+ match = re.search(r"facebook\.com/.*/videos/(\d+)", url)
95
+ elif platform == "twitch":
96
+ match = re.search(r"twitch\.tv/videos/(\d+)", url)
97
+ elif platform == "spotify":
98
+ match = re.search(r"spotify\.com/track/([^/?]+)", url)
99
+ else:
100
+ match = None
101
+
102
+ if match:
103
+ return match.group(1)
104
+ else:
105
+ raise ValueError("Invalid URL format")
106
+
107
+ def simulate_view(video_id: str, platform: str, proxy: str, delay: int):
108
+ proxies = {
109
+ "http": f"http://{proxy}",
110
+ "https": f"http://{proxy}"
111
+ }
112
+ fake_ipv4 = fake.ipv4()
113
+ headers = {
114
+ "User-Agent": fake.user_agent(),
115
+ "X-Forwarded-For": fake_ipv4,
116
+ "Client-IP": fake_ipv4,
117
+ "X-Real-IP": fake_ipv4
118
+ }
119
+ try:
120
+ if platform == "instagram":
121
+ view_url = f"http://www.instagram.com/p/{video_id}?autoplay=true"
122
+ elif platform == "tiktok":
123
+ view_url = f"http://www.tiktok.com/@{video_id}?autoplay=true"
124
+ elif platform == "youtube":
125
+ view_url = f"http://www.youtube.com/watch?v={video_id}&autoplay=1"
126
+ elif platform == "facebook":
127
+ view_url = f"http://www.facebook.com/watch/?v={video_id}&autoplay=1"
128
+ elif platform == "twitch":
129
+ view_url = f"http://www.twitch.tv/videos/{video_id}?autoplay=true"
130
+ elif platform == "spotify":
131
+ view_url = f"http://open.spotify.com/track/{video_id}?autoplay=true"
132
+ else:
133
+ raise ValueError("Invalid platform")
134
+
135
+ response = requests.get(view_url, headers=headers, proxies=proxies, timeout=10)
136
+ time.sleep(delay)
137
+ except Exception as e:
138
+ print(f"Error in simulate_view: {e}")
139
+
140
+ def perform_views(url: str, platform: str, count: int, delay: int, parallel_processes: int):
141
+ video_id = extract_video_id(url, platform)
142
+
143
+ def task():
144
+ try:
145
+ proxy_response = requests.get("http://0.0.0.0:8000/rotate_ip")
146
+ if proxy_response.status_code == 200:
147
+ proxy = proxy_response.text.strip()
148
+ if proxy:
149
+ simulate_view(video_id, platform, proxy, delay)
150
+ except Exception as e:
151
+ print(f"Error in perform_views: {e}")
152
+
153
+ with ThreadPoolExecutor(max_workers=parallel_processes) as executor:
154
+ for _ in range(count):
155
+ executor.submit(task)
156
+
157
+ @app.post("/increase_views", response_class=PlainTextResponse)
158
+ def increase_views(
159
+ url: str = Form(...),
160
+ platform: str = Form(...),
161
+ count: int = Form(...),
162
+ delay: int = Form(...),
163
+ parallel_processes: int = Form(...),
164
+ background_tasks: BackgroundTasks = BackgroundTasks()
165
+ ):
166
+ if platform not in ["instagram", "tiktok", "youtube", "facebook", "twitch", "spotify"]:
167
+ raise HTTPException(status_code=400, detail="Invalid platform. Choose 'instagram', 'tiktok', 'youtube', 'facebook', 'twitch', or 'spotify'.")
168
+
169
+ background_tasks.add_task(perform_views, url, platform, count, delay, parallel_processes)
170
+ return PlainTextResponse(f"Started {count} view tasks for {platform} at {url} with {delay} seconds delay and {parallel_processes} parallel processes.")
171
+
172
+ def increase_views_gradio(url, platform, count, delay, parallel_processes):
173
+ return increase_views(url, platform, count, delay, parallel_processes, background_tasks=BackgroundTasks())
174
+
175
+ iface = gr.Interface(
176
+ fn=increase_views_gradio,
177
+ inputs=[
178
+ gr.Textbox(label="URL"),
179
+ gr.Dropdown(["instagram", "tiktok", "youtube", "facebook", "twitch", "spotify"], label="Platform"),
180
+ gr.Number(label="View Count", minimum=1),
181
+ gr.Number(label="Delay (seconds)", minimum=1),
182
+ gr.Number(label="Parallel Processes", minimum=1),
183
+ ],
184
+ outputs="text",
185
+ title="Increase Views",
186
+ description="Increase views on your favorite social media platforms.",
187
+ )
188
+
189
+ @app.get("/form", response_class=HTMLResponse)
190
+ def form():
191
+ return iface.render()
192
+
193
+ @app.get("/", response_class=HTMLResponse)
194
+ def read_root():
195
+ html_content = """
196
+ <!DOCTYPE html>
197
+ <html lang="en">
198
+ <head>
199
+ <meta charset="UTF-8">
200
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
201
+ <title>Main Page</title>
202
+ <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
203
+ <style>
204
+ body {
205
+ background-color: #f8f9fa;
206
+ }
207
+ .container {
208
+ margin-top: 50px;
209
+ text-align: center;
210
+ }
211
+ h1 {
212
+ color: #343a40;
213
+ }
214
+ .btn {
215
+ margin: 10px;
216
+ }
217
+ </style>
218
+ </head>
219
+ <body>
220
+ <div class="container">
221
+ <h1>Welcome</h1>
222
+ <p>Choose an action:</p>
223
+ <a href="/rotate_ip"><button class="btn btn-primary">Rotate IP</button></a>
224
+ <a href="/form"><button class="btn btn-primary">Increase Views</button></a>
225
+ </div>
226
+ </body>
227
+ </html>
228
+ """
229
+ return HTMLResponse(content=html_content)
230
+
231
+ if __name__ == "__main__":
232
+ import uvicorn
233
+ iface.launch(share=True)