From 3018d10b6d48d7788e9f8a26aa366c3e05960e89 Mon Sep 17 00:00:00 2001 From: Sheldon Woodward Date: Sat, 17 Oct 2020 12:48:16 -0700 Subject: [PATCH] Release/1.0.8 (#63) * Do not let muxing fail silently If the muxing process exits with non-zero status code, it would be useful to deal with that error. As of now it fails but the Python interpreter doesn't know it. To give an example, tried muxing a file with a non-existing, non-user-writable output path and the process failed but the interpreter didn't catch any error, so it seemed like it worked when in fact it didn't. * Add support for os.PathLike objects (#62) * Add support for Path objects MKVTrack and MKVFile's mux() already support passing a Path object for the file_path argument. Would be even better to add support for general os.path-like object, not only strings. * Update Verifications.py Added support for all Path-like objects, instead of only pathlib's Path. Co-authored-by: Marco Rubin <20150305+Rubo3@users.noreply.github.com> --- pymkv/MKVFile.py | 4 ++-- pymkv/Verifications.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pymkv/MKVFile.py b/pymkv/MKVFile.py index ea581f0..afc234c 100644 --- a/pymkv/MKVFile.py +++ b/pymkv/MKVFile.py @@ -260,11 +260,11 @@ def mux(self, output_path, silent=False): 'property') output_path = expanduser(output_path) if silent: - sp.run(self.command(output_path, subprocess=True), stdout=open(devnull, 'wb')) + sp.run(self.command(output_path, subprocess=True), stdout=open(devnull, 'wb'), check=True) else: command = self.command(output_path) print('Running with command:\n"' + command + '"') - sp.run(self.command(output_path, subprocess=True)) + sp.run(self.command(output_path, subprocess=True), check=True, capture_output=True) def add_file(self, file): """Add an MKV file into the :class:`~pymkv.MKVFile` object. diff --git a/pymkv/Verifications.py b/pymkv/Verifications.py index 9a7fe27..ad74270 100644 --- a/pymkv/Verifications.py +++ b/pymkv/Verifications.py @@ -4,6 +4,7 @@ """Verification functions for mkvmerge and associated files.""" import json +import os from os.path import expanduser, isfile from re import match import subprocess as sp @@ -25,7 +26,7 @@ def verify_mkvmerge(mkvmerge_path='mkvmerge'): def verify_matroska(file_path, mkvmerge_path='mkvmerge'): - """Verify a file is a Matroska file. + """Verify if a file is a Matroska file. file_path (str): Path of the file to be verified. @@ -35,7 +36,9 @@ def verify_matroska(file_path, mkvmerge_path='mkvmerge'): if not verify_mkvmerge(mkvmerge_path=mkvmerge_path): raise FileNotFoundError('mkvmerge is not at the specified path, add it there or change the mkvmerge_path ' 'property') - if not isinstance(file_path, str): + if isinstance(file_path, os.PathLike): + file_path = str(file_path) + elif not isinstance(file_path, str): raise TypeError('"{}" is not of type str'.format(file_path)) file_path = expanduser(file_path) if not isfile(file_path):