Skip to content

Commit

Permalink
Added --trimafterspace argument
Browse files Browse the repository at this point in the history
  • Loading branch information
latenitefilms committed Jun 24, 2023
1 parent f94eab8 commit d9371a5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ Here's a real-world example:
- `5bis-01-01 - 23Y06M08 - 5bis-01T01.wav.mxf`
- `A016C010_230608_R2QM - A016C010_230608_R2QM.new.01.mxf`

You can also use the optional `--trimafterspace` argument:

**Before:**

- `5bis-01T01A03.E0A869B4CDC3A.mxf`
- `V01.E0A7CD6A_55C5455C54DD8V.mxf`

**After:**

- `5bis-01-01.mxf`
- `A016C010_230608_R2QM.mxf`

---

## Easy Installation
Expand All @@ -52,12 +64,28 @@ To process a **folder** of MXF files:
./rename-avid-mxf "/path/to/folder"
```

You can also use the optional **Trim After Space** argument:

```bash
./rename-avid-mxf --trimafterspace "/path/to/folder/or/file"
```

This script will recursively search through the specified folder and rename all MXF files based on their package name.

**PRO TIP:** You can right-click on files in Finder with the OPTION key held down to copy a file or folders pathname.

---

## Version History

### v1.0.1 - Saturday 24th June 2023
- Added `--trimafterspace` argument.

### v1.0.0 - Saturday 24th June 2023
- Initial Release

---

## Manual Installation

If you don't want to download a pre-compiled executable, you can trigger the Python Script directly.
Expand Down
18 changes: 13 additions & 5 deletions Source/rename-avid-mxf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
if getattr(sys, 'frozen', False):
os.environ['DYLD_LIBRARY_PATH'] = sys._MEIPASS

def rename_file(path):
def rename_file(path, trim_after_space):
# Retrieve media information
media_info = MediaInfo.parse(path)

Expand All @@ -17,6 +17,11 @@ def rename_file(path):
if track.track_type == "General":
# Get the package name
package_name = track.package_name

# If the flag is set, trim the package name after the first space
if trim_after_space:
package_name = package_name.split(' ')[0]

# Clean the package name to avoid any illegal characters for filenames
package_name = package_name.replace('/', '-')

Expand All @@ -27,12 +32,12 @@ def rename_file(path):
# Rename the file
os.rename(path, new_path)

def process_directory(dir_path):
def process_directory(dir_path, trim_after_space):
for root, dirs, files in os.walk(dir_path):
for file in files:
if file.endswith('.mxf'):
file_path = os.path.join(root, file)
rename_file(file_path)
rename_file(file_path, trim_after_space)

def main():
# Create the parser
Expand All @@ -41,16 +46,19 @@ def main():
# Add an argument for the file path
parser.add_argument('path', type=str, help='The path to the MXF file or directory')

# Add the new argument for the trim after space flag
parser.add_argument('--trimafterspace', action='store_true', help='Trim the filename after the first space')

# Parse the arguments
args = parser.parse_args()

# Check if the path is a directory or a file
if os.path.isdir(args.path):
# If it's a directory, process all MXF files in the directory
process_directory(args.path)
process_directory(args.path, args.trimafterspace)
else:
# If it's a file, process the single file
rename_file(args.path)
rename_file(args.path, args.trimafterspace)

if __name__ == "__main__":
main()

0 comments on commit d9371a5

Please sign in to comment.