#NEWLINE# def save_subtitles( video , subtitles , single = False , directory = None , encoding = None ) : #NEWLINE# #INDENT# 'Save subtitles on filesystem.\n\n    Subtitles are saved in the order of the list. If a subtitle with a language has already been saved, other subtitles\n    with the same language are silently ignored.\n\n    The extension used is `.lang.srt` by default or `.srt` is `single` is `True`, with `lang` being the IETF code for\n    the :attr:`~subliminal.subtitle.Subtitle.language` of the subtitle.\n\n    :param video: video of the subtitles.\n    :type video: :class:`~subliminal.video.Video`\n    :param subtitles: subtitles to save.\n    :type subtitles: list of :class:`~subliminal.subtitle.Subtitle`\n    :param bool single: save a single subtitle, default is to save one subtitle per language.\n    :param str directory: path to directory where to save the subtitles, default is next to the video.\n    :param str encoding: encoding in which to save the subtitles, default is to keep original encoding.\n    :return: the saved subtitles\n    :rtype: list of :class:`~subliminal.subtitle.Subtitle`\n\n    ' #NEWLINE# saved_subtitles = [ ] #NEWLINE# for subtitle in subtitles : #NEWLINE# #INDENT# if ( subtitle . content is None ) : #NEWLINE# #INDENT# logger . error ( 'Skipping subtitle %r: no content' , subtitle ) #NEWLINE# continue #NEWLINE# #UNINDENT# if ( subtitle . language in set ( ( s . language for s in saved_subtitles ) ) ) : #NEWLINE# #INDENT# logger . debug ( 'Skipping subtitle %r: language already saved' , subtitle ) #NEWLINE# continue #NEWLINE# #UNINDENT# subtitle_path = get_subtitle_path ( video . name , ( None if single else subtitle . language ) ) #NEWLINE# if ( directory is not None ) : #NEWLINE# #INDENT# subtitle_path = os . path . join ( directory , os . path . split ( subtitle_path ) [ 1 ] ) #NEWLINE# #UNINDENT# logger . info ( 'Saving %r to %r' , subtitle , subtitle_path ) #NEWLINE# if ( encoding is None ) : #NEWLINE# #INDENT# with io . open ( subtitle_path , 'wb' ) as f : #NEWLINE# #INDENT# f . write ( s . content ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# with io . open ( subtitle_path , 'w' , encoding = encoding ) as f : #NEWLINE# #INDENT# f . write ( subtitle . text ) #NEWLINE# #UNINDENT# #UNINDENT# saved_subtitles . append ( subtitle ) #NEWLINE# if single : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return saved_subtitles