Exemple #1
0
    def __init__(self, file_path=None, title=None):
        self.mkvmerge_path = 'mkvmerge'
        self.title = title
        self._chapters_file = None
        self._chapter_language = None
        self._global_tags_file = None
        self._link_to_previous_file = 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 = []
Exemple #2
0
    def __init__(self, file_path=None, title=None):
        """A class that represents an MKV file.

        The MKVFile class can either import a pre-existing MKV file or create a new one. After an MKVFile object has
        been instantiated, MKVTracks or other MKVFile objects can be added using add_track() and add_file()
        respectively.

        Tracks are always added in the same order that they exist in a file or are added in. They can be reordered
        using move_track_front(), move_track_end(), move_track_forward(), move_track_backward(), or swap_tracks().

        After an MKVFile has been created, an mkvmerge command can be generated using command() or the file can be
        muxed using mux().

        file_path (str, optional):
            Path to a pre-existing MKV file. The file will be imported into the new MKVFile object.
        title (str, optional):
            The internal title given to the MKVFile. If no title is given, the title of the pre-existing file will
            be used if it exists.
        """
        self.mkvmerge_path = 'mkvmerge'
        self.title = title
        self._chapters_file = None
        self._chapter_language = None
        self._global_tags_file = None
        self._link_to_previous_file = 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 = []
Exemple #3
0
    def link_to_next(self, file_path):
        """Link the output file as the successor of the file_path file.

        file_path (str):
            Path of the file to be linked to.
        """
        # check if valid file
        if not isinstance(file_path, str):
            raise TypeError('"{}" is not of type str'.format(file_path))
        file_path = expanduser(file_path)
        if not verify_matroska(file_path):
            raise ValueError('"{}" is not a matroska file'.format(file_path))
        self._link_to_next_file = file_path
Exemple #4
0
    def link_to_next(self, file_path):
        """Link the output file as the successor of the `file_path` file.

        Parameters
        ----------
        file_path : str
            Path of the file to be linked to.

        Raises
        ------
        TypeError
            Raised if `file_path` is not of type str.
        ValueError
            Raised if file at `file_path` cannot be verified as an MKV.
        """
        # check if valid file
        if not isinstance(file_path, str):
            raise TypeError('"{}" is not of type str'.format(file_path))
        file_path = expanduser(file_path)
        if not verify_matroska(file_path):
            raise ValueError('"{}" is not a matroska file'.format(file_path))
        self._link_to_next_file = file_path