platypush/plugins/media/subtitles/__init__.py
def download(self, link, media_resource=None, path=None, convert_to_vtt=False):
        """
        Downloads a subtitle link (.srt/.vtt file or gzip/zip OpenSubtitles archive link) to the specified directory

        :param link: Local subtitles file or OpenSubtitles gzip download link
        :type link: str

        :param path: Path where the subtitle file will be downloaded (default: temporary file under /tmp)
        :type path: str

        :param media_resource: Name of the media resource. If set and if it's a
            media local file then the subtitles will be saved in the same folder
        :type media_resource: str

        :param convert_to_vtt: If set to True, then the downloaded subtitles
            will be converted to VTT format (default: no conversion)
        :type convert_to_vtt: bool

        :returns: dict.

        Format::

            {
                "filename": "/path/to/subtitle/file.srt"
            }

        """

        if link.startswith('file://'):
            link = link[len('file://'):]
        if os.path.isfile(link):
            if convert_to_vtt:
                link = self.to_vtt(link).output
            return {'filename': link}

        gzip_content = requests.get(link).content

        if not path and media_resource:
            if media_resource.startswith('file://'):
                media_resource = media_resource[len('file://'):]
            if os.path.isfile(media_resource):
                media_resource = os.path.abspath(media_resource)
                path = os.path.join(
                    os.path.dirname(media_resource),
                    '.'.join(os.path.basename(media_resource).split('.')[:-1])) + '.srt'

        if path:
            f = open(path, 'wb')
        else:
            f = tempfile.NamedTemporaryFile(prefix='media_subs_',
                                            suffix='.srt', delete=False)
            path = f.name

        try:
            with f:
                f.write(gzip.decompress(gzip_content))
            if convert_to_vtt:
                path = self.to_vtt(path).output
        except Exception as e:
            os.unlink(path)
            raise e

        return {'filename': path}

        Downloads a subtitle link (.srt/.vtt file or gzip/zip OpenSubtitles archive link) to the specified directory

        :param link: Local subtitles file or OpenSubtitles gzip download link
        :type link: str

        :param path: Path where the subtitle file will be downloaded (default: temporary file under /tmp)
        :type path: str

        :param media_resource: Name of the media resource. If set and if it's a
            media local file then the subtitles will be saved in the same folder
        :type media_resource: str

        :param convert_to_vtt: If set to True, then the downloaded subtitles
            will be converted to VTT format (default: no conversion)
        :type convert_to_vtt: bool

        :returns: dict.

        Format::

            {
                "filename": "/path/to/subtitle/file.srt"
            }

        
Downloads a subtitle link (.srt/.vtt file or gzip/zip OpenSubtitles archive link) to the specified directory
Downloads a subtitle link ( . srt / . vtt file or gzip / zip OpenSubtitles archive link ) to the specified directory
def download(self, link, media_resource=None, path=None, convert_to_vtt=False):
        if link.startswith('file://'):
            link = link[len('file://'):]
        if os.path.isfile(link):
            if convert_to_vtt:
                link = self.to_vtt(link).output
            return {'filename': link}
        gzip_content = requests.get(link).content
        if not path and media_resource:
            if media_resource.startswith('file://'):
                media_resource = media_resource[len('file://'):]
            if os.path.isfile(media_resource):
                media_resource = os.path.abspath(media_resource)
                path = os.path.join(
                    os.path.dirname(media_resource),
                    '.'.join(os.path.basename(media_resource).split('.')[:-1])) + '.srt'
        if path:
            f = open(path, 'wb')
        else:
            f = tempfile.NamedTemporaryFile(prefix='media_subs_',
                                            suffix='.srt', delete=False)
            path = f.name
        try:
            with f:
                f.write(gzip.decompress(gzip_content))
            if convert_to_vtt:
                path = self.to_vtt(path).output
        except Exception as e:
            os.unlink(path)
            raise e
        return {'filename': path}
def download ( self , link , media_resource = None , path = None , convert_to_vtt = False ) : if link . startswith ( 'file://' ) : link = link [ len ( 'file://' ) : ] if os . path . isfile ( link ) : if convert_to_vtt : link = self . to_vtt ( link ) . output return { 'filename' : link } gzip_content = requests . get ( link ) . content if not path and media_resource : if media_resource . startswith ( 'file://' ) : media_resource = media_resource [ len ( 'file://' ) : ] if os . path . isfile ( media_resource ) : media_resource = os . path . abspath ( media_resource ) path = os . path . join ( os . path . dirname ( media_resource ) , '.' . join ( os . path . basename ( media_resource ) . split ( '.' ) [ : - 1 ] ) ) + '.srt' if path : f = open ( path , 'wb' ) else : f = tempfile . NamedTemporaryFile ( prefix = 'media_subs_' , suffix = '.srt' , delete = False ) path = f . name try : with f : f . write ( gzip . decompress ( gzip_content ) ) if convert_to_vtt : path = self . to_vtt ( path ) . output except Exception as e : os . unlink ( path ) raise e return { 'filename' : path }
Downloads a subtitle link (.srt/.vtt file or gzip/zip OpenSubtitles archive link) to the specified directory
Downloads a subtitle link ( . srt / . vtt file or gzip / zip OpenSubtitles archive link ) to the specified directory
"""
        Downloads a subtitle link (.srt/.vtt file or gzip/zip OpenSubtitles archive link) to the specified directory

        :param link: Local subtitles file or OpenSubtitles gzip download link
        :type link: str

        :param path: Path where the subtitle file will be downloaded (default: temporary file under /tmp)
        :type path: str

        :param media_resource: Name of the media resource. If set and if it's a
            media local file then the subtitles will be saved in the same folder
        :type media_resource: str

        :param convert_to_vtt: If set to True, then the downloaded subtitles
            will be converted to VTT format (default: no conversion)
        :type convert_to_vtt: bool

        :returns: dict.

        Format::

            {
                "filename": "/path/to/subtitle/file.srt"
            }

        """
dict.
Format:.

{
"filename": "/path/to/subtitle/file.srt"
}
dict . Format : . { " filename " : " / path / to / subtitle / file . srt " }
self
link
Local subtitles file or OpenSubtitles gzip download link
Local subtitles file or OpenSubtitles gzip download link
media_resource
Name of the media resource. If set and if it's a
media local file then the subtitles will be saved in the same folder
Name of the media resource . If set and if it ' s a media local file then the subtitles will be saved in the same folder
path
Path where the subtitle file will be downloaded (default: temporary file under /tmp)
Path where the subtitle file will be downloaded ( default : temporary file under / tmp )
convert_to_vtt
If set to True, then the downloaded subtitles
will be converted to VTT format (default: no conversion)
If set to True then the downloaded subtitles will be converted to VTT format ( default : no conversion )