Fred808 commited on
Commit
ec48a63
·
verified ·
1 Parent(s): 9d108c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -176
app.py CHANGED
@@ -1,104 +1,20 @@
1
  import os
2
  import time
3
  import json
4
- import requests
 
5
  from huggingface_hub import upload_file
6
 
7
  # === CONFIGURATION ===
8
  HF_TOKEN = os.environ.get("HF_TOKEN")
9
  REPO_ID = "Fred808/BG1"
10
  DATA_PATH = "AEffects"
11
- BASE_URL = "https://fred808-yt1.hf.space"
12
- INIT_API_URL = f"{BASE_URL}/batch/download"
13
- STATUS_API_URL = f"{BASE_URL}/batch/status/{{}}"
14
- FETCH_API_URL = f"{BASE_URL}/batch/download-all/{{}}"
15
  PROCESSED_FILE = "processed.json"
16
  OUTPUT_DIR = "batch_downloads"
17
 
18
- VIDEO_URLS = [
19
- "https://youtu.be/__gJ9VL9z-c",
20
- "https://youtu.be/bAcmb9PGzIE",
21
- "https://youtu.be/aO0eUnu0hO0",
22
- "https://youtu.be/fsLO1F5x7yM",
23
- "https://youtu.be/XcJyW5iBKlU",
24
- "https://youtu.be/md8mbgTEfIk",
25
- "https://www.youtube.com/playlist?list=PLxj9fixyu7Pbhy8o_Teys78waXmoxmQVZ",
26
- "https://www.youtube.com/playlist?list=PLsGl9GczcgBsv58A4sTYSmLDhipykRS4O",
27
- "https://youtu.be/Wg244y2f9Fw",
28
- "https://m.youtube.com/watch?v=aafyp5g1CjI",
29
- "https://youtu.be/Aj1x89EFc8M",
30
- "https://youtu.be/SNHBFtdGWhg",
31
- "https://www.youtube.com/playlist?list=PLVm7O9OzjT6EIDtFGC67QxGsHkz3_RbIw",
32
- "https://www.youtube.com/playlist?list=PL-J0k20j-Ffh5IWHjeT2Je-asx7YkFbj6",
33
- "https://www.youtube.com/playlist?list=PLsGl9GczcgBsZdwrobBkXT_A8jse09yRz",
34
- "https://www.youtube.com/c/BlenderMadeEasy",
35
- "https://youtu.be/8tViVXgu7fo",
36
- "https://youtu.be/aTeLyeVO0Dc",
37
- "https://youtu.be/RRilLLyyn1Y",
38
- "https://youtu.be/567FFSk23Io",
39
- "https://youtu.be/KO29y5eW61g",
40
- "https://youtu.be/Y1bOokHzEAk",
41
- "https://youtu.be/k-mEz54_p90",
42
- "https://www.youtube.com/playlist?list=PLNShHVjao84dTJDUQA9dPNTGsox16p1iV",
43
- "https://youtu.be/tWvgHbZXCtA",
44
- "https://youtu.be/4yrsAiTdMj4",
45
- "https://youtu.be/HDBZ7CwlfIs",
46
- "https://youtu.be/vuiS9Ypanu8",
47
- "https://youtu.be/-F6oaJzyr4A",
48
- "https://youtu.be/nxU4jXUYPEg",
49
- "https://youtu.be/abafsArInDE",
50
- "https://youtu.be/v0pIfh3Unz0",
51
- "https://youtu.be/Td8GUnhZeao",
52
- "https://youtu.be/VlSs430PAeU",
53
- "https://youtu.be/xt5dWu15uM4",
54
- "https://youtu.be/c3FnWQTMo9s",
55
- "https://youtu.be/B0J27sf9N1Y",
56
- "https://youtu.be/lLqep5Q4MiI",
57
- "https://youtu.be/Q30-nakUrSM",
58
- "https://youtu.be/HSm-cq7zd2s",
59
- "https://youtu.be/x6oWgtJInCQ",
60
- "https://youtu.be/9gn_1V1sCS8",
61
- "https://youtu.be/dIv2FXyD3CU",
62
- "https://youtu.be/ABayYXu7OfI",
63
- "https://youtu.be/-c0Evpf8V3A",
64
- "https://www.youtube.com/playlist?list=PLgO2ChD7acqHzccBuhAGw8dTPLnR1E3QB",
65
- "https://www.youtube.com/user/AndrewPPrice/videos",
66
- "https://www.youtube.com/playlist?list=PL2aDImegRwZFMIdrSdn2DCapf98I-LJsf",
67
- "https://youtu.be/n6V8v5PlvGI",
68
- "https://youtu.be/XO783U-B5bg",
69
- "https://youtu.be/G17sBkp-DIk",
70
- "https://youtu.be/VMLW6XW0k6U",
71
- "https://youtu.be/WgZ1K3J3RGU",
72
- "https://youtu.be/DEx1nwxRzXQ",
73
- "https://youtu.be/xbKDdRDLhJ8",
74
- "https://youtu.be/F5Z8rj-fekU",
75
- "https://youtu.be/wkX0z6ygng4",
76
- "https://youtu.be/rg-VJGf3Z8E",
77
- "https://youtu.be/Bkme3OeK6DM",
78
- "https://youtu.be/FsniCv0L-7E",
79
- "https://youtu.be/fZrY5n-wqZQ",
80
- "https://youtu.be/XGHBtvnvz9U",
81
- "https://youtu.be/SXOXeN5uzVw",
82
- "https://youtu.be/Pv8P8yYvPMY",
83
- "https://youtu.be/J5t7gzIfTt0",
84
- "https://youtu.be/xtdE6TLkOkQ",
85
- "https://youtu.be/AY1GBG8PBuU",
86
- "https://youtu.be/R1tv1mgiOkQ",
87
- "https://youtu.be/HJSGo",
88
- "https://youtu.be/5B244CYX1Tw",
89
- "https://youtu.be/OPCWsTtIZ8Y",
90
- "https://youtu.be/FxLy1X3DLhw",
91
- "https://youtu.be/PSptnmU1GRg",
92
- "https://youtu.be/S4jF-8zKRYA",
93
- "https://youtu.be/N_F5hpeiPJA",
94
- "https://youtu.be/7ZJ2WuqjX9w",
95
- "https://youtu.be/F8kCZwJg3VA",
96
- "https://youtu.be/tbJY_k1jM7w",
97
- "https://youtu.be/kDwS1zqD4XY",
98
- "https://youtu.be/mK9B1E4wKZI",
99
- "https://youtu.be/QY4EVmF3_mM",
100
- "https://youtu.be/A2P9BZez8L0",
101
- "https://youtu.be/U7Qxp5-VWXs"
102
  ]
103
 
104
  # === Load processed videos ===
@@ -112,10 +28,6 @@ def save_processed():
112
  with open(PROCESSED_FILE, "w") as f:
113
  json.dump(list(processed_urls), f, indent=2)
114
 
115
- def chunk_urls(lst, n):
116
- for i in range(0, len(lst), n):
117
- yield lst[i:i + n]
118
-
119
  def upload_to_dataset(filepath):
120
  try:
121
  upload_file(
@@ -136,94 +48,47 @@ if os.path.exists(OUTPUT_DIR):
136
  else:
137
  os.makedirs(OUTPUT_DIR)
138
 
139
- # === Process in batches ===
140
- unprocessed_urls = [url for url in VIDEO_URLS if url not in processed_urls]
141
-
142
- for batch in chunk_urls(unprocessed_urls, 20):
143
- print(f"\n[*] Submitting batch of {len(batch)} URLs...")
144
  try:
145
- res = requests.post(INIT_API_URL, json={"urls": batch})
146
- res.raise_for_status()
147
- batch_id = res.json().get("batch_id")
148
- if not batch_id:
149
- raise Exception("No batch_id returned.")
150
- print(f"[+] Batch submitted. ID: {batch_id}")
151
- except Exception as e:
152
- print(f"[!] Submission error: {e}")
153
- continue
154
-
155
- # === Wait until all videos in batch are fully processed ===
156
- status_url = STATUS_API_URL.format(batch_id)
157
- print("[*] Waiting for all batch videos to be processed...")
158
-
159
- while True:
160
- try:
161
- res = requests.get(status_url)
162
- res.raise_for_status()
163
- data = res.json()
164
-
165
- total = int(data.get("total_urls", 0))
166
- completed = data.get("completed", 0)
167
- failed = data.get("failed", 0)
168
 
169
- print(f"[~] Status: {data.get('status')} — {completed}/{total} done, {failed} failed.")
 
170
 
171
- if completed >= total:
172
- print(f"[✓] Batch fully processed: {completed}/{total} completed.")
173
- break
174
- elif failed > 0 and completed + failed >= total:
175
- print(f"[!] Batch has failed videos — retrying in 30s...")
176
- else:
177
- print(f"[~] Still waiting...")
178
 
179
- except Exception as e:
180
- print(f"[!] Error checking status: {e}")
 
 
181
 
182
- time.sleep(5)
183
 
184
- # === Fetch download links ===
185
- fetch_url = FETCH_API_URL.format(batch_id)
186
- print("[*] Fetching download list...")
187
- try:
188
- res = requests.get(fetch_url)
189
- res.raise_for_status()
190
- downloads = res.json().get("downloads", [])
191
- if not downloads:
192
- print("[!] No downloads returned.")
193
- continue
194
- print(f"[+] Found {len(downloads)} videos.")
195
- except Exception as e:
196
- print(f"[!] Failed to fetch download list: {e}")
197
- continue
198
-
199
- # === Download and upload ===
200
- for video, url in zip(downloads, batch):
201
- filename = video.get("filename")
202
- file_url = video.get("url")
203
- if not filename or not file_url:
204
- print("[!] Skipping invalid entry.")
205
- continue
206
-
207
- if file_url.startswith("/"):
208
- file_url = BASE_URL + file_url
209
-
210
- local_path = os.path.join(OUTPUT_DIR, filename)
211
- try:
212
- print(f"[*] Downloading {filename}...")
213
- with requests.get(file_url, stream=True) as r:
214
- r.raise_for_status()
215
- with open(local_path, "wb") as f:
216
- for chunk in r.iter_content(chunk_size=8192):
217
- f.write(chunk)
218
- print(f"[✓] Downloaded: {filename}")
219
- upload_to_dataset(local_path)
220
- processed_urls.add(url)
221
- save_processed()
222
- os.remove(local_path)
223
- except Exception as e:
224
- print(f"[!] Error downloading/uploading {filename}: {e}")
225
 
226
- print("[⏱] Waiting 30s before next batch...\n")
227
- time.sleep(30)
228
 
229
- print("\n✅ Done. All batches fully processed.")
 
1
  import os
2
  import time
3
  import json
4
+ import asyncio
5
+ from torrentp import TorrentDownloader
6
  from huggingface_hub import upload_file
7
 
8
  # === CONFIGURATION ===
9
  HF_TOKEN = os.environ.get("HF_TOKEN")
10
  REPO_ID = "Fred808/BG1"
11
  DATA_PATH = "AEffects"
 
 
 
 
12
  PROCESSED_FILE = "processed.json"
13
  OUTPUT_DIR = "batch_downloads"
14
 
15
+ # Placeholder for magnet links - these will replace the original VIDEO_URLS
16
+ MAGNET_LINKS = [
17
+ "magnet:?xt=urn:btih:18ED0A9276EA0324DFE1683A13E52DEB7C36CC1B&dn=Digital+Tutors+Creating+A+High-Speed+Camera+Effect+With+After+Effects&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.publicbt.com%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.prq.to%2Fannounce&tr=udp%3A%2F%2F10.rarbg.me%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.token.ro%3A80%2Fannounce&tr=udp%3A%2F%2F10.rarbg.com%2Fannounce&tr=http%3A%2F%2Ftracker.torrentfrancais.com%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2710%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2F11.rarbg.com%2Fannounce&tr=http%3A%2F%2Ftracker.ex.ua%2Fannounce&tr=http%3A%2F%2Ftorrent.gresille.org%2Fannounce&tr=http%3A%2F%2F94.228.192.98%2Fannounce&tr=udp%3A%2F%2Ftracker.istole.it%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Fcoppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.zer0day.to%3A1337%2Fannounce"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  ]
19
 
20
  # === Load processed videos ===
 
28
  with open(PROCESSED_FILE, "w") as f:
29
  json.dump(list(processed_urls), f, indent=2)
30
 
 
 
 
 
31
  def upload_to_dataset(filepath):
32
  try:
33
  upload_file(
 
48
  else:
49
  os.makedirs(OUTPUT_DIR)
50
 
51
+ async def download_and_upload_torrent(magnet_link):
52
+ print(f"[*] Starting download for: {magnet_link}")
 
 
 
53
  try:
54
+ # Initialize TorrentDownloader with magnet link and output directory
55
+ # stop_after_download=True ensures it stops seeding after download
56
+ torrent_downloader = TorrentDownloader(magnet_link, OUTPUT_DIR, stop_after_download=True)
57
+ await torrent_downloader.start_download()
58
+ print(f"[✓] Downloaded: {magnet_link}")
59
+
60
+ # Find the downloaded file(s) in the output directory
61
+ # This part might need refinement based on how torrentp names files/folders
62
+ downloaded_files = []
63
+ for root, _, files in os.walk(OUTPUT_DIR):
64
+ for file in files:
65
+ downloaded_files.append(os.path.join(root, file))
66
+
67
+ if not downloaded_files:
68
+ print(f"[!] No files found after downloading {magnet_link}")
69
+ return
70
+
71
+ for local_path in downloaded_files:
72
+ upload_to_dataset(local_path)
73
+ os.remove(local_path) # Clean up local file after upload
74
+
75
+ processed_urls.add(magnet_link)
76
+ save_processed()
77
 
78
+ except Exception as e:
79
+ print(f"[!] Error downloading/uploading {magnet_link}: {e}")
80
 
81
+ async def main():
82
+ unprocessed_links = [link for link in MAGNET_LINKS if link not in processed_urls]
 
 
 
 
 
83
 
84
+ for link in unprocessed_links:
85
+ await download_and_upload_torrent(link)
86
+ print("[⏱] Waiting 5s before next torrent...\n")
87
+ time.sleep(5) # Small delay between torrents
88
 
89
+ print("\n✅ Done. All torrents processed.")
90
 
91
+ if __name__ == "__main__":
92
+ asyncio.run(main())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
 
 
94