Fred808 commited on
Commit
179ebbf
Β·
verified Β·
1 Parent(s): b9d8908

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -75
app.py CHANGED
@@ -7,7 +7,7 @@ from huggingface_hub import upload_file
7
  # === CONFIGURATION ===
8
  HF_TOKEN = os.environ.get("HF_TOKEN")
9
  REPO_ID = "Fred808/BG1"
10
- DATA_PATH = "Blenders"
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/{{}}"
@@ -16,60 +16,92 @@ PROCESSED_FILE = "processed.json"
16
  OUTPUT_DIR = "batch_downloads"
17
 
18
  VIDEO_URLS = [
19
- "https://youtu.be/wJe9zz_G4js",
20
- "https://youtu.be/6RKL-j1k4Dc",
21
- "https://youtu.be/tK848ib0BBw",
22
- "https://youtu.be/r6ZQil-zd5Y",
23
- "https://youtu.be/-gbCSnkvwNo",
24
- "https://youtu.be/oso5I277FRY",
25
- "https://youtu.be/4haAdmHqGOw",
26
- "https://youtu.be/OeGULgqwJh8",
27
- "https://youtu.be/QtIfb9JXOJg",
28
- "https://youtu.be/lgljOqhhgHg",
29
- "https://youtu.be/bokz-7HbgGM",
30
- "https://youtu.be/-CiHJ41n6VI",
31
- "https://youtu.be/Ys4793edotw",
32
- "https://youtu.be/9N87-yRR5aE",
33
- "https://youtu.be/5WOrfMz2Sqs",
34
- "https://youtu.be/1qVbGr_ie30",
35
- "https://youtu.be/qa_1LjeWsJg",
36
- "https://youtu.be/9OVvnOh2ZGk",
37
- "https://youtu.be/xEpVyEi1Hts",
38
- "https://youtu.be/Wg244y2f9Fw",
39
- "https://youtu.be/a-4oCHe-hDE",
40
- "https://youtu.be/Q30-nakUrSM",
41
- "https://youtu.be/HSm-cq7zd2s",
42
- "https://youtu.be/x6oWgtJInCQ",
43
- "https://youtu.be/9gn_1V1sCS8",
44
- "https://youtu.be/dIv2FXyD3CU",
45
- "https://youtu.be/SGUBriL9bNU",
46
- "https://youtu.be/ABayYXu7OfI",
47
- "https://youtu.be/-c0Evpf8V3A",
48
- "https://youtu.be/F7VggbBaCsg",
49
- "https://youtu.be/cn5BC3Vzcsc",
50
- "https://youtu.be/TbjEVSNPiMQ",
51
- "https://youtu.be/2PNiRWStZIo",
52
- "https://youtu.be/UEeXv1bczuE",
53
- "https://youtu.be/mYgznqvbisM",
54
- "https://youtu.be/VMLW6XW0k6U",
55
- "https://youtu.be/G17sBkp-DIk",
56
- "https://youtu.be/XO783U-B5bg",
57
- "https://youtu.be/n6V8v5PlvGI",
58
- "https://youtu.be/VFSg3DkGSXQ",
59
- "https://youtu.be/WgZ1K3J3RGU",
60
- "https://youtu.be/DEx1nwxRzXQ",
61
- "https://youtu.be/xbKDdRDLhJ8",
62
- "https://youtu.be/F5Z8rj-fekU",
63
- "https://youtu.be/wkX0z6ygng4",
64
- "https://youtu.be/rg-VJGf3Z8E",
65
- "https://youtu.be/Bkme3OeK6DM",
66
- "https://youtu.be/FsniCv0L-7E",
67
- "https://youtu.be/fZrY5n-wqZQ",
68
- "https://youtu.be/XGHBtvnvz9U"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  ]
70
 
71
-
72
- # === Load processed ===
73
  if os.path.exists(PROCESSED_FILE):
74
  with open(PROCESSED_FILE, "r") as f:
75
  processed_urls = set(json.load(f))
@@ -94,22 +126,19 @@ def upload_to_dataset(filepath):
94
  token=HF_TOKEN
95
  )
96
  print(f"[↑] Uploaded: {filepath}")
97
- return True
98
  except Exception as e:
99
  print(f"[!] Upload failed: {filepath} β€” {e}")
100
- return False
101
 
102
- # === Prepare output folder ===
103
  if os.path.exists(OUTPUT_DIR):
104
- for f in os.listdir(OUTPUT_DIR):
105
- os.remove(os.path.join(OUTPUT_DIR, f))
106
  else:
107
  os.makedirs(OUTPUT_DIR)
108
 
109
- # === Filter unprocessed URLs ===
110
  unprocessed_urls = [url for url in VIDEO_URLS if url not in processed_urls]
111
 
112
- # === Process in batches ===
113
  for batch in chunk_urls(unprocessed_urls, 20):
114
  print(f"\n[*] Submitting batch of {len(batch)} URLs...")
115
  try:
@@ -126,29 +155,33 @@ for batch in chunk_urls(unprocessed_urls, 20):
126
  # === Wait until all videos in batch are fully processed ===
127
  status_url = STATUS_API_URL.format(batch_id)
128
  print("[*] Waiting for all batch videos to be processed...")
 
129
  while True:
130
  try:
131
  res = requests.get(status_url)
132
  res.raise_for_status()
133
  data = res.json()
134
 
135
- total = data.get("total_urls", "?")
136
  completed = data.get("completed", 0)
137
  failed = data.get("failed", 0)
138
- status = data.get("status")
139
 
140
- print(f"[~] Status: {status} β€” {completed}/{total} done, {failed} failed.")
141
 
142
- if completed + failed >= int(total):
143
- print(f"[βœ“] Batch fully processed: {completed} completed, {failed} failed.")
144
  break
 
 
 
 
145
 
146
  except Exception as e:
147
  print(f"[!] Error checking status: {e}")
148
 
149
  time.sleep(5)
150
 
151
- # === Fetch download list ===
152
  fetch_url = FETCH_API_URL.format(batch_id)
153
  print("[*] Fetching download list...")
154
  try:
@@ -163,7 +196,7 @@ for batch in chunk_urls(unprocessed_urls, 20):
163
  print(f"[!] Failed to fetch download list: {e}")
164
  continue
165
 
166
- # === Download & upload ===
167
  for video, url in zip(downloads, batch):
168
  filename = video.get("filename")
169
  file_url = video.get("url")
@@ -175,7 +208,6 @@ for batch in chunk_urls(unprocessed_urls, 20):
175
  file_url = BASE_URL + file_url
176
 
177
  local_path = os.path.join(OUTPUT_DIR, filename)
178
-
179
  try:
180
  print(f"[*] Downloading {filename}...")
181
  with requests.get(file_url, stream=True) as r:
@@ -184,15 +216,12 @@ for batch in chunk_urls(unprocessed_urls, 20):
184
  for chunk in r.iter_content(chunk_size=8192):
185
  f.write(chunk)
186
  print(f"[βœ“] Downloaded: {filename}")
187
- except Exception as e:
188
- print(f"[!] Download failed: {filename} β€” {e}")
189
- continue
190
-
191
- # Upload
192
- if upload_to_dataset(local_path):
193
  processed_urls.add(url)
194
  save_processed()
195
- os.remove(local_path)
 
 
196
 
197
  print("[⏱] Waiting 30s before next batch...\n")
198
  time.sleep(30)
 
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/{{}}"
 
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 ===
 
105
  if os.path.exists(PROCESSED_FILE):
106
  with open(PROCESSED_FILE, "r") as f:
107
  processed_urls = set(json.load(f))
 
126
  token=HF_TOKEN
127
  )
128
  print(f"[↑] Uploaded: {filepath}")
 
129
  except Exception as e:
130
  print(f"[!] Upload failed: {filepath} β€” {e}")
 
131
 
132
+ # === Create output folder ===
133
  if os.path.exists(OUTPUT_DIR):
134
+ for file in os.listdir(OUTPUT_DIR):
135
+ os.remove(os.path.join(OUTPUT_DIR, file))
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:
 
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:
 
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")
 
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:
 
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)