Nov-18-2020, 11:28 PM
Hello!
Like many, I am currently learning python and working on my first project. It is a script that changes all the files within a directory based on user input. Currently built for TV Show file changes.
so far its going well, I'm just stuck on one thing. I feel like the answer is on the tip of my tongue, like I've heard it in previous lessons I took, I just can't quite remember.
At a certain point in the script, to handle some episodes that may be "2 in 1s", it asks the user to specify if there are Episodes that are joined together (ex one .mp4 file titled "Episode 1, Episode 2"). if the user answers "y", it then asks how many instances this occurs (ex. 2). the user then specifys the # of times, and then the loop asks the same question depending on how many times the user specified (First Episode?, Second Episode?).
This is essentially the process:
(python) Are there multi episodes?
(user) Y
(python) How many?
(user) 2
(python) First Episode?
(user) 1
(python) Second Episode?
(user) 2
(python) First Episode?
(user) 5
(python) Second Episode?
(user) 6
The script should then rename "Episode 1, Episode 2" to E01E02 and "Episode 5, Episode 6" to E05E06. However, the end result is only E05E06 is changed, what i want to be changed to "E01E02" stays at its original title, "Episode 1, Episode 2".
I believe it does change, but the next loop overwrites it, thus only the latest user response changes.
Is there a way to get the loop to keep user changes each time it runs through?
I'm thinking it is a problem with my eptokea and eptokeb strings, just not sure how to go about fixing it
Any help is greatly appreciated!
SAMPLE CODE
Like many, I am currently learning python and working on my first project. It is a script that changes all the files within a directory based on user input. Currently built for TV Show file changes.
so far its going well, I'm just stuck on one thing. I feel like the answer is on the tip of my tongue, like I've heard it in previous lessons I took, I just can't quite remember.
At a certain point in the script, to handle some episodes that may be "2 in 1s", it asks the user to specify if there are Episodes that are joined together (ex one .mp4 file titled "Episode 1, Episode 2"). if the user answers "y", it then asks how many instances this occurs (ex. 2). the user then specifys the # of times, and then the loop asks the same question depending on how many times the user specified (First Episode?, Second Episode?).
This is essentially the process:
(python) Are there multi episodes?
(user) Y
(python) How many?
(user) 2
(python) First Episode?
(user) 1
(python) Second Episode?
(user) 2
(python) First Episode?
(user) 5
(python) Second Episode?
(user) 6
The script should then rename "Episode 1, Episode 2" to E01E02 and "Episode 5, Episode 6" to E05E06. However, the end result is only E05E06 is changed, what i want to be changed to "E01E02" stays at its original title, "Episode 1, Episode 2".
I believe it does change, but the next loop overwrites it, thus only the latest user response changes.
Is there a way to get the loop to keep user changes each time it runs through?
I'm thinking it is a problem with my eptokea and eptokeb strings, just not sure how to go about fixing it
Any help is greatly appreciated!
SAMPLE CODE
epstochange = int(input("How many multi eps? ")) for i in range(epstochange): i += 1 print("Which episodes are joined?") eptokea = input("First Episode: ") eptokeb = input("Second Episode: ") # Starts renaming loop if user specifies tv shows are multi episode path = os.getcwd() os.chdir(filenamedir) filenames = os.listdir(filenamedir) COUNT = 1 def increment(): global COUNT COUNT = COUNT + 1 for f in filenames: f_name, f_ext = os.path.splitext(f) if str(COUNT) == eptokea.format(i): def incrementx(): global COUNT COUNT = COUNT + 2 f_name = showname + " - " + "S" + season.zfill(2) + "E" + eptokea.format(i).zfill(2) + "E" + eptokeb.format(i).zfill(2) incrementx() new_name = '{} {}'.format(f_name, f_ext) os.rename(f, new_name) else: f_name = showname + " - " + "S" + season.zfill(2) + "E" + str(COUNT).zfill(2) increment() new_name = '{} {}'.format(f_name, f_ext) os.rename(f, new_name)