tecuts commited on
Commit
88f3ca5
·
verified ·
1 Parent(s): ca08db2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py CHANGED
@@ -328,6 +328,44 @@ async def download_track(track_id: int, quality: str = "LOSSLESS"):
328
  track_number = track_info.get('trackNumber', 1)
329
  isrc = track_info.get('isrc', '')
330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
331
  is_lossless = 'dash+xml' in manifest_mime
332
 
333
  if is_lossless:
 
328
  track_number = track_info.get('trackNumber', 1)
329
  isrc = track_info.get('isrc', '')
330
 
331
+ # For HIGH/LOW quality, return direct CDN URLs (no server-side download)
332
+ if quality in ['HIGH', 'LOW']:
333
+ print("📦 Parsing manifest for direct URL...")
334
+ base_url, segments, audio_format = parse_dash_manifest(manifest_data)
335
+
336
+ if segments:
337
+ # Get the first segment URL (initialization segment)
338
+ first_segment = segments[0]
339
+ if first_segment.startswith('http://') or first_segment.startswith('https://'):
340
+ direct_url = first_segment
341
+ elif base_url:
342
+ direct_url = base_url + first_segment
343
+ else:
344
+ direct_url = first_segment
345
+
346
+ print(f"✅ Direct URL found for {quality}: {direct_url[:100]}...")
347
+
348
+ return {
349
+ "success": True,
350
+ "track": {
351
+ "id": track_id,
352
+ "title": title,
353
+ "artist": artist,
354
+ "album": album,
355
+ "albumArtist": album_artist,
356
+ "trackNumber": track_number,
357
+ "duration": duration,
358
+ "isrc": isrc,
359
+ "quality": audio_quality,
360
+ "format": audio_format
361
+ },
362
+ "downloadUrl": direct_url,
363
+ "message": f"Direct TIDAL CDN URL for {quality} quality (time-limited)"
364
+ }
365
+ else:
366
+ raise HTTPException(status_code=500, detail="No segments found in manifest")
367
+
368
+ # For LOSSLESS/HI_RES_LOSSLESS, download and merge segments
369
  is_lossless = 'dash+xml' in manifest_mime
370
 
371
  if is_lossless: