Skip to content

Commit

Permalink
Release/1.0.8 (#63)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
sheldonkwoodward and Rubo3 authored Oct 17, 2020
1 parent 64a6e96 commit 3018d10
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pymkv/MKVFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions pymkv/Verifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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):
Expand Down

0 comments on commit 3018d10

Please sign in to comment.