platypush/backend/http/app/routes/plugins/media/__init__.py
def add_subtitles(media_id, req):
    """
    This route can be used to download and/or expose subtitles files
    associated to a media file
    """

    media_hndl = media_map.get(media_id)
    if not media_hndl:
        raise FileNotFoundError('{} is not a registered media_id'.format(media_id))

    subfile = None
    if req.data:
        subfile = json.loads(req.data.decode('utf-8')).get('filename')
        if not subfile:
            raise AttributeError('No filename specified in the request')

    if not subfile:
        if not media_hndl.path:
            raise NotImplementedError(
                'Subtitles are currently only supported for local media files')

        req = {
            'type': 'request',
            'action': 'media.subtitles.get_subtitles',
            'args': {
                'resource': media_hndl.path,
            }
        }

        try:
            subtitles = send_message(req).output or []
        except Exception as e:
            raise RuntimeError('Could not get subtitles: {}'.format(str(e)))

        if not subtitles:
            raise FileNotFoundError('No subtitles found for resource {}'.
                                    format(media_hndl.path))

        req = {
            'type': 'request',
            'action': 'media.subtitles.download',
            'args': {
                'link': subtitles[0].get('SubDownloadLink'),
                'media_resource': media_hndl.path,
                'convert_to_vtt': True,
            }
        }

        subfile = (send_message(req).output or {}).get('filename')

    media_hndl.set_subtitles(subfile)
    return {
        'filename': subfile,
        'url': get_remote_base_url() + '/media/subtitles/' + media_id + '.vtt',
    }

    This route can be used to download and/or expose subtitles files
    associated to a media file
    
This route can be used to download and/or expose subtitles files
associated to a media file
This route can be used to download and / or expose subtitles files associated to a media file
def add_subtitles(media_id, req):
    media_hndl = media_map.get(media_id)
    if not media_hndl:
        raise FileNotFoundError('{} is not a registered media_id'.format(media_id))
    subfile = None
    if req.data:
        subfile = json.loads(req.data.decode('utf-8')).get('filename')
        if not subfile:
            raise AttributeError('No filename specified in the request')
    if not subfile:
        if not media_hndl.path:
            raise NotImplementedError(
                'Subtitles are currently only supported for local media files')
        req = {
            'type': 'request',
            'action': 'media.subtitles.get_subtitles',
            'args': {
                'resource': media_hndl.path,
            }
        }
        try:
            subtitles = send_message(req).output or []
        except Exception as e:
            raise RuntimeError('Could not get subtitles: {}'.format(str(e)))
        if not subtitles:
            raise FileNotFoundError('No subtitles found for resource {}'.
                                    format(media_hndl.path))
        req = {
            'type': 'request',
            'action': 'media.subtitles.download',
            'args': {
                'link': subtitles[0].get('SubDownloadLink'),
                'media_resource': media_hndl.path,
                'convert_to_vtt': True,
            }
        }
        subfile = (send_message(req).output or {}).get('filename')
    media_hndl.set_subtitles(subfile)
    return {
        'filename': subfile,
        'url': get_remote_base_url() + '/media/subtitles/' + media_id + '.vtt',
    }
def add_subtitles ( media_id , req ) : media_hndl = media_map . get ( media_id ) if not media_hndl : raise FileNotFoundError ( '{} is not a registered media_id' . format ( media_id ) ) subfile = None if req . data : subfile = json . loads ( req . data . decode ( 'utf-8' ) ) . get ( 'filename' ) if not subfile : raise AttributeError ( 'No filename specified in the request' ) if not subfile : if not media_hndl . path : raise NotImplementedError ( 'Subtitles are currently only supported for local media files' ) req = { 'type' : 'request' , 'action' : 'media.subtitles.get_subtitles' , 'args' : { 'resource' : media_hndl . path , } } try : subtitles = send_message ( req ) . output or [ ] except Exception as e : raise RuntimeError ( 'Could not get subtitles: {}' . format ( str ( e ) ) ) if not subtitles : raise FileNotFoundError ( 'No subtitles found for resource {}' . format ( media_hndl . path ) ) req = { 'type' : 'request' , 'action' : 'media.subtitles.download' , 'args' : { 'link' : subtitles [ 0 ] . get ( 'SubDownloadLink' ) , 'media_resource' : media_hndl . path , 'convert_to_vtt' : True , } } subfile = ( send_message ( req ) . output or { } ) . get ( 'filename' ) media_hndl . set_subtitles ( subfile ) return { 'filename' : subfile , 'url' : get_remote_base_url ( ) + '/media/subtitles/' + media_id + '.vtt' , }
This route can be used to download and/or expose subtitles files
associated to a media file
This route can be used to download and / or expose subtitles files associated to a media file
"""
    This route can be used to download and/or expose subtitles files
    associated to a media file
    """
media_id
req