def copy_components(project_dir, bootstrap_dir): """ Copies the components from the bootstrap directory into the project directory. Returns a list of all the files that were installed. """ project = process_project.load_project(project_dir, bootstrap_dir) components = process_component.load_components(os.path.join(bootstrap_dir, "components"), project.component_names) # Copy all the components returned, not just the requested ones. to_copy = {} for component in components: for cat in component.provides_categories: if cat not in CATEGORIES: print("*** Found un-registered category " + cat) CATEGORIES.append(cat) if cat not in to_copy: to_copy[cat] = [] to_copy[cat].append(component.provides(cat, components)) generated = {} copied = {} for (cat, name_paths) in to_copy.items(): outdir = project.map_category_to_dir(cat) for name_path_map in name_paths: for (outname, src) in name_path_map.items(): dest = os.path.join(outdir, outname) if dest in generated: raise Exception("two or more components write to the same place (" + dest + ")") generated[dest] = True copied.update(_copy_struct(src, dest, project)) return list(copied.keys())
def copy_components(project_dir, bootstrap_dir): """ Copies the components from the bootstrap directory into the project directory. Returns a list of all the files that were installed. """ project = process_project.load_project(project_dir, bootstrap_dir) components = process_component.load_components( os.path.join(bootstrap_dir, "components"), project.component_names) # Copy all the components returned, not just the requested ones. to_copy = {} for component in components: for cat in component.provides_categories: if cat not in CATEGORIES: print("*** Found un-registered category " + cat) CATEGORIES.append(cat) if cat not in to_copy: to_copy[cat] = [] to_copy[cat].append(component.provides(cat, components)) generated = {} copied = {} for (cat, name_paths) in to_copy.items(): outdir = project.map_category_to_dir(cat) for name_path_map in name_paths: for (outname, src) in name_path_map.items(): dest = os.path.join(outdir, outname) if dest in generated: raise Exception( "two or more components write to the same place (" + dest + ")") generated[dest] = True copied.update(_copy_struct(src, dest, project)) return list(copied.keys())
def update_cached_playlists(spotify): user = spotify.current_user() playlist_items = spotify.all_items(spotify.followed_playlists()) playlists_by_name = { item.name: item for item in playlist_items if item.owner.id == user.id } missing_found = 0 for name, playlist_names in CATEGORIES.items(): group = CachedPlaylistGroup() for playlist_name in playlist_names: try: playlist = playlists_by_name[playlist_name] except KeyError: if args.create_missing: playlist = spotify.playlist_create( user.id, playlist_name, description="Automatically created by a script.") print( f"\033[1;32mCreated playlist: {playlist_name}\033[0m") else: print( f"\033[0;33mWarning: no playlist called '{playlist_name}' found\033[0m" ) missing_found += 1 continue print(f"Updating cache for [{playlist.id}] {playlist.name}...") obj = CachedPlaylist.from_tekore_playlist(playlist, spotify) group.add_playlist(obj) fp = open(name, 'w') json.dump(group.serialize(), fp, indent=2) fp.close() if missing_found: if missing_found == 1: print( "\033[1;33m1 playlist wasn't found.\n" "Rerun this script with --create-missing to create it.\033[0m") else: print( f"\033[1;33m{missing_found} playlists weren't found.\n" "Rerun this script with --create-missing to create them.\033[0m" )
def find_cached_playlist(name): """Returns the ID of the playlist with this name or something close enough to it, if it's in the playlist cache. Returns None if no such ID found.""" playlists = {} # name: id for filename in CATEGORIES.keys(): group = CachedPlaylistGroup.from_filename(filename) playlists.update({playlist.name: playlist for playlist in group}) matches = difflib.get_close_matches(name, playlists.keys(), n=1) if matches: return playlists[matches[0]] matches = difflib.get_close_matches("WCS " + name, playlists.keys(), n=1) if matches: return playlists[matches[0]] return None
sp.playlist_remove( playlist_id, ["spotify:track:" + track_id for track_id in found_in_playlist]) def log_output(message): print(message) if args.confirm_remove: args.output_file.write(message + "\n") log_output("=== " + datetime.datetime.now().isoformat() + " ===") handle_playlist(ALL_PLAYLIST_ID, ALL_PLAYLIST_NAME) for filename in CATEGORIES.keys(): playlists = json.load(open(filename)) for playlist in playlists: if playlist['id'] == REMOVED_PLAYLIST_ID: continue handle_playlist(playlist['id'], playlist['name']) for item in removed_items: if len(removed_track_playlists[item.track.id]) == 0: continue remove_string = "Removed" if args.confirm_remove else "Would remove" log_output( "{remove_string} [{track_id}] \"{name}\" ({artist}), which was in:". format( remove_string=remove_string,
def all_cached_playlists(): group = CachedPlaylistGroup() for filename in CATEGORIES.keys(): group.add_from_filename(filename) return group
def selectCategory(self, category): """ set a filter """ category = str(category) if not category in CATEGORIES.keys(): category = None self.database.search(category)
def category_groups(row): typ = row['TypeText'] return [k for k, v in CATEGORIES.iteritems() if typ in v]