36f83ff72c
Introduced Python scripts for SRT subtitle checking and fixing, and added comprehensive documentation covering advanced features such as protocol detection, subtitle/audio/quality management, keyboard shortcuts, and touch gestures. Updated local settings to allow new build and Python commands, added TypeScript definitions for FLV, and implemented RTMP/FLV protocol support in the player. Removed CHANGELOG.md and made various improvements to styles and example app.
188 lines
5.8 KiB
Python
188 lines
5.8 KiB
Python
import re
|
||
|
||
def fix_srt_file(input_path, output_path):
|
||
"""SRT dosyasındaki format hatalarını düzeltir."""
|
||
|
||
with open(input_path, 'r', encoding='utf-8') as f:
|
||
content = f.read()
|
||
|
||
lines = content.split('\n')
|
||
fixed_lines = []
|
||
i = 0
|
||
subtitle_number = 1
|
||
errors_fixed = []
|
||
|
||
while i < len(lines):
|
||
# Boş satırları atla
|
||
while i < len(lines) and lines[i].strip() == '':
|
||
i += 1
|
||
|
||
if i >= len(lines):
|
||
break
|
||
|
||
# Altyazı numarasını ekle/düzelt
|
||
fixed_lines.append(str(subtitle_number))
|
||
|
||
# Eğer mevcut satır numara değilse, bu satırı kaybetme
|
||
if not lines[i].strip().isdigit():
|
||
# Bu satır muhtemelen yanlış yerleştirilmiş metin, geri al
|
||
pass
|
||
else:
|
||
i += 1
|
||
|
||
if i >= len(lines):
|
||
errors_fixed.append(f"Altyazı {subtitle_number}: Zaman damgası eksik (dosya sonu)")
|
||
break
|
||
|
||
# Zaman damgasını bul ve düzelt
|
||
timestamp_line = lines[i].strip()
|
||
|
||
if '-->' in timestamp_line:
|
||
# Zaman damgasını düzelt
|
||
fixed_timestamp = fix_timestamp(timestamp_line, subtitle_number)
|
||
if fixed_timestamp != timestamp_line:
|
||
errors_fixed.append(f"Altyazı {subtitle_number}: Zaman damgası düzeltildi")
|
||
errors_fixed.append(f" Eski: {timestamp_line}")
|
||
errors_fixed.append(f" Yeni: {fixed_timestamp}")
|
||
fixed_lines.append(fixed_timestamp)
|
||
i += 1
|
||
else:
|
||
# Zaman damgası bulunamadı, bu bir format hatası
|
||
# Bu durumda bu satırı metin olarak kabul et
|
||
errors_fixed.append(f"Altyazı {subtitle_number}: Zaman damgası bulunamadı, atlanıyor")
|
||
# Sonraki geçerli zaman damgasını bul
|
||
found_timestamp = False
|
||
while i < len(lines) and not found_timestamp:
|
||
if '-->' in lines[i]:
|
||
fixed_timestamp = fix_timestamp(lines[i].strip(), subtitle_number)
|
||
fixed_lines.append(fixed_timestamp)
|
||
i += 1
|
||
found_timestamp = True
|
||
else:
|
||
i += 1
|
||
|
||
if not found_timestamp:
|
||
errors_fixed.append(f"Altyazı {subtitle_number}: Hiç zaman damgası bulunamadı, atlanıyor")
|
||
break
|
||
|
||
# Metin satırlarını topla
|
||
text_lines = []
|
||
while i < len(lines) and lines[i].strip() != '' and '-->' not in lines[i]:
|
||
# Bir sonraki satır numara mı kontrol et
|
||
if i + 1 < len(lines) and lines[i + 1].strip() != '' and '-->' in lines[i + 1]:
|
||
# Bu muhtemelen metin
|
||
text_lines.append(lines[i])
|
||
i += 1
|
||
elif lines[i].strip().isdigit() and i + 1 < len(lines) and '-->' in lines[i + 1]:
|
||
# Bu bir sonraki altyazının numarası, dur
|
||
break
|
||
else:
|
||
text_lines.append(lines[i])
|
||
i += 1
|
||
|
||
# Metni ekle
|
||
for text_line in text_lines:
|
||
fixed_lines.append(text_line.rstrip())
|
||
|
||
# Boş satır ekle
|
||
fixed_lines.append('')
|
||
|
||
subtitle_number += 1
|
||
|
||
# Dosyayı kaydet
|
||
with open(output_path, 'w', encoding='utf-8') as f:
|
||
f.write('\n'.join(fixed_lines))
|
||
|
||
return errors_fixed, subtitle_number - 1
|
||
|
||
|
||
def fix_timestamp(timestamp, subtitle_num):
|
||
"""Zaman damgası formatını düzeltir."""
|
||
|
||
# Boşlukları temizle
|
||
parts = timestamp.split('-->')
|
||
if len(parts) != 2:
|
||
return timestamp
|
||
|
||
start = parts[0].strip()
|
||
end = parts[1].strip()
|
||
|
||
# Her iki tarafı da düzelt
|
||
start_fixed = fix_time_part(start)
|
||
end_fixed = fix_time_part(end)
|
||
|
||
return f"{start_fixed} --> {end_fixed}"
|
||
|
||
|
||
def fix_time_part(time_str):
|
||
"""Tek bir zaman bölümünü düzeltir (HH:MM:SS,mmm)."""
|
||
|
||
# Virgül ve noktayı ayır
|
||
if ',' in time_str:
|
||
main_part, ms_part = time_str.rsplit(',', 1)
|
||
elif '.' in time_str:
|
||
main_part, ms_part = time_str.rsplit('.', 1)
|
||
# Noktayı virgüle çevir
|
||
else:
|
||
# Milisaniye yok, sonuna ekle
|
||
main_part = time_str
|
||
ms_part = '000'
|
||
|
||
# HH:MM:SS kısmını düzelt
|
||
time_parts = main_part.split(':')
|
||
|
||
# Eksik bölümleri tamamla
|
||
while len(time_parts) < 3:
|
||
time_parts.insert(0, '00')
|
||
|
||
# Her bölümü 2 haneli yap
|
||
fixed_parts = []
|
||
for part in time_parts:
|
||
# Sadece sayıları al
|
||
digits = ''.join(filter(str.isdigit, part))
|
||
if not digits:
|
||
digits = '0'
|
||
# 2 haneli yap
|
||
fixed_parts.append(digits.zfill(2))
|
||
|
||
# Milisaniyeyi 3 haneli yap
|
||
ms_digits = ''.join(filter(str.isdigit, ms_part))
|
||
if not ms_digits:
|
||
ms_digits = '000'
|
||
elif len(ms_digits) > 3:
|
||
ms_digits = ms_digits[:3]
|
||
else:
|
||
ms_digits = ms_digits.ljust(3, '0')
|
||
|
||
return f"{':'.join(fixed_parts)},{ms_digits}"
|
||
|
||
|
||
if __name__ == "__main__":
|
||
print("SRT dosyası düzeltiliyor...")
|
||
print("="*60)
|
||
|
||
errors_fixed, total_subtitles = fix_srt_file("public/ses.srt", "public/ses_fixed.srt")
|
||
|
||
print(f"\nToplam {total_subtitles} altyazı işlendi")
|
||
|
||
if errors_fixed:
|
||
print(f"\nDüzeltilen hatalar ({len([e for e in errors_fixed if not e.startswith(' ')])} adet):")
|
||
print("="*60)
|
||
for error in errors_fixed[:30]:
|
||
print(f" {error}")
|
||
if len(errors_fixed) > 30:
|
||
print(f"\n ... ve daha fazlası")
|
||
|
||
print(f"\nDüzeltilmiş dosya kaydedildi: public/ses_fixed.srt")
|
||
print("\nŞimdi kontrol ediliyor...")
|
||
print("="*60)
|
||
|
||
# Kontrol et
|
||
import check_srt
|
||
errors, warnings = check_srt.check_srt_format("public/ses_fixed.srt")
|
||
|
||
if not errors:
|
||
print("\n✓ Tüm hatalar düzeltildi!")
|
||
else:
|
||
print(f"\nHala {len(errors)} hata var. Manuel düzeltme gerekebilir.")
|