ChandimaPrabath commited on
Commit
9c0c806
1 Parent(s): 49ea85c
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -98,31 +98,31 @@ async def get_media_store_api():
98
 
99
  @app.get("/api/get/music/{filename}")
100
  async def get_media_api(request: Request, filename: str):
101
- """Endpoint to get the music file (audio or video) by title with support for range requests."""
102
- title = unquote(filename)
103
- if not title:
104
- raise HTTPException(status_code=400, detail="Title parameter is required")
105
 
106
- if title in instance.MUSIC_STORE:
107
- cache_path = instance.MUSIC_STORE[title]
108
  if os.path.exists(cache_path):
109
  return await serve_media(cache_path, request)
110
 
111
- media_path = instance.find_music_path(title)
112
 
113
  if not media_path:
114
  raise HTTPException(status_code=404, detail="Media not found")
115
 
116
  cache_path = os.path.join(CACHE_DIR, media_path)
117
  file_url = f"https://huggingface.co/{REPO}/resolve/main/{media_path}"
118
- media_id = instance.get_music_id(title)
119
 
120
- if media_id not in instance.download_threads or not instance.download_threads[media_id].is_alive():
121
- thread = Thread(target=instance.download_music, args=(file_url, TOKEN, cache_path, media_id, title))
122
- instance.download_threads[media_id] = thread
123
  thread.start()
124
 
125
- return JSONResponse({"status": "Download started", "music_id": media_id})
126
 
127
  @app.get("/api/get/progress/{id}")
128
  async def get_progress_api(id: str):
 
98
 
99
  @app.get("/api/get/music/{filename}")
100
  async def get_media_api(request: Request, filename: str):
101
+ """Endpoint to get the music file (audio or video) by filename with support for range requests."""
102
+ filename = unquote(filename)
103
+ if not filename:
104
+ raise HTTPException(status_code=400, detail="filename parameter is required")
105
 
106
+ if filename in instance.MUSIC_STORE:
107
+ cache_path = instance.MUSIC_STORE[filename]
108
  if os.path.exists(cache_path):
109
  return await serve_media(cache_path, request)
110
 
111
+ media_path = instance.find_music_path(filename)
112
 
113
  if not media_path:
114
  raise HTTPException(status_code=404, detail="Media not found")
115
 
116
  cache_path = os.path.join(CACHE_DIR, media_path)
117
  file_url = f"https://huggingface.co/{REPO}/resolve/main/{media_path}"
118
+ music_id = instance.get_music_id(filename)
119
 
120
+ if music_id not in instance.download_threads or not instance.download_threads[music_id].is_alive():
121
+ thread = Thread(target=instance.download_music, args=(file_url, TOKEN, cache_path, music_id, filename))
122
+ instance.download_threads[music_id] = thread
123
  thread.start()
124
 
125
+ return JSONResponse({"status": "Download started", "music_id": music_id})
126
 
127
  @app.get("/api/get/progress/{id}")
128
  async def get_progress_api(id: str):