Files
player/check_srt.py
T
hibna 36f83ff72c Add SRT/FLV/RTMP support and update documentation
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.
2025-11-03 02:35:56 +03:00

110 lines
3.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import re
def check_srt_format(file_path):
"""SRT dosyasını kontrol eder ve hataları bulur."""
errors = []
warnings = []
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
i = 0
subtitle_count = 0
while i < len(lines):
# Boş satırları atla
while i < len(lines) and lines[i].strip() == '':
i += 1
if i >= len(lines):
break
subtitle_count += 1
expected_number = subtitle_count
# Satır 1: Altyazı numarası
line_num = i + 1
if not lines[i].strip().isdigit():
errors.append(f"Satır {line_num}: Altyazı numarası bekleniyor, bulunan: '{lines[i].strip()}'")
else:
actual_number = int(lines[i].strip())
if actual_number != expected_number:
warnings.append(f"Satır {line_num}: Altyazı numarası {expected_number} olmalı, {actual_number} bulundu")
i += 1
if i >= len(lines):
errors.append(f"Altyazı {subtitle_count}: Zaman damgası eksik")
break
# Satır 2: Zaman damgası
line_num = i + 1
timestamp_pattern = r'^\d{2}:\d{2}:\d{2},\d{3}\s*-->\s*\d{2}:\d{2}:\d{2},\d{3}$'
if not re.match(timestamp_pattern, lines[i].strip()):
# Hatalı formatları tespit et
timestamp_line = lines[i].strip()
# Yaygın hatalar
if '-->' in timestamp_line:
# Virgül yerine nokta kullanımı
if '.' in timestamp_line and ',' not in timestamp_line:
errors.append(f"Satır {line_num}: Milisaniye ayırıcı virgül (,) olmalı, nokta (.) değil: '{timestamp_line}'")
# Eksik sıfırlar
elif re.search(r'\d{1}:\d{2}:\d{2}', timestamp_line):
errors.append(f"Satır {line_num}: Saat/dakika/saniye 2 haneli olmalı: '{timestamp_line}'")
# Eksik/fazla milisaniye basamağı
elif re.search(r',\d{1,2}[^\d]|,\d{1,2}$', timestamp_line):
errors.append(f"Satır {line_num}: Milisaniye 3 haneli olmalı: '{timestamp_line}'")
elif re.search(r',\d{4,}', timestamp_line):
errors.append(f"Satır {line_num}: Milisaniye 3 haneli olmalı (fazla basamak): '{timestamp_line}'")
else:
errors.append(f"Satır {line_num}: Geçersiz zaman damgası formatı: '{timestamp_line}'")
else:
errors.append(f"Satır {line_num}: Zaman damgası bekleniyor (-->), bulunan: '{timestamp_line}'")
i += 1
# Satır 3+: Altyazı metni
text_lines = []
while i < len(lines) and lines[i].strip() != '':
text_lines.append(lines[i])
i += 1
if not text_lines:
warnings.append(f"Altyazı {subtitle_count} (satır {line_num}): Metin içeriği boş")
print(f"Toplam altyazı sayısı: {subtitle_count}")
print(f"\n{'='*60}")
if errors:
print(f"\nHATALAR ({len(errors)} adet):")
print("="*60)
for error in errors[:50]: # İlk 50 hatayı göster
print(f" - {error}")
if len(errors) > 50:
print(f"\n ... ve {len(errors) - 50} hata daha")
else:
print("\nKritik hata bulunamadi!")
if warnings:
print(f"\nUYARILAR ({len(warnings)} adet):")
print("="*60)
for warning in warnings[:20]: # İlk 20 uyarıyı göster
print(f" - {warning}")
if len(warnings) > 20:
print(f"\n ... ve {len(warnings) - 20} uyari daha")
return errors, warnings
if __name__ == "__main__":
import sys
file_path = sys.argv[1] if len(sys.argv) > 1 else "public/ses.srt"
errors, warnings = check_srt_format(file_path)
if not errors and not warnings:
print("\nSRT dosyasi tamamen dogru formatta!")
else:
print(f"\nOzet: {len(errors)} hata, {len(warnings)} uyari")