Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- def menu():
- print("\nEnter a choice from the menu:\n1.list albums\n2.list songs in album\n3.find length of song\n4.get lyrics of song\n5.find album which song is in\n6.search for songs by title\n7.search for songs by lyrics\n8.exit\n")
- def main():
- SERVER_IP = "127.0.0.1"
- count = 0
- SERVER_PORT = 25565
- server_address = (SERVER_IP, SERVER_PORT)
- while(True):
- try:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect(server_address)
- except Exception as exep:
- print("Error: %s" % exep)
- break
- if count == 0:
- sock.sendall("HELLO#".encode())
- server_msg = sock.recv(1024).decode()
- print(server_msg)
- count += 1
- continue
- if count == 1:
- sock.sendall("LOGIN#".encode())
- server_msg = sock.recv(1024).decode()
- print(server_msg)
- pwd = input()
- try:
- sock.sendall(pwd.encode())
- server_msg = sock.recv(1024).decode()
- except Exception as e:
- print("Error: %s" % e)
- break
- if server_msg == 'Wrong password!':
- print(server_msg)
- break
- print(server_msg)
- count+=1
- continue
- menu()
- user_choice = input("Enter a choice: ")
- if user_choice == '1':
- try:
- sock.sendall("GETALBUMS#".encode())
- except Exception as e:
- print("Error: %s" % e)
- break
- elif user_choice == '2':
- song = input("Enter an album: ")
- try:
- sock.sendall(("GETSONGS#" + song).encode())
- except Exception as e:
- print("Error: %s" % e)
- break
- elif user_choice == '3':
- song = input("Enter a song: ")
- try:
- sock.sendall(("GETLENGTH#" + song).encode())
- except Exception as e:
- print("Error: %s" % e)
- break
- elif user_choice == '4':
- song = input("Enter a song: ")
- try:
- sock.sendall(("GETLYRICS#" + song).encode())
- except Exception as e:
- print("Error: %s" % e)
- break
- elif user_choice == '5':
- song = input("Enter a song: ")
- try:
- sock.sendall(("SONGALBUM#" + song).encode())
- except Exception as e:
- print("Error: %s" % e)
- break
- elif user_choice == '6':
- search_term = input("Enter a search term: ")
- try:
- sock.sendall(("SEARCHSONG#" + search_term).encode())
- except Exception as e:
- print("Error: %s" % e)
- break
- elif user_choice == '7':
- search_term = input("Enter a search term: ")
- try:
- sock.sendall(("SEARCHLYRIC#" + search_term).encode())
- except Exception as e:
- print("Error: %s" % e)
- break
- elif user_choice == '8':
- try:
- sock.sendall("EXIT#".encode())
- except Exception as e:
- print("Error: %s" % e)
- break
- server_msg = sock.recv(1024).decode()
- print(server_msg)
- break
- else:
- print("Wrong input! try again.\n")
- continue
- server_msg = sock.recv(1024).decode()
- print(server_msg)
- input("\nPress Enter to continue...")
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement