|
2 | 2 | import os |
3 | 3 | import argparse |
4 | 4 |
|
5 | | -def generate_media_list(directories, output_file): |
| 5 | +def generate_media_list(directories, output_file, file_extensions=None): |
6 | 6 | """ |
7 | 7 | Generates a list of media files from the specified directories and writes them to the output file. |
8 | 8 |
|
9 | 9 | Args: |
10 | 10 | directories (list of str): Directories to search for media files. |
11 | 11 | output_file (str): Path to the output file where the list will be saved. |
| 12 | + file_extensions (list of str, optional): File extensions to search for. |
| 13 | + Defaults to ['.mp4', '.mkv', '.avi'] |
12 | 14 | """ |
| 15 | + if file_extensions is None: |
| 16 | + file_extensions = ['.mp4', '.mkv', '.avi'] |
| 17 | + |
| 18 | + # Convert to tuple for endswith() method |
| 19 | + file_extensions = tuple(file_extensions) |
| 20 | + |
13 | 21 | media_files = [] |
14 | 22 | for directory in directories: |
15 | 23 | for root, dirs, files in os.walk(directory, topdown=True): |
16 | 24 | dirs[:] = [d for d in dirs if not d.startswith('.')] # Ignore hidden directories |
17 | 25 | for file in files: |
18 | | - if file.endswith(('.mp4', '.mkv', '.avi')): |
| 26 | + if file.lower().endswith(file_extensions): |
19 | 27 | media_files.append(os.path.join(root, file)) |
20 | 28 |
|
21 | 29 | with open(output_file, 'w', encoding='utf-8') as f: |
|
0 commit comments