Sebaorgo Posted February 16, 2019 Report Share Posted February 16, 2019 Salut am nevoie de ajutor in python. problema se pune in felul urmator : am un folder cu mai multe fisiere audio de tip wav sau mp3 vreau sa fac o lista cu numele fisierelor si lungimea lor luate din proprietati, nu prin calcule, este posibil in python ? multumesc in avans ! Quote Link to comment Share on other sites More sharing options...
Active Members MrGrj Posted February 16, 2019 Active Members Report Share Posted February 16, 2019 (edited) """ Python version: > 3.6 """ import os DIR_PATH = '/path/to/your/music/folder' def print_files_info(): for file in os.listdir(DIR_PATH): file_path = os.path.join(DIR_PATH, file) file_size = os.path.getsize(file_path) print(f'Name: {file}; Size: {file_size} bytes.') if __name__ == '__main__': print_files_info() Asta de mai sus iti afiseasa numele si marimea unui fisier. Daca vrei sa afisezi lungimea melodiei: - pentru fisiere .mp3, poti folosi mutagen: - pentru fisiere .wav, poti folosi wave si contextlib: import contextlib import os import wave from mutagen.mp3 import MP3 DIR_PATH = '/path/to/your/music/folder' def print_files_info(): for file in os.listdir(DIR_PATH): file_path = os.path.join(DIR_PATH, file) file_size = os.path.getsize(file_path) if file.endswith('.mp3'): audio = MP3(file_path) print(f'Name: {file}; Size: {file_size} bytes; Type: mp3; Length: {audio.info.length}') elif file.endswith('.wav'): with contextlib.closing(wave.open(file_path, 'r')) as f: # The length of an audio or wave file is determined by its framerate frames = f.getnframes() rate = f.getframerate() length = frames / float(rate) print(f'Name: {file}; Size: {file_size} bytes; Type: wav; Length: {length}') else: print('Pula .mp3 sau .wav') if __name__ == '__main__': print_files_info() Edited February 16, 2019 by MrGrj Quote Link to comment Share on other sites More sharing options...
Sebaorgo Posted February 16, 2019 Author Report Share Posted February 16, 2019 Multumesc ! Merge de vis Quote Link to comment Share on other sites More sharing options...
Sebaorgo Posted February 21, 2019 Author Report Share Posted February 21, 2019 (edited) Mai am o intrebare : cum pot sa dau precizia fisierelor wav in milisecunde ? Momentan e "prea exact" de ex : length = 292.33922902494334 si eu vreau : length = 292.339 Multumesc anticipat ! EDIT : Am reusit dar nu mai pot sterge postarea Edited February 21, 2019 by Sebaorgo Quote Link to comment Share on other sites More sharing options...