def has_music_files(path): count = 0 for ext in MUSIC_FILES: for f in os.listdir(path): if ext == get_extension(f): count += 1 return count > 0
def get_apeflac_albums(): sql = ''' SELECT Title, ID, Path FROM Album ''' conn, c = connect() items = c.execute(sql).fetchall() conn.close() out = [] for item in items: pieces = get_pieces(item[1]) count_ape = 0 count_flac = 0 for piece in pieces: ext = get_extension(piece['Name']) if ext == 'flac': count_flac += 1 if ext == 'ape': count_ape += 1 if count_ape > 0 and count_flac > 0: it = { 'Title': item[0], 'ID': item[1], 'Path': item[2], 'CountApe': count_ape, 'CountFlac': count_flac, } out.append(it) return out
def tag_get_piece_paths(album_id): album = get_album(album_id) print(album['Title']) pieces = get_pieces(album_id) paths = [] for piece in pieces: if get_extension(piece['Name']) != 'cue': paths.append(os.path.join(album['Path'], piece['Name'])) return paths
def remove_tag(album_id, tag): album = get_album(album_id) print(album['Title']) pieces = get_pieces(album_id) for piece in pieces: if get_extension(piece['Name']) != 'cue': p = os.path.join(album['Path'], piece['Name']) delete_tag(p, tag) return ''
def delete_album_ape(album_id): pieces = get_pieces(album_id) for piece in pieces: if get_extension(piece['Name']) == 'ape': remove_piece(album_id, piece['Name']) delete_piece(piece['ID']) socket_log(msg=piece['Name'] + ' deleted', mode='info', id=album_id)
def insert_pieces(path, album_id, conn, c): for ext in MUSIC_FILES: for f in os.listdir(path): if f[0] != '.' and ext == get_extension(f): insert_piece( name=f, code='', # kirkpatrick(f, 'K ', ' '), album_id=album_id, c=c, conn=conn)
def check_subdirs(path): path = os.path.join(AUDIO_ROOT, path) if os.path.exists(path): for d in os.listdir(path): p = os.path.join(path, d) if os.path.isdir(p) and d not in SKIP_DIRS: for f in os.listdir(p): if f[0] != '.' and get_extension(f) in MUSIC_FILES: return True return False
def add_count(albums): for album in albums: count_pieces = 0 count_cue = 0 pieces = get_pieces(album['ID']) for piece in pieces: extension = get_extension(piece['Name']) if extension != 'cue': count_pieces += 1 else: count_cue += 1 album['CountPieces'] = count_pieces album['CountCues'] = count_cue
def get_apealone_albums(): sql = ''' SELECT Title, ID, Path FROM Album ''' conn, c = connect() items = [] try: items = c.execute(sql).fetchall() except: print_error(sql, 'apeflac') conn.close() out = [] for item in items: pieces = get_pieces(item[1]) count_ape = 0 count_flac = 0 count_cue = 0 count_piece = 0 for piece in pieces: ext = get_extension(piece['Name']) if ext == 'flac': count_flac += 1 if ext == 'ape': count_ape += 1 if ext == 'cue': count_cue += 1 else: count_piece += 1 if count_ape > 0 and count_flac == 0: # if 3 > count_ape > 0 == count_flac \ # and count_cue == 1: it = { 'Title': item[0], 'ID': item[1], 'Path': item[2], 'CountApe': count_ape, 'CountFlac': count_flac, 'CountCues': count_cue, 'CountPieces': count_piece } out.append(it) return out
def rename_music_files(path): for ext in MUSIC_FILES: for f in os.listdir(path): if ext == get_extension(f): rename_file(path, f) return ''
def has_musical_files(path): for ext in MUSIC_FILES: for f in os.listdir(path): if ext == get_extension(f): return True return False