Merge 016086870910427bc3daab27b595ce7ddd4aded0 into 335d97ec2d3ca4216e8b7c4fb9ffe536a0ec0914

This commit is contained in:
m4xr1sk 2025-02-08 22:13:22 +01:00 committed by GitHub
commit 039e58a628
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -279,16 +279,33 @@ class DownloadManager:
return self.stopped
def download_subtitle(self, sub: Dict):
"""Downloads and saves subtitle file for a specific language."""
"""Downloads and saves the actual subtitle file or keeps the original format if no external file is needed."""
if self.stopped:
return True
# Scarica il contenuto della playlist M3U8 o del file VTT
content = self.client.request(sub['uri'])
if content:
sub_path = os.path.join(self.temp_dir, 'subs', f"{sub['language']}.vtt")
if not content:
return self.stopped
vtt_url = None
for line in content.splitlines():
if line.startswith("http"): # Trova la prima URL nel file .m3u8
vtt_url = line.strip()
break
sub_path = os.path.join(self.temp_dir, 'subs', f"{sub['language']}.vtt")
if vtt_url:
# Scarica il vero file VTT se esiste un URL nel file .m3u8
vtt_content = self.client.request(vtt_url)
if vtt_content:
with open(sub_path, 'w', encoding='utf-8') as f:
f.write(vtt_content)
print(f"Sottotitoli scaricati: {sub_path}")
else:
print(f"Errore nel download dei sottotitoli da {vtt_url}")
else:
# Se non c'è un URL, salva il contenuto direttamente
with open(sub_path, 'w', encoding='utf-8') as f:
f.write(content)
print(f"Sottotitoli salvati direttamente: {sub_path}")
return self.stopped
def download_all(self, video_url: str, audio_streams: List[Dict], sub_streams: List[Dict]):