Arnold Manzano commited on
Commit
05f636c
·
1 Parent(s): 886bcf1

Adding bulk swap

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py CHANGED
@@ -135,6 +135,11 @@ async def index():
135
  <input type="text" name="url" placeholder="Paste Image/Video URL..." style="width:300px;" required>
136
  <button type="submit">Start Swapping</button>
137
  </form>
 
 
 
 
 
138
  <form action="/process-gallery" method="post">
139
  <input type="text" name="page_url" placeholder="Paste Gallery Page URL..." required>
140
  <button type="submit">Bulk Swap Gallery</button>
@@ -201,6 +206,35 @@ async def process_swap(background_tasks: BackgroundTasks, url: str = Form(...)):
201
  <a href="/">Back to Home</a>
202
  """)
203
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
204
  @app.post("/process-gallery")
205
  async def process_gallery(background_tasks: BackgroundTasks, page_url: str = Form(...)):
206
  global running_and_queued_count
 
135
  <input type="text" name="url" placeholder="Paste Image/Video URL..." style="width:300px;" required>
136
  <button type="submit">Start Swapping</button>
137
  </form>
138
+ <form action="/process-bulk" method="post">
139
+ <textarea name="urls_text" rows="8" placeholder="Paste multiple links here (one per line)..." style="width:100%; max-width:500px; padding:10px; border-radius:8px; border:1.5px solid #ccc;"></textarea>
140
+ <br><br>
141
+ <button type="submit">Queue All Links</button>
142
+ </form>
143
  <form action="/process-gallery" method="post">
144
  <input type="text" name="page_url" placeholder="Paste Gallery Page URL..." required>
145
  <button type="submit">Bulk Swap Gallery</button>
 
206
  <a href="/">Back to Home</a>
207
  """)
208
 
209
+ @app.post("/process-bulk")
210
+ async def process_bulk(background_tasks: BackgroundTasks, urls_text: str = Form(...)):
211
+ global running_and_queued_count
212
+
213
+ # Split by newline, strip spaces, and remove empty strings
214
+ urls = [line.strip() for line in urls_text.splitlines() if line.strip()]
215
+
216
+ if not urls:
217
+ return HTMLResponse(content="<h1>No URLs provided</h1><a href='/'>Back</a>")
218
+
219
+ headers = {
220
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
221
+ }
222
+
223
+ count = 0
224
+ for url in urls:
225
+ target_path, output_path = generate_paths(url)
226
+ print(f"###### Queueing bulk job {url}")
227
+
228
+ running_and_queued_count += 1
229
+ background_tasks.add_task(background_worker, url, target_path, output_path, headers)
230
+ count += 1
231
+
232
+ return HTMLResponse(content=f"""
233
+ <h1>Bulk Jobs Queued!</h1>
234
+ <p>Added <strong>{count}</strong> URLs to the processing queue.</p>
235
+ <a href="/">Back to Home</a>
236
+ """)
237
+
238
  @app.post("/process-gallery")
239
  async def process_gallery(background_tasks: BackgroundTasks, page_url: str = Form(...)):
240
  global running_and_queued_count