Skip to content

Commit

Permalink
[BUGFIX sheldonkwoodward#73] Fix successive track removal
Browse files Browse the repository at this point in the history
  • Loading branch information
azsde committed Oct 26, 2022
1 parent 5a49315 commit c53e534
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pymkv/MKVFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

import bitmath

from pymkv.MKVTrack import MKVTrack
from pymkv.MKVTrack import MKVTrack, MKVTrackIdNotFound
from pymkv.MKVAttachment import MKVAttachment
from pymkv.Timestamp import Timestamp
from pymkv.ISO639_2 import is_ISO639_2
Expand Down Expand Up @@ -478,23 +478,24 @@ def replace_track(self, track_num, track):
else:
raise IndexError('track index out of range')

def remove_track(self, track_num):
def remove_track(self, track_id):
"""Remove a track from the :class:`~pymkv.MKVFile` object.
Parameters
----------
track_num : int
The track number of the track to remove.
track_id: int
The track id of the track to remove.
Raises
------
IndexError
Raised if `track_num` is is out of range of the track list.
MKVTrackIdNotFound
Raised if `track_id` is not found in the track list.
"""
if 0 <= track_num < len(self.tracks):
del self.tracks[track_num]
else:
raise IndexError('track index out of range')
for track in self.tracks:
if (track.track_id == track_id):
self.tracks.remove(track)
return
raise MKVTrackIdNotFound('Track id not found in the track list')

def split_none(self):
"""Remove all splitting options."""
Expand Down
3 changes: 3 additions & 0 deletions pymkv/MKVTrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,6 @@ def track_codec(self):
def track_type(self):
"""str: The type of track such as video or audio."""
return self._track_type

class MKVTrackIdNotFound(Exception):
pass

0 comments on commit c53e534

Please sign in to comment.