Created
April 4, 2022 05:19
-
-
Save elibroftw/4599fb62d857bd5dce4040efc46e608d to your computer and use it in GitHub Desktop.
Python get files of multiple extensions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# abstracted from https://github.com/elibroftw/music-caster/blob/master/src/music_caster.py :: get_audio_uris | |
import glob | |
import os.path | |
from pathlib import Path | |
MY_EXTS = {'.mp3', '.flac', '.m4a', '.mp4', '.aac', '.mpeg', '.ogg', '.opus', '.wma', '.wav'} | |
def valid_file_ext(uri) -> bool: | |
""" | |
check if uri has a valid MY extension | |
uri does not have to be a file that exists | |
""" | |
return Path(uri).suffix.lower() in MY_EXTS | |
def get_file_types(directory): | |
for file in glob.iglob(f'{glob.escape(directory)}/**/*.*', recursive=True): | |
# might want to check use os.path.file_exists | |
if os.path.isfile(uri): | |
if valid_file_ext(file): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment