本文整理汇总了Python中mediacrush.config._cfg函数的典型用法代码示例。如果您正苦于以下问题:Python _cfg函数的具体用法?Python _cfg怎么用?Python _cfg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_cfg函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: media_url
def media_url(f, absolute=True):
f = shard(f)
cdn = _cfg("cdn")
domain = _cfg("domain")
base = _cfg("protocol") + "://" + domain if len(cdn) == 0 else cdn
return '%s/%s' % (base, f) if absolute else '/%s' % f
开发者ID:DiodeZ,项目名称:MediaCrush,代码行数:7,代码来源:files.py
示例2: cdn_url
def cdn_url(path):
request_domain = request.headers["Host"].strip()
path = shard(path)
if request_domain != _cfg("incoming_domain").strip():
return "/" + path
else:
return "%s/%s" % (_cfg("protocol") + "://" + _cfg("domain") if _cfg("cdn") == '' else _cfg("cdn"), path)
开发者ID:DiodeZ,项目名称:MediaCrush,代码行数:8,代码来源:paths.py
示例3: _send_file
def _send_file(self, id):
if ".." in id or id.startswith("/"):
abort(403)
if "." in id:
if os.path.exists(os.path.join(_cfg("storage_folder"), id)): # These requests are handled by nginx if it's set up
path = os.path.join(_cfg("storage_folder"), id)
return send_file(path, as_attachment=True)
开发者ID:FoleyDiver,项目名称:MediaCrush,代码行数:8,代码来源:media.py
示例4: _template_params
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"),
}
开发者ID:Thapelo-Tsotetsi,项目名称:MediaCrush,代码行数:58,代码来源:media.py
示例5: __init__
def __init__(self, tmppath, f, extra):
self.path = tmppath
self.output = os.path.join(_cfg("storage_folder"), f.hash)
self.extra = extra
self.important = True
self.f = f
开发者ID:Web5design,项目名称:MediaCrush,代码行数:8,代码来源:processor.py
示例6: delete_file_storage
def delete_file_storage(hash):
try:
for root, dirs, files in os.walk(_cfg("storage_folder")):
for f in files:
if f.startswith(hash):
try:
os.unlink(os.path.join(root, f))
except: pass # It's fine if one or more files are missing - it means that the processing pipeline might not have got to them.
except: pass
开发者ID:DiodeZ,项目名称:MediaCrush,代码行数:9,代码来源:fileutils.py
示例7: init
def init(args):
folder = _cfg("storage_folder")
sharding_level = _cfgi("sharding")
for i in range(64 ** sharding_level):
try:
os.mkdir(os.path.join(folder, int2base(i, 64)))
except OSError as e:
print(e)
开发者ID:Janakas,项目名称:MediaCrush,代码行数:9,代码来源:shard.py
示例8: __init__
def __init__(self, tmppath, f, processor_state, ignore_limit):
self.path = tmppath
self.output = os.path.join(_cfg("storage_folder"), f.hash)
self.processor_state = processor_state
self.ignore_limit = ignore_limit
self.important = True
self.f = f
开发者ID:FoleyDiver,项目名称:MediaCrush,代码行数:9,代码来源:processor.py
示例9: _template_params
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"),
}
开发者ID:SCORE42,项目名称:MediaCrush,代码行数:44,代码来源:media.py
示例10: prepare
def prepare():
if os.path.exists(app.static_folder):
rmtree(app.static_folder)
os.makedirs(app.static_folder)
compiler = scss.Scss(scss_opts = {
'style': 'compressed'
})
# Compile styles (scss)
d = os.walk('styles')
for f in list(d)[0][2]:
if extension(f) == "scss":
with open(os.path.join('styles', f)) as r:
output = compiler.compile(r.read())
parts = f.rsplit('.')
css = '.'.join(parts[:-1]) + ".css"
with open(os.path.join(app.static_folder, css), "w") as w:
w.write(output)
w.flush()
copy = ['images', 'scripts']
preprocess = ['scripts/view.js', 'scripts/mediacrush.js']
# Copy images, preprocess some JS files
for folder in copy:
for f in list(os.walk(folder))[0][2]:
outputpath = os.path.join(app.static_folder, os.path.basename(f))
inputpath = os.path.join(folder, f)
if inputpath in preprocess:
with open(inputpath) as r:
# Using Jinja here is overkill
output = r.read()
output = output.replace("{{ protocol }}", _cfg("protocol"))
output = output.replace("{{ domain }}", _cfg("domain"))
with open(outputpath, "w") as w:
w.write(output)
w.flush()
else:
copyfile(inputpath, outputpath)
开发者ID:SCORE42,项目名称:MediaCrush,代码行数:43,代码来源:app.py
示例11: get_maxsize
def get_maxsize():
size = _cfg("max_file_size")
symbols = ('B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
letter = size[-1:].strip().upper()
num = size[:-1]
assert num.isdigit() and letter in symbols
num = float(num)
prefix = {symbols[0]:1}
for i, size in enumerate(symbols[1:]):
prefix[size] = 1 << (i+1)*10
return int(num * prefix[letter])
开发者ID:DiodeZ,项目名称:MediaCrush,代码行数:11,代码来源:files.py
示例12: _send_file
def _send_file(self, id, base=_cfg("storage_folder")):
if ".." in id or id.startswith("/"):
abort(403)
if "." in id:
path = os.path.join(base, id)
if os.path.exists(path): # These requests are handled by nginx if it's set up
return send_file(path, as_attachment=True)
else:
return abort(404)
return False
开发者ID:Janakas,项目名称:MediaCrush,代码行数:12,代码来源:media.py
示例13: migrate
def migrate(args):
base = _cfg("storage_folder")
for f in os.listdir(base):
path = os.path.join(base, f)
if os.path.isfile(path):
newpath = os.path.join(base, shard(f))
try:
print("Moving " + path + " into " + newpath)
os.rename(path, newpath)
except:
print("Move failed")
开发者ID:Janakas,项目名称:MediaCrush,代码行数:12,代码来源:shard.py
示例14: _send_file
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
开发者ID:nerdzeu,项目名称:NERDZCrush,代码行数:12,代码来源:media.py
示例15: inject
def inject():
if is_tor():
cdn = _cfg("tor_domain")
ads = True
if 'ad-opt-out' in request.cookies:
ads = False
if g.do_not_track:
ads = False
if not _cfg("project_wonderful_id"):
ads = False
return {
'mobile': g.mobile,
'ua_platform': request.user_agent.platform,
'analytics_id': _cfg("google_analytics_id"),
'analytics_domain': _cfg("google_analytics_domain"),
'dwolla_id': _cfg("dwolla_id"),
'coinbase_id': _cfg("coinbase_id"),
'flattr_id': _cfg("flattr_id"),
'dark_theme': "dark_theme" in request.cookies,
'ads': ads,
'ad_id': _cfg("project_wonderful_id"),
'notice_text': notice_text,
'notice_enabled': notice_enabled,
'share': share,
'render_media': render_media,
'len': len,
'str': str,
'get_mimetype': get_mimetype,
'cdn_url': cdn_url,
'is_tor': is_tor(),
'ip': get_ip(),
'media_url': media_url,
'root': _cfg("protocol") + "://" + _cfg("domain"),
'random': random,
'shard': shard,
'max_file_size': get_maxsize()
}
开发者ID:DiodeZ,项目名称:MediaCrush,代码行数:38,代码来源:app.py
示例16: inject
def inject():
mobile = request.user_agent.platform in ['android', 'iphone', 'ipad']
return {
'mobile': mobile,
'analytics_id': _cfg("google_analytics_id"),
'analytics_domain': _cfg("google_analytics_domain"),
'dwolla_id': _cfg("dwolla_id"),
'coinbase_id': _cfg("coinbase_id"),
'flattr_id': _cfg("flattr_id"),
'adsense_client': _cfg("adsense_client"),
'adsense_slot': _cfg("adsense_slot")
}
开发者ID:AeonAxan,项目名称:MediaCrush,代码行数:12,代码来源:app.py
示例17: inject
def inject():
if is_tor():
cdn = _cfg("tor_domain")
ads = True
if "ad-opt-out" in request.cookies:
ads = False
if g.do_not_track:
ads = False
if not _cfg("project_wonderful_id"):
ads = False
return {
"mobile": g.mobile,
"ua_platform": request.user_agent.platform,
"analytics_id": _cfg("google_analytics_id"),
"analytics_domain": _cfg("google_analytics_domain"),
"dwolla_id": _cfg("dwolla_id"),
"coinbase_id": _cfg("coinbase_id"),
"flattr_id": _cfg("flattr_id"),
"dark_theme": "dark_theme" in request.cookies,
"ads": ads,
"ad_id": _cfg("project_wonderful_id"),
"notice_text": notice_text,
"notice_enabled": notice_enabled,
"share": share,
"render_media": render_media,
"len": len,
"str": str,
"get_mimetype": get_mimetype,
"cdn_url": cdn_url,
"is_tor": is_tor(),
"ip": get_ip(),
"media_url": media_url,
"root": _cfg("protocol") + "://" + _cfg("domain"),
"random": random,
"shard": shard,
"max_file_size": get_maxsize(),
}
开发者ID:zenny,项目名称:MediaCrush,代码行数:38,代码来源:app.py
示例18: download
def download(self, url):
r = requests.get(url, stream=True)
length = r.headers["content-length"]
if not length.isdigit() or int(length) > get_maxsize():
raise FileTooBig("The file was larger than "+_cfg("max_file_size"))
for i, chunk in enumerate(r.iter_content(chunk_size=1024)):
if i > get_maxsize() / 1024:
# Evil servers may send more than Content-Length bytes
# As of 54541a9, python-requests keeps reading indefinitely
raise FileTooBig("The file was larger than "+_cfg("max_file_size"))
self.f.write(chunk)
self.f.flush()
if r.status_code == 404:
return False
parsed_url = urlparse(url)
self.filename = list(reversed(parsed_url.path.split("/")))[0]
if "content-type" in r.headers:
self.content_type = r.headers['content-type']
ext = mimetypes.guess_extension(self.content_type)
if ext:
self.filename = self.filename + ext
if "content-disposition" in r.headers:
disposition = r.headers['content-disposition']
parts = disposition.split(';')
if len(parts) > 1:
self.filename = parts[1].strip(' ')
self.filename = self.filename[self.filename.find('=') + 1:].strip(' ')
self.filename = ''.join([c for c in self.filename if c.isalpha() or c == '.'])
return True
开发者ID:DiodeZ,项目名称:MediaCrush,代码行数:36,代码来源:files.py
示例19: inject
def inject():
return {
"mobile": g.mobile,
"analytics_id": _cfg("google_analytics_id"),
"analytics_domain": _cfg("google_analytics_domain"),
"dwolla_id": _cfg("dwolla_id"),
"coinbase_id": _cfg("coinbase_id"),
"flattr_id": _cfg("flattr_id"),
"adsense_client": _cfg("adsense_client"),
"adsense_slot": _cfg("adsense_slot"),
"dark_theme": "dark_theme" in request.cookies,
"ads": not "ad-opt-out" in request.cookies,
"share": share,
}
开发者ID:priestd09,项目名称:MediaCrush,代码行数:14,代码来源:app.py
示例20: inject
def inject():
return {
'mobile': g.mobile,
'analytics_id': _cfg("google_analytics_id"),
'analytics_domain': _cfg("google_analytics_domain"),
'dwolla_id': _cfg("dwolla_id"),
'coinbase_id': _cfg("coinbase_id"),
'flattr_id': _cfg("flattr_id"),
'adsense_client': _cfg("adsense_client"),
'adsense_slot': _cfg("adsense_slot"),
'dark_theme': "dark_theme" in request.cookies,
'ads': not "ad-opt-out" in request.cookies,
'notice_text': notice_text,
'notice_enabled': notice_enabled,
'share': share,
'render_media': render_media,
'type_files': type_files,
'len': len
}
开发者ID:RagingFlame,项目名称:MediaCrush,代码行数:19,代码来源:app.py
注:本文中的mediacrush.config._cfg函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论