コード例 #1
0
ファイル: previewcache.py プロジェクト: jtoledo1974/raw2jpeg
def build_preview(origpath, preview, thumbnail):
    try:
        os.makedirs(dirname(preview))
    except OSError as exception:
        if exception.errno != errno.EEXIST:
            raise

    try:
        with open(preview, "w") as out, Preview(origpath) as img:
            if thumbnail:
                out.write(img.read_jpeg_preview(0))  # The smallest available
            else:
                out.write(img.read_jpeg_preview(-1))  # The largest available
            orientation = img.Orientation

            # XBMC no interpreta el exif del tif. Sacamos el JPEG embebido

            # Commented out because for some reason it is failing
            # in the rspbrry pi
            # try:
            #     subprocess.call(
            #         ["exiv2", preview,
            #          "-Mset Exif.Image.Orientation %s" % orientation],
            #         stderr=FNULL)
            # except:
            #     logging.debug("Unable to set Orientation information")

            logging.debug("Built %s preview" % preview)
            return (preview, orientation)
    except:
        os.unlink(preview)
        raise
コード例 #2
0
ファイル: bgallery.py プロジェクト: jtoledo1974/bgallery
def get_file_preview(path):
    path = unquote(path)
    logging.debug("get_preview %s" % path)
    path = join(root, path)
    (preview, orientation) = get_preview(path, return_orientation=True)
    # Using relpath is very inefficient here, so we don't do it
    return (preview[len(root):], orientation)
コード例 #3
0
ファイル: bgallery.py プロジェクト: jtoledo1974/bgallery
def jpeg(path):
    logging.debug("jpeg %s" % path)
    preview_path, orientation = get_file_preview(path)
    filedir = join(root, dirname(preview_path))
    filename = basename(preview_path)
    res = static_file(filename, root=filedir)
    res.set_header('Orientation', orientation)
    res.set_header('Content-Type', 'image/jpeg')
    return res
コード例 #4
0
ファイル: bgallery.py プロジェクト: jtoledo1974/bgallery
def thumb(path):
    logging.debug("thumb %s" % path)
    thumb_path, orientation, file_type = get_thumb(path)
    filedir = join(root, dirname(thumb_path))
    filename = basename(thumb_path)
    res = static_file(filename, root=filedir)
    res.set_header('Orientation', orientation)
    res.set_header('Content-Type', 'image/jpeg')
    return res
コード例 #5
0
ファイル: bgallery.py プロジェクト: jtoledo1974/bgallery
def get_thumb(path):
    path = unquote(path)
    logging.debug("get_thumb %s" % path)
    path = join(root, path)
    try:
        # TODO Might be worth avoiding this isdir check
        if isdir(path):
            return get_dir_thumb(path) + (DIR,)
        elif isfile(path):
            return get_file_thumb(path) + (FILE,)
        else:
            return ('', 0, None)
    except Exception as e:
        logging.warning(
            "Failed to retrieve a thumbnail for %s: %s" % (path, e))
        return ("", 0, None)
コード例 #6
0
ファイル: bgallery.py プロジェクト: jtoledo1974/bgallery
def get_dir_thumb(path):
    logging.debug("get_dir_thumb %s" % path)
    try:
        listdir = os.listdir(path)
        if ".nomedia" in listdir:
            raise HiddenError
        # splitext is very inefficient here, so we don't use it
        img = [de for de in listdir
               if de[-4:].lower() in ('.dng', '.jpg', 'jpeg')][0]
        res = get_file_thumb(join(path, img))
        logging.debug("Got result %s %s" % res)
        return res
    except (PreviewError, IndexError):
        # No proper images in the directory.
        # Recurse into the subdirectories
        dirlist = [d for d in os.listdir(path)
                   if isdir(join(path, d))]
        d = dirlist.pop(0)
        while(d):
            try:
                return get_dir_thumb(join(path, d))
            except (PreviewError, IndexError):
                d = dirlist.pop(0)
コード例 #7
0
ファイル: bgallery.py プロジェクト: jtoledo1974/bgallery
def folder(path):
    path = unquote(path)
    logging.debug("folder %s" % path)
    realpath = join(root, path, '')

    response.content_type = 'text/utf-8'

    yield dumps({'dir': path})+'\n'

    direntries = []

    for de in os.listdir(realpath):
        thumb_path, orientation, file_type = get_thumb(join(realpath, de))
        if thumb_path:
            direntries.append([de, orientation, file_type])

    direntries = sorted([t for t in direntries if t[2] == DIR], reverse=True)\
        + sorted([t for t in direntries if t[2] == FILE])

    for t in direntries:
        de, orientation, file_type = t
        s = dumps([de, orientation, file_type])+'\n'
        logging.debug(s)
        yield s
コード例 #8
0
ファイル: previewcache.py プロジェクト: jtoledo1974/raw2jpeg
 def add(self, path):
     logging.debug("Blacklisting %s" % path)
     self.bl[path] = os.path.getmtime(path)
     self._save()
コード例 #9
0
ファイル: previewcache.py プロジェクト: jtoledo1974/raw2jpeg
 def set(self, path, orientation):
     logging.debug("Setting orientation %d for %s" % (orientation, path))
     self.o[path] = orientation
     self._save()
コード例 #10
0
ファイル: bgallery.py プロジェクト: jtoledo1974/bgallery
def file(path):
    path = unquote(path)
    logging.debug("file %s" % path)
    filedir = join(root, dirname(path))
    filename = basename(path)
    return static_file(filename, root=filedir)
コード例 #11
0
ファイル: bgallery.py プロジェクト: jtoledo1974/bgallery
def get_root():
    logging.debug("get_root")
    return folder('')
コード例 #12
0
ファイル: bgallery.py プロジェクト: jtoledo1974/bgallery
def get_file_thumb(path):
    logging.debug("get_file_thumb %s" % path)
    (thumb, orientation) = get_preview(path, thumbnail=True,
                                       return_orientation=True)
    # Using relpath is very inefficient here, so we don't do it
    return (thumb[len(root):], orientation)