コード例 #1
0
ファイル: api.py プロジェクト: Janakas/MediaCrush
def _file_entry(f, mimetype=None):
    return {
        'type': mimetype if mimetype else get_mimetype(f),
        'file':
        media_url(f, absolute=False),  # This silliness will be fixed in API 2
        'url': media_url(f)
    }
コード例 #2
0
ファイル: api.py プロジェクト: nerdzeu/NERDZCrush
def _file_entry(f, mimetype=None):
    return {
        "type": mimetype if mimetype else get_mimetype(f),
        "file":
        media_url(f, absolute=False),  # This silliness will be fixed in API 2
        "url": media_url(f),
    }
コード例 #3
0
ファイル: media.py プロジェクト: Thapelo-Tsotetsi/MediaCrush
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"),
    }
コード例 #4
0
ファイル: media.py プロジェクト: hihihippp/MediaCrush
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"),
    }
コード例 #5
0
ファイル: media.py プロジェクト: nerdzeu/NERDZCrush
    def _send_file(self, id, base=_cfg("storage_folder"), as_attachment=False):
        if ".." in id or id.startswith("/"):
            abort(403)

        if "." in id:
            path = os.path.join(base, id)
            if os.path.exists(path):
                return send_file(path, as_attachment=as_attachment, mimetype=get_mimetype(path))
            else:
                return abort(404)

        return False
コード例 #6
0
ファイル: media.py プロジェクト: nerdzeu/NERDZCrush
    def _send_file(self, id, base=_cfg("storage_folder"), as_attachment=False):
        if ".." in id or id.startswith("/"):
            abort(403)

        if "." in id:
            path = os.path.join(base, id)
            if os.path.exists(path):
                return send_file(path,
                                 as_attachment=as_attachment,
                                 mimetype=get_mimetype(path))
            else:
                return abort(404)

        return False
コード例 #7
0
ファイル: media.py プロジェクト: dioptre/MediaCrush
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"),
    }
コード例 #8
0
ファイル: media.py プロジェクト: SCORE42/MediaCrush
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"),
    }
コード例 #9
0
ファイル: api.py プロジェクト: mpmedia/MediaCrush
def _file_entry(f, mimetype=None):
    return {
        'type': mimetype if mimetype else get_mimetype(f),
        'file': media_url(f, absolute=False), # This silliness will be fixed in API 2
        'url': media_url(f)
    }
コード例 #10
0
ファイル: api.py プロジェクト: Web5design/MediaCrush
def _file_entry(f, mimetype=None):
    return {
        'type': mimetype if mimetype else get_mimetype(f),
        'file': media_url(f),
    }
コード例 #11
0
 def test_get_mimetype(self):
     self.assertEqual(get_mimetype("blah.mp4"), "video/mp4")
コード例 #12
0
ファイル: api.py プロジェクト: dioptre/MediaCrush
def _file_entry(f, mimetype=None):
    return {
        'type': mimetype if mimetype else get_mimetype(f),
        'file': media_url(f),
        'url': _cfg("cdn") + media_url(f)
    }
コード例 #13
0
ファイル: api.py プロジェクト: blha303/MediaCrush
def _file_entry(f, mimetype=None):
    return {
        'type': mimetype if mimetype else get_mimetype(f),
        'file': media_url(f),
        'url': _cfg("cdn") + media_url(f)
    }
コード例 #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
ファイル: media.py プロジェクト: nerdzeu/NERDZCrush
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,
    }