This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
navigation.py
490 lines (365 loc) · 15.5 KB
/
navigation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
from imdb import IMDbDataAccessError
from pathlib import Path
import os
import time
import shutil
import logging
import renamer as rn
# This will prevent printing errors from other modules
logger = logging.getLogger("imdbpy")
logger.disabled = True
# Getting the terminal size for always printing the results in the middle
col = shutil.get_terminal_size().columns
# All the global Flags
option_4_selected = False
warning_message_shown = False
file_episode_count_not_eq = False
mission_successful = False
# Clear the console
def clearConsole():
command = "clear"
# If Machine is running on Windows, use cls
if os.name in ("nt", "dos"):
command = "cls"
os.system(command)
# Assign new the index number from the nenamer.py file
def setIndex():
try:
serial = int(input('Enter the "Serial No." of the show you need: '))
except ValueError:
error = True
while error:
print("\nInvalid Input!...\n")
serial = input('Enter the "Serial No." of the show you need: ')
if serial.isdigit():
error = False
serial = int(serial)
rn.index = serial - 1
# Print statements for the Main Menu. Returns a response from the user
def mainMenu():
global mission_successful
clearConsole()
rn.index = 0
mission_successful = False
print("|| ~~ MAIN MENU ~~ ||".center(col))
print("|| ----------------- ||".center(col))
print("|| Press [1] - Rename Anime / TV - Series episodes ||".center(col))
print("|| Press [2] - Rename General Files ||".center(col))
print("|| Press [3] - Exit ||".center(col))
response = input("\nPlease press a valid option: ")
return response
# Pring statements for the General Menu. This function use the global flag to determine which Menu to show. Returns a response from the user.
def menu():
# Global Flags
global option_4_selected, warning_message_shown, file_episode_count_not_eq, mission_successful
if option_4_selected:
print("|| ~ MENU ~ ||".center(col))
print("|| ---------- ||".center(col))
print("|| Press [1] - If you've found the show you want ||".center(col))
print("|| Press [2] - NEXT show info ||".center(col))
print("|| Press [3] - Previous show info ||".center(col))
print("|| Press [4] - Next 5 show-info at once. ||".center(col))
print("|| Press [5] - Search Again ||".center(col))
print("|| Press [6] - Main Menu ||".center(col))
print("|| Press [7] - Exit ||".center(col))
option_4_selected = False
# Used in response("1") and in rn.init()
elif warning_message_shown:
print("|| ~ MENU ~ ||".center(col))
print("|| ---------- ||".center(col))
print("|| Press [1] - Search Again ||".center(col))
print("|| Press [2] - Main Menu ||".center(col))
print("|| Press [3] - Exit ||".center(col))
warning_message_shown = False
elif file_episode_count_not_eq:
print("|| ~ MENU ~ ||".center(col))
print("|| ---------- ||".center(col))
print("|| Press [1] - Retry ||".center(col))
print("|| Press [2] - Main Menu ||".center(col))
print("|| Press [3] - Exit ||".center(col))
file_episode_count_not_eq = False
elif mission_successful:
print("|| ~ MENU ~ ||".center(col))
print("|| ---------- ||".center(col))
print("|| Press [1] - Choose Another Season ||".center(col))
print("|| Press [2] - Search For Another Series/ Anime ||".center(col))
print("|| Press [3] - Main Menu ||".center(col))
print("|| Press [4] - Exit ||".center(col))
else:
print("|| ~ MENU ~ ||".center(col))
print("|| ---------- ||".center(col))
print("|| Press [1] - Confirm ||".center(col))
print("|| Press [2] - NEXT show-info ||".center(col))
print("|| Press [3] - Previous show-info ||".center(col))
print("|| Press [4] - Next 5 show-info at once ||".center(col))
print("|| Press [5] - Search Again ||".center(col))
print("|| Press [6] - Main Menu ||".center(col))
print("|| Press [7] - Exit ||".center(col))
response = input("\nPlease press a valid option: ")
return response
# Special Menu for showing after user have selected the season
def episodeMenu():
print("|| ~ MENU ~ ||".center(col))
print("|| ---------- ||".center(col))
print("|| Press [1] - Confirm ||".center(col))
print("|| Press [2] - Choose Another Season ||".center(col))
print("|| Press [3] - Main Menu ||".center(col))
response = input("\nPlease press a valid option: ")
return response
def chooseAnotherSeasonErrorHandle():
try:
season = int(input("\nPlease choose a season: "))
except ValueError:
print(
"\nInvalid Season! Please choose from the available season(s) shown above..."
)
season_str = input("\nPlease choose a season: ")
error = True
while error:
if season_str.isdigit():
season = int(season_str)
error = False
break
print(
"\nInvalid Season! Please choose from the available season(s) shown above..."
)
season_str = input("\nPlease choose a season: ")
if season not in season_list:
while season not in season_list:
print(
"\nI-Invalid Season! Please choose from the available season(s) shown above..."
)
season = chooseAnotherSeasonErrorHandle()
else:
return season
def chooseAnotherSeason(season):
global mission_successful
season = chooseAnotherSeasonErrorHandle()
seasonToEpisodes(season)
episodeMenuResponse(episodeMenu())
mission_successful = False
# Get additional information on the season and episode list of a show / title using the "episodes" infoset from the IMDbPy server.
def showAvailableSeasons():
global season_list
print("\nRetrieving season data please wait...")
# Getting the episodes using "episodes" infoset form imdb server
try:
rn.ia.update(rn.title, "episodes")
except IMDbDataAccessError:
print("\nError!: Please try again...")
exit()
season_list = list(sorted(rn.title["episodes"].keys()))
seasons = ""
for i in season_list:
# If i is not any "Unknown" season
if i > 0:
seasons += "Season " + str(i) + " - "
seasons = seasons[:-3]
print(f"\nSeason(s) available : {seasons}")
# After getting the season(s) print the episodes on the console
def seasonToEpisodes(season):
global episode_names
season_x = rn.title["episodes"][season]
print(f"\nTotal Episode(s) count for Season {season}: {len(season_x)}\n")
print(f"Showing all the season {season} episodes: \n")
episode_names = []
for serial, name in season_x.items():
episode_names.append(name)
print(f"Episode {serial}: {name}")
# Take the response from the Main Menu and execute according to the user input
def mainMenuResponse(option):
# Option - Rename Anime / TV - Series episodes
if option == "1":
rn.init()
rn.showInfo(rn.getInfo())
response(menu())
# Option - Rename General Files
elif option == "2":
print(
"\nNOTE: Please make sure you've only the file(s) you want to rename in the folder..."
)
print(
"Please remove all unnecessary file type(s) (.srt , .bat, etc...) & check the hidden files or else they'll be also renamed with the other files..."
)
general_files = Path(input("\nFolder Path: "))
if not general_files.exists() or not general_files.is_dir():
error = True
print("\nWARNING! : File Path doesn't exist...")
while error:
files = Path(input("\nFolder Path: "))
if files.exists():
if files.is_dir():
error = False
else:
print("\nWARNING! : Not a directory...")
else:
print("\nWARNING! : File Path doesn't exist...")
print("\nNOTE: The files will be rename in this format:\n")
print('>>> "Title" - "Serial no." || Example - "Python Tutorial - 01.mkv"\n')
print(
"If you want to change the format, edith the source code of this script.\n"
)
file_title = input("Title of the file(s): ")
print("")
sl = int(input("Enter the Staring Serial no. : "))
for file in general_files.iterdir():
if file.is_file() and file.suffix != ".ini":
directory = file.parent
file_extension = file.suffix
new_file_name = f"{file_title} - {sl}{file_extension}"
sl += 1
print(new_file_name)
file.rename(Path(directory, new_file_name))
print("")
print("____________________________________________________".center(col))
print("|| ||".center(col))
print("|| ~~~ Successfully Renamed All The Files! ~~~ ||".center(col))
print("|| ||".center(col))
print("____________________________________________________".center(col))
print("")
time.sleep(4)
exit()
# Option - Exit
elif option == "3":
clearConsole()
exit()
else:
while option not in ("1", "2", "3"):
mainMenuResponse(mainMenu())
# Take the response from the General Menu and execute according to the user input
def response(option):
global option_4_selected, warning_message_shown, season
# Option - Confirm
if option == "1":
# If the title isn't a movie or title has a number of season(s)
if (
rn.title.get("kind") != "movie"
and rn.title.get("number of seasons", "N/A") != "N/A"
):
# get season information and show how many season is available
showAvailableSeasons()
season = chooseAnotherSeasonErrorHandle()
# Take the season no. input from the user and show all the episode names of that season
seasonToEpisodes(season)
episodeMenuResponse(episodeMenu())
else:
print(
'\nWARNING! : No season information available for the selected title ("N/A") or The selected title is a movie type\n'.center(
col
)
)
warning_message_shown = True
option = menu()
if option == "1":
response("5")
elif option == "2":
response("6")
elif option == "3":
response("7")
else:
while option not in ("1", "2", "3"):
print("\nWARNING! : Wrong Input!\n")
warning_message_shown = True
option = menu()
if option == "1":
response("5")
elif option == "2":
response("6")
elif option == "3":
response("7")
# Option - Next show info
elif option == "2":
# Increment the search index by 1
rn.index += 1
# Show the information of the current index
rn.showInfo(rn.getInfo())
# Take response for the
response(menu())
# Option - Previous show info
elif option == "3":
rn.index -= 1
rn.showInfo(rn.getInfo())
response(menu())
# Option - Show 5 show info at once
elif option == "4":
# Response option 4 flag is true
option_4_selected = True
start = rn.index
end = rn.index + 5
for counter in range(start, end):
rn.showInfo(rn.getInfo())
rn.index += 1
# Take user input from menu()
user_input = menu()
if user_input == "1":
# set the index according to the show user choose
setIndex()
# Get the informations for the index we just set
rn.showInfo(rn.getInfo())
response("1")
elif user_input in ("2", "3", "4", "5", "6", "7"):
# For other options call normal response
response(user_input)
else:
while user_input not in ("1", "2", "3", "4", "5", "6", "7"):
print("\nWARNING! : Wrong Input!\n")
option_4_selected = True
user_input = menu()
if user_input == "1":
setIndex()
rn.showInfo(rn.getInfo())
response("1")
elif user_input in ("2", "3", "4", "5", "6", "7"):
response(user_input)
# Option - Search Again
elif option == "5":
global mission_successful
clearConsole()
rn.index = 0
mission_successful = False
# This option does the same thing as mainMenuResponse() option - 1
rn.init()
rn.showInfo(rn.getInfo())
response(menu())
# Option - Back to the main menu
elif option == "6":
rn.index = 0
mainMenuResponse(mainMenu())
# Program exit because nothing to do
# Option - Exit the program
elif option == "7":
clearConsole()
exit()
else:
while option not in ("1", "2", "3", "4", "5", "6", "7"):
print("\nWARNING! : Wrong Input!\n")
response(menu())
# Take the response from the Episode Menu and execute according to the user input
def episodeMenuResponse(option):
# Option - Confirm
if option == "1":
global files
files = Path(input("\nFolder Path: "))
if not files.exists() or not files.is_dir():
error = True
print("\nWARNING! : File Path doesn't exist...")
while error:
files = Path(input("\nFolder Path: "))
if files.exists():
if files.is_dir():
error = False
else:
print("\nWARNING! : Not a directory...")
else:
print("\nWARNING! : File Path doesn't exist...")
rn.rename(rn.checkFiles(files))
# Option - Choose another season
elif option == "2":
chooseAnotherSeason(chooseAnotherSeasonErrorHandle())
# Option - Main Menu
elif option == "3":
mainMenuResponse(mainMenu())
else:
while option not in ("1", "2", "3"):
print("\nWARNING! : Wrong Input!\n")
episodeMenuResponse(episodeMenu())