Exemplo n.º 1
0
    def add_subtitle(self, set_default=True):
        """
        Muxes the subtitle in the MKV file and sets it as default if the flag
        is set appropriately (default True)

        Parameters
        ----------
            set_default : bool
                wether to set the muxed subtitle as default subtitle track.
                Default is `True`
        """
        stats = self._get_stats()
        subs = self.download_subtitles()
        movies = list()
        for idx, _ in enumerate(stats):
            movies.append({**stats[idx], **subs[idx]})

        for movie in movies:
            if not movie["has_lang"]:
                sub_track = MKVTrack(movie["sub"])
                sub_track.language = self.os_language
                sub_track.default_track = True if set_default else False
                mkv_file = MKVFile(movie["file_path"].absolute())
                mkv_file.add_track(sub_track)
                # TODO Handle output folder or file replace config
                mkv_file.mux(movie["file_path"].stem + "_w_sub.mkv")

        return True
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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.')