import csv import os import sys if len(sys.argv) != 2: print('Usage: python3 playlisttotxt.py ') sys.exit(1) else: csvname = sys.argv[1] with open(csvname, 'r') as file: reader = csv.reader(file) next(reader) playlist = [] for row in reader: artist_name = row[3] track_name = row[1] playlist.append(f'{artist_name} - {track_name}') 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]) with open('musiclist.txt', 'a') as file: for track in playlist: if track in formatted_lines: continue else: url = input(f'URL for {track}: ') urlid = url.split('v=')[1] if url.startswith('https://youtube.com/watch?v=') or url.startswith('https://www.youtube.com/watch?v='): file.write(f'{track} --- {urlid} --- YT\n') elif url.startswith('https://music.youtube.com/watch?v='): file.write(f'{track} --- {urlid} --- YTM\n') else: print('Invalid URL')