tecuts commited on
Commit
0532bd9
·
verified ·
1 Parent(s): 82c6cbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -87,6 +87,7 @@ class DownloadRequest(BaseModel):
87
  url: str
88
 
89
 
 
90
  # [Previous cookie handling code remains the same...]
91
 
92
  class FileInfo(BaseModel):
@@ -153,18 +154,16 @@ async def download_file(request: DownloadRequest):
153
 
154
  for file_path in all_files:
155
  try:
156
- # Convert to absolute path
157
- abs_file_path = os.path.abspath(file_path)
158
  filename = os.path.basename(file_path)
159
 
160
- # Create new path in download directory
161
- new_path = os.path.join(download_subdir, filename)
162
- abs_new_path = os.path.abspath(new_path)
163
 
164
- logger.info(f"Moving file from {abs_file_path} to {abs_new_path}")
165
 
166
- # Copy file instead of moving
167
- shutil.copy2(abs_file_path, abs_new_path)
168
 
169
  # Get file extension
170
  file_type = os.path.splitext(filename)[1].lstrip('.')
@@ -185,10 +184,10 @@ async def download_file(request: DownloadRequest):
185
  logger.error(f"Error processing file {file_path}: {str(e)}")
186
  continue
187
 
188
- # Clean up original files after successful copy
189
  for root, dirs, files in os.walk('.'):
190
  for dir_name in dirs:
191
- if dir_name != download_subdir:
192
  dir_path = os.path.join(root, dir_name)
193
  logger.info(f"Removing directory: {dir_path}")
194
  shutil.rmtree(dir_path, ignore_errors=True)
@@ -220,6 +219,7 @@ async def download_file(request: DownloadRequest):
220
  finally:
221
  if 'original_dir' in locals():
222
  os.chdir(original_dir)
 
223
  @app.get("/")
224
  async def root():
225
  return {"message": "Welcome to GAMDL API. Visit /docs for API documentation."}
 
87
  url: str
88
 
89
 
90
+
91
  # [Previous cookie handling code remains the same...]
92
 
93
  class FileInfo(BaseModel):
 
154
 
155
  for file_path in all_files:
156
  try:
157
+ # Get just the filename from the path
 
158
  filename = os.path.basename(file_path)
159
 
160
+ # Create new path in current directory
161
+ new_path = os.path.join(".", filename)
 
162
 
163
+ logger.info(f"Moving file from {file_path} to {new_path}")
164
 
165
+ # Copy file to current directory
166
+ shutil.copy2(file_path, new_path)
167
 
168
  # Get file extension
169
  file_type = os.path.splitext(filename)[1].lstrip('.')
 
184
  logger.error(f"Error processing file {file_path}: {str(e)}")
185
  continue
186
 
187
+ # Clean up original files and directories after successful copy
188
  for root, dirs, files in os.walk('.'):
189
  for dir_name in dirs:
190
+ if dir_name == "Apple Music": # Only remove the music directory
191
  dir_path = os.path.join(root, dir_name)
192
  logger.info(f"Removing directory: {dir_path}")
193
  shutil.rmtree(dir_path, ignore_errors=True)
 
219
  finally:
220
  if 'original_dir' in locals():
221
  os.chdir(original_dir)
222
+
223
  @app.get("/")
224
  async def root():
225
  return {"message": "Welcome to GAMDL API. Visit /docs for API documentation."}