def html_opener(path, meta):
    if not meta:
        html_url = quoted_url('files:direct', path=path)
        return dict(html_url=html_url, keep_formatting=False)

    file_path = os.path.join(meta.path, meta['html']['main'])
    html_url = quoted_url('files:direct', path=file_path)
    keep_formatting = meta['html']['keep_formatting']
    return dict(html_url=html_url, keep_formatting=keep_formatting)
def audio_opener(path, meta):
    if not meta:
        return dict(audio_url=quoted_url('files:direct', path=path),
                    audio_title=os.path.basename(path))

    audio_path = os.path.join(meta.path, meta['audio']['playlist'][0]['file'])
    return dict(audio_url=quoted_url('files:direct', path=audio_path),
                audio_title=meta['audio']['playlist'][0]['title'],
                meta=meta)
def video_opener(path, meta):
    if not meta:
        return dict(video_url=quoted_url('files:direct', path=path),
                    width='100%',
                    height='100%')

    resolution = (meta['video'].get('resolution') or 'x').split('x')
    width, height = [int(x) if x else '100%' for x in resolution]
    file_path = os.path.join(meta.path, meta['video']['main'])
    video_url = quoted_url('files:direct', path=file_path)
    return dict(video_url=video_url, width=width, height=height)
def get_folder_cover(fsobj):
    cover = fsobj.dirinfo.get(request.locale, 'cover', None)
    if cover:
        # There is a cover image
        cover_path = fsobj.other_path(cover)
        return quoted_url('files:direct', path=cover_path)
    # Look for default cover
    default_cover = fsobj.other_path('cover.jpg')
    if not request.app.supervisor.exts.fsal.exists(default_cover):
        return
    fsobj.dirinfo.set('cover', 'cover.jpg')
    fsobj.dirinfo.store()
    return quoted_url('files:direct', path=default_cover)
def get_view_path(fsobj):
    """
    Return a view URL with specified file preselected.
    """
    ext = fsobj.rel_path.rsplit('.', 1)[-1].lower()
    view = EXTENSION_VIEW_MAPPING.get(ext)
    if not view:
        return quoted_url('files:direct', path=fsobj.rel_path)
    parent = os.path.dirname(fsobj.rel_path) or '.'
    return i18n_url('files:path', path=parent, view=view, selected=fsobj.name)
def retrieve_thumb_url(path, defaults):
    thumb_url = None
    thumb_path = get_thumb_path(urlunquote(request.query.get('target')))
    if thumb_path:
        thumb_url = quoted_url('files:direct', path=thumb_path)
    else:
        facet_type = request.query.get('facet', 'generic')
        try:
            facet = defaults['facets'][facet_type]
        except KeyError:
            pass
        else:
            cover = facet.get('cover')
            if cover:
                cover_path = os.path.join(facet['path'], cover)
                thumb_url = quoted_url('files:direct',
                                       path=cover_path)

    return dict(url=thumb_url)
Example #7
0
def get_folder_cover(fsobj):
    """
    Return the URL of the cover image belonging to the passed in folder
    ``fsobj`` under the current locale.
    """
    cover = fsobj.meta.get('cover', language=request.locale)
    if not cover:
        # No cover image found (default is checked for in the meta extractor)
        return
    # There is a cover image
    cover_path = fsobj.other_path(cover)
    return quoted_url('filemanager:direct', path=cover_path)
Example #8
0
def get_view_path(fsobj):
    """
    Return a view URL with specified file preselected.
    """
    ext = fsobj.rel_path.rsplit('.', 1)[-1].lower()
    view = EXTENSION_VIEW_MAPPING.get(ext)
    if not view:
        return quoted_url('filemanager:direct', path=fsobj.rel_path)
    parent = os.path.dirname(fsobj.rel_path) or '.'
    return i18n_url('filemanager:list',
                    path=parent,
                    view=view,
                    selected=fsobj.name)
def get_folder_icon(fsobj):
    """
    Return folder icon or icon URL and a flag that tells us whether icon is a
    URL or not
    """
    icon = fsobj.dirinfo.get(request.locale, 'icon', None)
    if icon:
        # Dirinfo has an icon, so let's use that
        return quoted_url('files:direct', path=fsobj.other_path(icon)), True
    # Since dirinfo does not have an icon for us, we'll see if there's an icon
    # for a view
    view = fsobj.dirinfo.get(request.locale, 'view', 'generic')
    return 'folder' if view == 'generic' else view, False
Example #10
0
def get_folder_icon(fsobj):
    """
    Return folder icon or icon URL and a flag that tells us whether icon is a
    URL or not
    """
    icon = fsobj.meta.get('icon', request.locale)
    if icon:
        # Dirinfo has an icon, so let's use that
        return quoted_url('filemanager:direct',
                          path=fsobj.other_path(icon)), True
    # Since metadata does not have an icon for us, we'll see if there's an
    # icon for a view
    view = fsobj.meta.get('view', request.locale, 'generic')
    return 'folder' if view == 'generic' else view, False
Example #11
0
def get_file_thumb(fsobj):
    """
    Return icon name or thumbnail URL and flag that tells us if returned value
    is an URL.
    """
    ext = fsobj.rel_path.rsplit('.', 1)[-1].lower()
    thumb = None
    if EXTENSION_VIEW_MAPPING.get(ext) == 'image':
        try:
            thumb = get_thumb_path(fsobj.rel_path)
        except Exception:
            pass
    else:
        thumb = None
    if not thumb:
        # No thumb for this file, so let's try an icon
        return get_file_icon(fsobj), False
    else:
        return quoted_url('filemanager:direct', path=thumb), True