Пример #1
0
def compression_rate(originalpath, f):
    if f.processor == "default":
        return 0
    processor = get_processor(f.processor)

    original_size = os.path.getsize(originalpath)
    minsize = min(original_size, original_size)
    for ext in processor.outputs:
        try:
            convsize = os.path.getsize(file_storage("%s.%s" % (f.hash, ext)))
            print(("%s: %s (%s)" % (ext, convsize, original_size)))
            minsize = min(minsize, convsize)
        except OSError:
            continue  # One of the target files wasn't processed.
            # This will fail later in the processing workflow.

    # Cross-multiplication:
    # Original size   1
    # ------------- = -
    # Min size        x

    x = minsize / float(original_size)

    # Compression rate: 1/x
    return round(1 / x, 2)
Пример #2
0
def _file_object(f):
    mimetype = f.mimetype
    processor = get_processor(f.processor)

    metadata = {}
    if f.metadata and f.metadata != 'None':
        metadata = json.loads(f.metadata)
    ret = {
        'original': media_url(f.original, absolute=False),
        'type': mimetype,
        'blob_type': normalise_processor(f.processor),
        'hash': f.hash,
        'files': [],
        'extras': [],
        'metadata': metadata,
        'flags': f.flags.as_dict(),
        'title': f.title,
        'description': f.description,
    }
    if f.compression:
        ret['compression'] = float(f.compression)

    ret['files'].append(_file_entry(f.original, mimetype=f.mimetype))

    for f_ext in processor.outputs:
        name = "%s.%s" % (f.hash, f_ext)
        if name == f.original:
            continue

        ret['files'].append(_file_entry(name))
    for f_ext in processor.extras:
        ret['extras'].append(_file_entry("%s.%s" % (f.hash, f_ext)))

    return ret
Пример #3
0
def _file_object(f):
    mimetype = f.mimetype
    processor = get_processor(f.processor)

    metadata = {}
    if f.metadata and f.metadata != 'None':
        metadata = json.loads(f.metadata)
    ret = {
        'original': media_url(f.original, absolute=False),
        'type': mimetype,
        'blob_type': normalise_processor(f.processor),
        'hash': f.hash,
        'files': [],
        'extras': [],
        'metadata': metadata,
        'flags': f.flags.as_dict(),
        'title': f.title,
        'description': f.description,
    }
    if f.compression:
        ret['compression'] = float(f.compression)

    ret['files'].append(_file_entry(f.original, mimetype=f.mimetype))

    for f_ext in processor.outputs:
        name = "%s.%s" % (f.hash, f_ext)
        if name == f.original:
            continue

        ret['files'].append(_file_entry(name))
    for f_ext in processor.extras:
        ret['extras'].append(_file_entry("%s.%s" % (f.hash, f_ext)))

    return ret
Пример #4
0
def _file_object(f):
    mimetype = f.mimetype
    processor = get_processor(f.processor)

    ret = {
        'original': media_url(f.original),
        'type': mimetype,
        'blob_type': normalise_processor(f.processor),
        'hash': f.hash,
        'files': [],
        'extras': [],
        'flags': f.flags.as_dict(),
    }
    if f.compression:
        ret['compression'] = float(f.compression)

    ret['files'].append(_file_entry(f.original, mimetype=f.mimetype))

    for f_ext in processor.outputs:
        name = "%s.%s" % (f.hash, f_ext)
        if name == f.original:
            continue

        ret['files'].append(_file_entry(name))
    for f_ext in processor.extras:
        ret['extras'].append(_file_entry("%s.%s" % (f.hash, f_ext)))

    return ret
Пример #5
0
def _file_object(f):
    mimetype = f.mimetype
    processor = get_processor(f.processor)

    metadata = {}
    if f.metadata and f.metadata != "None":
        metadata = json.loads(f.metadata)
    ret = {
        "original": media_url(f.original, absolute=False),
        "type": mimetype,
        "blob_type": normalise_processor(f.processor),
        "hash": f.hash,
        "files": [],
        "extras": [],
        "metadata": metadata,
        "flags": f.flags.as_dict(),
        "title": f.title,
        "description": f.description,
    }
    if f.compression:
        ret["compression"] = float(f.compression)

    ret["files"].append(_file_entry(f.original, mimetype=f.mimetype))

    for f_ext in processor.outputs:
        name = "%s.%s" % (f.hash, f_ext)
        if name == f.original:
            continue

        ret["files"].append(_file_entry(name))
    for f_ext in processor.extras:
        ret["extras"].append(_file_entry("%s.%s" % (f.hash, f_ext)))

    return ret
Пример #6
0
def _template_params(f):
    if f.compression:
        compression = int(float(f.compression) * 100)
    if compression == 100 or f.status != "done":
        compression = None

    can_delete = None
    try:
        if request.cookies.get('hist-opt-out', '0') == '1':
            can_delete = check_password_hash(f.ip, get_ip())
    except:
        pass

    mimetype = f.mimetype
    processor = get_processor(f.processor)

    types = [mimetype]
    for f_ext in processor.outputs:
        types.append(get_mimetype(f_ext))

    if 'do-not-send' in request.cookies:
        try:
            blacklist = json.loads(request.cookies['do-not-send'])
            for t in blacklist:
                if t in types:
                    types.remove(t)
        except:
            pass
    metadata = {}
    if f.metadata and f.metadata != 'null':
        metadata = json.loads(f.metadata)
    subtitles = None
    if 'subtitles' in metadata and 'streams' in metadata['subtitles']:
        for stream in metadata['subtitles']['streams']:
            if stream['type'] == 'subtitle':
                subtitles = stream
                if subtitles['info']['codec_name'] == 'ssa':
                    subtitles['info']['codec_name'] = 'ass'
                subtitles['url'] = '/' + f.hash + '.' + subtitles['info']['codec_name']
                break

    return {
        'filename': f.hash,
        'original': f.original,
        'video': normalise_processor(f.processor) == 'video',
        'flags': f.flags.as_dict(),
        'metadata': metadata,
        'subtitles': subtitles,
        'has_subtitles': subtitles != None,
        'compression': compression,
        'mimetype': mimetype,
        'can_delete': can_delete if can_delete is not None else 'check',
        'fragment': 'fragments/' + fragment(f.processor) + '.html',
        'types': types,
        'processor': f.processor,
        'protocol': _cfg("protocol"),
        'domain': _cfg("domain"),
    }
Пример #7
0
def _template_params(f):
    if f.compression:
        compression = int(float(f.compression) * 100)
    if compression == 100 or f.status != "done":
        compression = None

    can_delete = None
    try:
        if request.cookies.get("hist-opt-out", "0") == "1":
            can_delete = check_password_hash(f.ip, get_ip())
    except:
        pass

    mimetype = f.mimetype
    processor = get_processor(f.processor)

    types = [mimetype]
    for f_ext in processor.outputs:
        types.append(get_mimetype(f_ext))

    if "do-not-send" in request.cookies:
        try:
            blacklist = json.loads(request.cookies["do-not-send"])
            for t in blacklist:
                if t in types:
                    types.remove(t)
        except:
            pass
    metadata = {}
    if f.metadata and f.metadata != "null":
        metadata = json.loads(f.metadata)
    subtitles = None
    if "subtitles" in metadata and "streams" in metadata["subtitles"]:
        for stream in metadata["subtitles"]["streams"]:
            if stream["type"] == "subtitle":
                subtitles = stream
                if subtitles["info"]["codec_name"] == "ssa":
                    subtitles["info"]["codec_name"] = "ass"
                subtitles["url"] = "/" + f.hash + "." + subtitles["info"]["codec_name"]
                break

    return {
        "filename": f.hash,
        "original": f.original,
        "video": normalise_processor(f.processor) == "video",
        "flags": f.flags.as_dict(),
        "metadata": metadata,
        "subtitles": subtitles,
        "has_subtitles": subtitles != None,
        "compression": compression,
        "mimetype": mimetype,
        "can_delete": can_delete if can_delete is not None else "check",
        "fragment": "fragments/" + fragment(f.processor) + ".html",
        "types": types,
        "processor": f.processor,
        "protocol": _cfg("protocol"),
        "domain": _cfg("domain"),
    }
Пример #8
0
def delete_file(f):
    delete_file_storage(f.original)
    processor = get_processor(f.processor)

    if processor != 'default':
        extensions = processor.outputs
        if 'extras' in dir(processor):
            extensions += processor.extras

        for f_ext in extensions:
            delete_file_storage("%s.%s" % (f.hash, f_ext))

    f.delete()
Пример #9
0
def delete_file(f):
    delete_file_storage(f.original)
    processor = get_processor(f.processor)

    if processor != 'default':
        extensions = processor.outputs
        if 'extras' in dir(processor):
            extensions += processor.extras

        for f_ext in extensions:
            delete_file_storage("%s.%s" % (f.hash, f_ext))

    f.delete()
Пример #10
0
def _template_params(f):
    if f.compression:
        compression = int(float(f.compression) * 100)
    if compression == 100 or f.status != "done":
        compression = None

    can_delete = None
    try:
        if request.cookies.get('hist-opt-out', '0') == '1':
            can_delete = check_password_hash(f.ip, get_ip())
    except:
        pass

    mimetype = f.mimetype
    processor = get_processor(f.processor)

    types = [mimetype]
    for f_ext in processor.outputs:
        types.append(get_mimetype(f_ext))

    if 'do-not-send' in request.cookies:
        try:
            blacklist = json.loads(request.cookies['do-not-send'])
            for t in blacklist:
                if t in types:
                    types.remove(t)
        except:
            pass
    metadata = {}
    if f.metadata and f.metadata != 'None':
        metadata = json.loads(f.metadata)

    return {
        'filename': f.hash,
        'original': f.original,
        'video': normalise_processor(f.processor) == 'video',
        'flags': f.flags.as_dict(),
        'metadata': metadata,
        'compression': compression,
        'mimetype': mimetype,
        'can_delete': can_delete if can_delete is not None else 'check',
        'fragment': 'fragments/' + fragment(f.processor) + '.html',
        'types': types,
        'processor': f.processor,
        'protocol': _cfg("protocol"),
        'domain': _cfg("domain"),
    }
Пример #11
0
def _template_params(f):
    if f.compression:
        compression = int(float(f.compression) * 100)
    if compression == 100 or f.status != "done":
        compression = None

    can_delete = None
    try:
        if request.cookies.get('hist-opt-out', '0') == '1':
            can_delete = check_password_hash(f.ip, get_ip())
    except:
        pass

    mimetype = f.mimetype
    processor = get_processor(f.processor)

    types = [mimetype]
    for f_ext in processor.outputs:
        types.append(get_mimetype(f_ext))

    if 'do-not-send' in request.cookies:
        try:
            blacklist = json.loads(request.cookies['do-not-send'])
            for t in blacklist:
                if t in types:
                    types.remove(t)
        except:
            pass

    return {
        'filename': f.hash,
        'original': f.original,
        'video': mimetype in VIDEO_FORMATS,
        'loop': mimetype in LOOP_FORMATS,
        'autoplay': mimetype in AUTOPLAY_FORMATS,
        'compression': compression,
        'mimetype': mimetype,
        'can_delete': can_delete if can_delete is not None else 'check',
        'fragment': 'fragments/' + fragment(f.processor) + '.html',
        'types': types,
        'processor': f.processor,
        'protocol': _cfg("protocol"),
        'domain': _cfg("domain"),
    }
Пример #12
0
def _file_object(f):
    mimetype = f.mimetype
    processor = get_processor(f.processor)

    ret = {
        'original': media_url(f.original),
        'type': mimetype,
        'blob_type': f.processor.split('/')[0] if '/' in f.processor else f.processor,
        'hash': f.hash,
        'files': [],
        'extras': []
    }
    if f.compression:
        ret['compression'] = float(f.compression)

    ret['files'].append(_file_entry(f.original, mimetype=f.mimetype))

    for f_ext in processor.outputs:
        ret['files'].append(_file_entry("%s.%s" % (f.hash, f_ext)))
    for f_ext in processor.extras:
        ret['extras'].append(_file_entry("%s.%s" % (f.hash, f_ext)))

    return ret
Пример #13
0
def compression_rate(originalpath, f):
    if f.processor == 'default': return 0
    processor = get_processor(f.processor)

    original_size = os.path.getsize(originalpath)
    minsize = min(original_size, original_size)
    for ext in processor.outputs:
        try:
            convsize = os.path.getsize(file_storage("%s.%s" % (f.hash, ext)))
            print("%s: %s (%s)" % (ext, convsize, original_size))
            minsize = min(minsize, convsize)
        except OSError:
            continue # One of the target files wasn't processed.
                     # This will fail later in the processing workflow.

    # Cross-multiplication:
    # Original size   1
    # ------------- = -
    # Min size        x

    x = minsize / float(original_size)

    # Compression rate: 1/x
    return round(1/x, 2)
Пример #14
0
def _template_params(f):
    if f.compression:
        compression = int(float(f.compression) * 100)
    if compression == 100 or f.status != "done":
        compression = None

    can_delete = None
    try:
        if request.cookies.get('hist-opt-out', '0') == '1':
            can_delete = check_password_hash(f.ip, get_ip())
    except:
        pass

    mimetype = f.mimetype
    processor = get_processor(f.processor)

    types = [mimetype]
    for f_ext in processor.outputs:
        types.append(get_mimetype(f_ext))

    if 'do-not-send' in request.cookies:
        try:
            blacklist = json.loads(request.cookies['do-not-send'])
            for t in blacklist:
                if t in types:
                    types.remove(t)
        except:
            pass
    metadata = {}
    if f.metadata and f.metadata != 'null':
        try:
            metadata = json.loads(f.metadata)
        except:
            pass
    subtitles = None
    if 'subtitles' in metadata and 'streams' in metadata['subtitles']:
        for stream in metadata['subtitles']['streams']:
            if stream['type'] == 'subtitle':
                subtitles = stream
                if subtitles['info']['codec_name'] == 'ssa':
                    subtitles['info']['codec_name'] = 'ass'
                subtitles['url'] = '/' + f.hash + '.' + subtitles['info']['codec_name']
                break

    if f.description:
        f.description = slimdown.convert(f.description)

    return {
        'filename': f.hash,
        'original': f.original,
        'video': normalise_processor(f.processor) == 'video',
        'flags': f.flags.as_dict(),
        'metadata': metadata,
        'subtitles': subtitles,
        'has_subtitles': subtitles != None,
        'compression': compression,
        'mimetype': mimetype,
        'can_delete': can_delete if can_delete is not None else 'check',
        'fragment': 'fragments/' + fragment(f.processor) + '.html',
        'types': types,
        'processor': f.processor,
        'protocol': _cfg("protocol"),
        'domain': _cfg("domain"),
        'file': f
    }
Пример #15
0
def _template_params(f):
    if f.compression:
        compression = int(float(f.compression) * 100)
    if compression == 100 or f.status != "done":
        compression = None

    can_delete = None
    try:
        if request.cookies.get("hist-opt-out", "0") == "1":
            can_delete = check_password_hash(f.ip, get_ip())
    except:
        pass

    mimetype = f.mimetype
    processor = get_processor(f.processor)

    types = [mimetype]
    for f_ext in processor.outputs:
        types.append(get_mimetype(f_ext))

    if "do-not-send" in request.cookies:
        try:
            blacklist = json.loads(request.cookies["do-not-send"])
            for t in blacklist:
                if t in types:
                    types.remove(t)
        except:
            pass
    metadata = {}
    if f.metadata and f.metadata != "null":
        try:
            metadata = json.loads(f.metadata)
        except:
            pass
    subtitles = None
    if "subtitles" in metadata and "streams" in metadata["subtitles"]:
        for stream in metadata["subtitles"]["streams"]:
            if stream["type"] == "subtitle":
                subtitles = stream
                if subtitles["info"]["codec_name"] == "ssa":
                    subtitles["info"]["codec_name"] = "ass"
                subtitles["url"] = "/" + f.hash + "." + subtitles["info"][
                    "codec_name"]
                break

    if f.description:
        f.description = slimdown.convert(f.description)

    return {
        "filename": f.hash,
        "original": f.original,
        "video": normalise_processor(f.processor) == "video",
        "flags": f.flags.as_dict(),
        "metadata": metadata,
        "subtitles": subtitles,
        "has_subtitles": subtitles != None,
        "compression": compression,
        "mimetype": mimetype,
        "can_delete": can_delete if can_delete is not None else "check",
        "fragment": "fragments/" + fragment(f.processor) + ".html",
        "types": types,
        "processor": f.processor,
        "protocol": _cfg("protocol"),
        "domain": _cfg("domain"),
        "file": f,
    }