def save_library(self): try: if self.current_library_filename: ml.save_library(self.library, self.current_library_filename) else: self.save_library_as() except Exception as e: print(traceback.print_exc()) messagebox.showerror('Create Library Error', e)
def save_library_as(self): try: library_filename = filedialog.asksaveasfilename(initialdir=os.getcwd(), title='Save music library', filetypes=(('json', '*.json'),), defaultextension='.json') if library_filename: ml.save_library(self.library, library_filename) self.current_library_filename = library_filename except Exception as e: print(traceback.print_exc()) messagebox.showerror('Create Library Error', e)
def write_song_list_to_file_json(self): if not self.library: return try: song_list_file_name = filedialog.asksaveasfilename(initialdir=os.getcwd(), title='Library Song List', filetypes=(('Text File', '*.txt'),), defaultextension='.txt') if song_list_file_name: ml.write_song_list_json(self.library, song_list_file_name) except Exception as e: print(traceback.print_exc()) messagebox.showerror('Write song list error.', e)
def refresh_weight_labels(self): relative_frequencies = ml.calculate_relative_frequency(self.library, SONGS_IN_PLAYLIST) for priority, weight_label in enumerate(list(zip(*self.weight_modifier_widgets))[1]): num_songs_in_priority = ml.get_number_of_songs_for_priority(self.library, priority) priority_playlist_frequency = float(num_songs_in_priority / relative_frequencies[priority]) \ if relative_frequencies[priority] != '--' else 0.0 if relative_frequencies[priority] == '--': weight_label_text = f'Priority: {priority}' else: weight_label_format = 'Priority: {}, {} Songs in priority. Each song will' +\ ' appear in 1 out of every {:.2f} playlists ({:.2f} out of {} for a single playlist)' weight_label_text = weight_label_format.format(priority, num_songs_in_priority, float(relative_frequencies[priority]), priority_playlist_frequency, SONGS_IN_PLAYLIST) weight_label.configure(text=weight_label_text)
def create_library_from_directory(self): try: library_directory = filedialog.askdirectory() if library_directory: self.library = ml.create_library(library_directory) self.current_library_filename = None self.current_category = None self.refresh_category_om() self.refresh_song_lb(None) self.load_weights() except Exception as e: print(traceback.print_exc()) messagebox.showerror('Create Library Error', e)
def load_library(self, library_filename: typing.Optional[str] = None): try: if not library_filename: library_filename = filedialog.askopenfilename(initialdir=os.getcwd(), title="Select Music Library", filetypes=(("json", "*.json"),)) if library_filename: self.library = ml.load_library(library_filename) self.current_library_filename = library_filename self.current_category = None self.refresh_category_om() self.refresh_song_lb(None) self.load_weights() except Exception as e: print(traceback.print_exc()) messagebox.showerror('Open Library Error', e)
def update_library_keep_repeats(self): if not self.library: return try: library_directory = filedialog.askdirectory() if library_directory: self.library = ml.get_updated_library_keep_repeats(self.library, library_directory) self.current_category = None self.refresh_category_om() self.refresh_song_lb(None) self.load_weights() except Exception as e: print(traceback.print_exc()) messagebox.showerror('Create Library Error', e)
def library(self, path): MusicLibrary.load(path)
def selectedSongs(self): return MusicLibrary.displayCount()
def sameGenre(self): MusicLibrary.findArtist(MusicLibrary.looking.genre)
def sameAlbum(self): MusicLibrary.findAlbum(MusicLibrary.looking.album)
def sameArtist(self): MusicLibrary.findArtist(MusicLibrary.looking.artist)
def reset_repeat_data(self): if self.library: ml.reset_repeat_data(self.library)
def select(self, i): MusicLibrary.select(MusicLibrary.library[i-1])
def reset_repeat_data_special(self): if self.library: ml.reset_repeats_special(self.library)
def query(self): return MusicLibrary.displayContents()
def sameYear(self): MusicLibrary.findArtist(MusicLibrary.looking.year)
def showAll(self): MusicLibrary.findAll()
def select(self, i): MusicLibrary.select(MusicLibrary.library[i - 1])