feat(subtitles): add support for loading and displaying subtitles in the application feat(video): implement video capture and frame navigation functionality feat(ui): create main window UI for subtitle and video management test: add unit tests for utility functions related to subtitle processing chore: set up project structure with necessary files and directories for functionality feat(ui_hardsubripper.py): add UI implementation for HardSubRipper application to provide a graphical interface for subtitle extraction and translation functionalities
74 lines
2.6 KiB
Python
74 lines
2.6 KiB
Python
|
|
debug = False
|
|
|
|
class TimeStamp:
|
|
def __init__(self, start, end):
|
|
self.start = start
|
|
self.end = end
|
|
|
|
def getStartInMilliseconds(self):
|
|
hours, minutes, seconds = self.start.split(':')
|
|
return int(hours)*3600000 + int(minutes)*60000 + int(seconds.split(',')[0])*1000 + int(seconds.split(',')[1])
|
|
|
|
def getEndInMilliseconds(self):
|
|
hours, minutes, seconds = self.end.split(':')
|
|
return int(hours)*3600000 + int(minutes)*60000 + int(seconds.split(',')[0])*1000 + int(seconds.split(',')[1])
|
|
|
|
def getStartInSeconds(self):
|
|
hours, minutes, seconds = self.start.split(':')
|
|
return int(hours)*3600 + int(minutes)*60 + int(seconds.split(',')[0])
|
|
|
|
def getEndInSeconds(self):
|
|
hours, minutes, seconds = self.end.split(':')
|
|
return int(hours)*3600 + int(minutes)*60 + int(seconds.split(',')[0])
|
|
|
|
def getDurationInSeconds(self):
|
|
return self.getEndInSeconds() - self.getStartInSeconds()
|
|
|
|
class Line:
|
|
def __init__(self, number, text, start, end):
|
|
self.number = number
|
|
self.text = text
|
|
self.time = TimeStamp(start, end)
|
|
|
|
def __repr__(self):
|
|
return f'{self.time.start} --> {self.time.end}\n{self.text}\n'
|
|
|
|
def __str__(self):
|
|
return f'{self.time.start} --> {self.time.end}\n{self.text}\n'
|
|
|
|
class Subtitles:
|
|
def __init__(self):
|
|
self.subtitles = {}
|
|
self.number_of_lines = 0
|
|
self.timestamps = {}
|
|
|
|
def load(self,lang, path):
|
|
self.subtitles[lang] = {}
|
|
with open(path, 'r',encoding='utf-8-sig') as file:
|
|
lines = file.readlines()
|
|
for i in range(len(lines)):
|
|
if lines[i].strip().isdigit():
|
|
start, end = lines[i+1].strip().split(' --> ')
|
|
text = lines[i+2].strip()
|
|
if debug :print(f'{lines[i].strip()} {start} {end} {text}')
|
|
self.subtitles[lang][int(lines[i].strip())] = Line(int(lines[i].strip()), text, start, end)
|
|
self.timestamps[int(lines[i].strip())] = TimeStamp(start, end)
|
|
self.number_of_lines = int(lines[i].strip()) if int(lines[i].strip()) > self.number_of_lines else self.number_of_lines
|
|
|
|
def getLine(self, lang, number)->Line:
|
|
return self.subtitles[lang][number]
|
|
|
|
def getLine(self, number)->str:
|
|
line = ""
|
|
for lang in self.subtitles:
|
|
if number in self.subtitles[lang]:
|
|
line += self.subtitles[lang][number].text + "\n"
|
|
return line
|
|
|
|
def getLines(self, lang):
|
|
return self.subtitles[lang]
|
|
|
|
def getLinesCount(self, lang):
|
|
return len(self.subtitles[lang])
|