Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend file type support #70

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions pymkv/MKVFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class MKVFile:
Raised if the path to mkvmerge could not be verified.
"""

def __init__(self, file_path=None, title=None):
self.mkvmerge_path = 'mkvmerge'
def __init__(self, file_path=None, title=None, mkvmerge_path='mkvmerge'):
self.mkvmerge_path = mkvmerge_path
self.title = title
self._chapters_file = None
self._chapter_language = None
Expand All @@ -89,32 +89,32 @@ def __init__(self, file_path=None, title=None):
self._link_to_next_file = None
self.tracks = []
self.attachments = []
if file_path is not None and not verify_mkvmerge(mkvmerge_path=self.mkvmerge_path):
raise FileNotFoundError('mkvmerge is not at the specified path, add it there or change the mkvmerge_path '
'property')
if file_path is not None and verify_matroska(file_path):
# add file title
file_path = expanduser(file_path)
info_json = json.loads(sp.check_output([self.mkvmerge_path, '-J', file_path]).decode())
if self.title is None and 'title' in info_json['container']['properties']:
self.title = info_json['container']['properties']['title']

# add tracks with info
for track in info_json['tracks']:
new_track = MKVTrack(file_path, track_id=track['id'])
if 'track_name' in track['properties']:
new_track.track_name = track['properties']['track_name']
if 'language' in track['properties']:
new_track.language = track['properties']['language']
if 'default_track' in track['properties']:
new_track.default_track = track['properties']['default_track']
if 'forced_track' in track['properties']:
new_track.forced_track = track['properties']['forced_track']
self.add_track(new_track)

# split options
self._split_options = []

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 file_path is not None:
file_path = expanduser(file_path)
info = json.loads(sp.check_output([self.mkvmerge_path, '-J', file_path]).decode())
if info['container']['recognized'] is True and info['container']['supported'] is True:
# add file title
if self.title is None and 'title' in info['container']['properties']:
self.title = info['container']['properties']['title']

# add tracks with info
for track in info['tracks']:
new_track = MKVTrack(file_path, track_id=track['id'], mkvmerge_path=mkvmerge_path)
if 'track_name' in track['properties']:
new_track.track_name = track['properties']['track_name']
if 'language' in track['properties']:
new_track.language = track['properties']['language']
if 'default_track' in track['properties']:
new_track.default_track = track['properties']['default_track']
if 'forced_track' in track['properties']:
new_track.forced_track = track['properties']['forced_track']
self.add_track(new_track)

def __repr__(self):
return repr(self.__dict__)

Expand Down