import os formatted_lines = [] if os.path.exists('musiclist.txt'): with open('musiclist.txt', 'r') as file: lines = file.readlines() for line in lines: formatted_lines.append(line.split(' --- ')[0]) while True: first_part = input('Enter the artist and song title: ') if first_part == '': print('You must enter an artist and song title') continue if first_part in formatted_lines: print('This song is already in the list') continue provider = input('Enter the provider: ') if provider == '': print('You must enter a provider') continue url = input('Enter the source URL: ') if url == '': print('You must enter a source URL') continue if (provider == 'YT') and (url.split('?v=')[0] == 'https://www.youtube.com/watch'): urlid = url.split('?v=')[1] with open('musiclist.txt', 'a') as file: file.write(f'{first_part} --- {urlid} --- {provider}\n') elif (provider == 'YTM') and (url.split('?v=')[0] == 'https://music.youtube.com/watch'): urlid = url.split('?v=')[1] with open('musiclist.txt', 'a') as file: file.write(f'{first_part} --- {urlid} --- {provider}\n') else: print('Invalid source URL') continue