Пример #1
0
def addAudio(source, ext):
    for file in glob.glob("*." + ext):
        t = MKVTrack(file)
        lang = file.split('.')[0]
        t.track_name = lang
        t.language = langToShort(lang)
        print("Adding AudioTrack")
        source.add_track(t)
Пример #2
0
def addSubs(source, ext):
    for file in glob.glob("*." + ext):
        t = MKVTrack(file)
        lang = file.split('.')[0]
        if "_" in lang:
            lang = lang.split('_')[0]
        else:
            lang = lang
        t.track_name = shortToLong(lang)
        t.language = lang
        print("Adding new SUB")
        source.add_track(t)
Пример #3
0
 def add_subtitles(self, subtitles_text: str, language):
     self.logger.debug('Adding subtitles.')
     track = self.get_subtitles_track(language)
     fixed_subtitles_path = self.folder.joinpath('subtitles-fixed.txt')
     with fixed_subtitles_path.open(
             'w', encoding='utf-8') as fixed_subtitles_file:
         fixed_subtitles_file.write(subtitles_text)
     fixed_track = MKVTrack(fixed_subtitles_path.__str__())
     fixed_track.track_name = track.track_name + '-fixed'
     fixed_track.language = track.language
     self.mkv_file.add_track(fixed_track)
     output_name = Path(self.path.stem + '-fixed').with_suffix(
         self.path.suffix)
     output_path = self.path.with_name(output_name)
     self.mkv_file.mux(output_path.__str__())
     os.remove(fixed_subtitles_file.__str__())
     self.logger.debug('Successfully added subtitles.')