def add_cover_art(path='.', no_gui=False, max_num=1): song_filenames = [] if os.path.isdir(path): logging.log(logging.VERBOSE, "Finding all .mp3 files in: %s", path) for root, dirs, files in os.walk(path): for file in files: if file.endswith('.mp3'): song_filenames.append(os.path.join(root, file)) elif os.path.isfile(path) and args.file.endswith('.mp3'): logging.log(logging.VERBOSE, "Finding: %s", path) song_filenames.append(os.path.abspath(path)) for song_filename in song_filenames: logging.log(logging.VERBOSE, "Processing file: %s", song_filename) song_query = extract_query(song_filename) try: art_directory = scrape_google_image(song_query + " song cover art", name=song_query, max_num=1) art_filename = os.path.join(art_directory, os.listdir(art_directory)[0]) if not no_gui: window = tkinter_window(art_filename, song_filename) if window.is_cancelled: exit() else: add_image(art_filename, song_filename) except (HTTPError, URLError, ValueError) as e: logging.warning('Unable to download images: %s', e)
def on_search(self): self.search_button.configure(state='disabled', text='Searching..') self.window.update() song_query = self.song_query.get() art_directory = scrape_google_image(song_query + " song cover art", name=song_query, max_num=1) self.art_filename = os.path.join(art_directory, os.listdir(art_directory)[0]) self.update_image() self.search_button.configure(state='normal', text='Search')
music_names[i][0] = music_names[i][0][1:] else: break # Remove extension from song names for i in range(len(music_names)): music_names[i][0] = "".join(music_names[i][0].split('.')[:-1]) # replace '-','_','320','Kbps','kbps' sign with ' ' for i in range(len(music_names)): music_names[i][0] = music_names[i][0].replace("-", " ") music_names[i][0] = music_names[i][0].replace("_", " ") music_names[i][0] = music_names[i][0].replace("320", " ") music_names[i][0] = music_names[i][0].replace("Kbps", " ") music_names[i][0] = music_names[i][0].replace("kbps", " ") # remove anything in between (),[],{} for i in range(len(music_names)): music_names[i][0] = re.sub(r"[\(\[].*?[\)\]]", "", music_names[i][0]) for i in range(len(music_names)): audiofile = eyed3.load(music_names[i][1]) song_directory = scrape_google_image(music_names[i][0] + " song cover art", name=music_names[i][0], max_num=1) song_filename = os.path.join(song_directory, os.listdir(song_directory)[0]) Image.open(song_filename) tkinter_window(song_filename, audiofile)
num.append("-") for i in range(len(music_names)): for a in music_names[i][0]: if a in num: music_names[i][0] = music_names[i][0][1:] else: break # Remove extension from song names for i in range(len(music_names)): music_names[i][0] = "".join(music_names[i][0].split('.')[:-1]) # replace '-','_','320','Kbps','kbps' sign with ' ' for i in range(len(music_names)): music_names[i][0] = music_names[i][0].replace("-", " ") music_names[i][0] = music_names[i][0].replace("_", " ") music_names[i][0] = music_names[i][0].replace("320", " ") music_names[i][0] = music_names[i][0].replace("Kbps", " ") music_names[i][0] = music_names[i][0].replace("kbps", " ") # remove anything in between (),[],{} for i in range(len(music_names)): music_names[i][0] = re.sub(r"[\(\[].*?[\)\]]", "", music_names[i][0]) for i in range(len(music_names)): audiofile = eyed3.load(music_names[i][1]) song_file_name = scrape_image_from_google_images.scrape_google_image( music_names[i][0] + " song cover art", name=music_names[i][0]) Image.open(song_file_name) tkinter_window(song_file_name, audiofile)
music_names[i][0] = music_names[i][0].replace("_", " ") music_names[i][0] = re.sub("\d\d\d\s*kbps", " ", music_names[i][0], flags=re.I) # remove anything in between (),[],{} and replace multiple spaces for i in range(len(music_names)): music_names[i][0] = re.sub(r"[\(\[].*?[\)\]]", "", music_names[i][0]) music_names[i][0] = re.sub(" +", " ", music_names[i][0]) for i in range(len(music_names)): audiofile = eyed3.load(music_names[i][1]) try: song_directory = scrape_google_image(music_names[i][0] + " song cover art", name=music_names[i][0], max_num=1) except (HTTPError, URLError): print('Unable to Download the images') continue song_filename = os.path.join(song_directory, os.listdir(song_directory)[0]) Image.open(song_filename) if args.no_gui: add_image(song_filename, audiofile) else: while True: inputs = tkinter_window(song_filename, audiofile) if inputs: try: song_directory = scrape_google_image(