-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyoutube_manager.py
More file actions
80 lines (68 loc) · 2.14 KB
/
youtube_manager.py
File metadata and controls
80 lines (68 loc) · 2.14 KB
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
import json
def load_data():
try:
with open('youtube.txt', 'r') as file:
test = json.load(file)
# print(type(test))
return test
except FileNotFoundError:
return []
def save_data_helper(videos):
with open('youtube.txt', 'w') as file:
json.dump(videos, file)
def list_all_videos(videos):
print("\n")
print("*" * 70)
for index, video in enumerate(videos, start=1):
print(f"{index}. {video['name']}, Duration: {video['time']} ")
print("\n")
print("*" * 70)
def add_video(videos):
name = input("Enter video name: ")
time = input("Enter video time: ")
videos.append({'name': name, 'time': time})
save_data_helper(videos)
def update_video(videos):
list_all_videos(videos)
index = int(input("Enter the video number to update"))
if 1 <= index <= len(videos):
name = input("Enter the new video name")
time = input("Enter the new video time")
videos[index-1] = {'name':name, 'time': time}
save_data_helper(videos)
else:
print("Invalid index selected")
def delete_video(videos):
list_all_videos(videos)
index = int(input("Enter the video number to be deleted"))
if 1<= index <= len(videos):
del videos[index-1]
save_data_helper(videos)
else:
print("Invalid video index selected")
def main():
videos = load_data()
while True:
print("\n Youtube Manager | choose an option ")
print("1. List all youtube videos ")
print("2. Add a youtube video ")
print("3. Update a youtube video details ")
print("4. Delete a youtube video ")
print("5. Exit the app ")
choice = input("Enter your choice: ")
# print(videos)
match choice:
case '1':
list_all_videos(videos)
case '2':
add_video(videos)
case '3':
update_video(videos)
case '4':
delete_video(videos)
case '5':
break
case _:
print("Invalid Choice")
if __name__ == "__main__":
main()