pysrt | Python parser for SubRip files | Parser library
kandi X-RAY | pysrt Summary
kandi X-RAY | pysrt Summary
Python parser for SubRip (srt) files
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Read source code from source_file
- Generates a generator of SubRipItem from a source file
- Guess the eol
- Get the first line of the given iterable
- Create a Time instance from a string
- Splits the input file
- Sorts the list of indexes
- Save to file
- Parse command line arguments
- Create the backup file
- Parse arguments
- Build argument parser
- Create a file from a file
- Detect the encoding of a bigger file
- Open a Unicode file
- Read content from source_file
- Return the source file
- Read file from source string
- Break lines into output_file
- Rate the input file
pysrt Key Features
pysrt Examples and Code Snippets
Community Discussions
Trending Discussions on pysrt
QUESTION
from tkinter import filedialog, font
from tkinter import *
from tkinter import ttk
root = Tk()
root.geometry("300x100")
root.title("SRT")
root.resizable(False, False)
frame = Frame(root)
frame.grid(column=1, row =0)
def open():
b.destroy()
filename1 = filedialog.askopenfilename(filetypes=[("SRT files(*.srt)", "*.srt")],initialdir = "/", title = "Select file")
root.geometry("775x300")
k=Label(frame,text="SELECTED SUBTITLE",font=("Times New Roman", 15)).grid(column=3, row =0)
y=Label(frame,text=filename1,font=("Times New Roman", 12)).grid(column=3, row =1)
seconds=Label(root, font=("Times New Roman", 15),text="Seconds").grid(column=2,row=2)
minutes=Label(root, font=("Times New Roman", 15),text="Minutes").grid(column=0,row=2,ipadx=20)
minuteselect = StringVar()
minutes = ttk.Combobox(root, textvariable=minuteselect)
minutes['values']=tuple([i for i in range(1,61)])
minutes['state'] = 'readonly'
minutes.grid(column=0,row=4,padx=10)
secondselect = StringVar()
seconds = ttk.Combobox(root, textvariable=secondselect)
seconds['values']=tuple([i for i in range(1,61)])
seconds['state'] = 'readonly'
seconds.grid(column=2,row=4)
plus =Button(root,text="DECREASE", width='10', height='1').place(x=400,y=150)
minus =Button(root,text="INCREASE", width='10', height='1').place(x=280,y=150)
b =Button(frame,text="Select The Subtitle", width='30', height='1',command=open)
b.grid(row=1, column=1,padx=41,pady=30)
b.rowconfigure(1, weight=1)
b.columnconfigure(1, weight=1)
root.mainloop()
...ANSWER
Answered 2021-May-23 at 20:20First thing I would do is restructure the code you have. You are doing everything inside the open function you have, which complicates your life. Also, you remove the possibility for the user to change the .srt file used for the conversion.
I would use 1 form to contain all the controls.
- Button to select .srt file
- Combobox for the minutes
- Combobox for the seconds
- Save button
Then put the actual magic on the event that triggers when the Save button I suggested is pressed. Here you just get the values from the 2 comboboxes and use this to offset the subtitles based on these values.
Now, this doesn't actually properly answer your question, it's how I handled the exact same app long time ago. Sub timings can really s*ck donkeyballs :-|
To actually answer your question, if you want to use buttons and comboboxes, the required logic changes a bit. You will need to create global variables to hold the minutes and seconds, and take into account that if the seconds are set to 59 and the user presses the INCREASE button for seconds, the seconds should be reset to 0 and minutes should be increased by 1. Of course the inverse goes for the DECREASE. (1m0s --> 0m59s).
The logic for the buttons should go to separate functions, just as you did for the open button & function. Bind them just as you did for the open fucntion using the command
keyword when instantiating them. Put logic in there to update the global minute & second variables, and use combobox.set(value)
(docs) to update the combobox values.
You might also want to bind events to the comboboxes themselves being changed. See the pydocs and this excellent answer from nbro
Finally, you still need a Save button to actually update the values in the .srt file.
Some side-notes:
- The range you use for the minutes & seconds seems incorrect to me. I would use
range(0,60)
as you need the option for0
and you do not need the option for60
(as this would become 1 hour or 1 minute respectively. Considering you wanna fix timings for subtitles, using hours seems preposturous. Using milliseconds would seem usefull though. - You should be able to handle negative values. Subtitles are either early or late, and with the current logic, you can only handle the situation where the subtitles are early.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pysrt
You can use pysrt like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page