diff --git a/command.py b/command.py index dcf4da3..ecc451f 100644 --- a/command.py +++ b/command.py @@ -199,17 +199,14 @@ def cmd_play(bot, user, text, command, parameter): index = int(params[0]) else: bot.send_msg(constants.strings('invalid_index', index=parameter), text) + return if len(params) > 1: - _start_at = params[1] - match = re.search("(?:(\d\d):)?(?:(\d\d):)?(\d\d(?:\.\d*)?)", _start_at, flags=re.IGNORECASE) - if match: - if match[1] is None and match[2] is None: - start_at = float(match[3]) - elif match[2] is None: - start_at = float(match[3]) + 60 * int(match[1]) - else: - start_at = float(match[3]) + 60 * int(match[2]) + 3600 * int(match[2]) + try: + start_at = util.parse_time(params[1]) + except ValueError: + bot.send_msg(constants.strings('bad_parameter', command=command), text) + return if len(var.playlist) > 0: if index != -1: diff --git a/configuration.default.ini b/configuration.default.ini index 1da9495..909991a 100644 --- a/configuration.default.ini +++ b/configuration.default.ini @@ -104,6 +104,9 @@ access_address = http://127.0.0.1:8181 flask_secret = ChangeThisPassword +upload_enabled = True +maximum_upload_file_size = 30M + [debug] # Set ffmpeg to True if you want to display DEBUG level log of ffmpeg. ffmpeg = False diff --git a/configuration.example.ini b/configuration.example.ini index 1e4a480..1062771 100644 --- a/configuration.example.ini +++ b/configuration.example.ini @@ -140,6 +140,11 @@ port = 64738 # !! YOU NEED TO CHANGE IT IF auth_method IS 'token'!! # flask_secret = ChangeThisPassword +# 'upload_enabled': Enable the upload function of the web interface. +# 'maximum_upload_file_size': Unit can be 'B', 'KB', 'MB', 'GB', 'TB'. +#upload_enabled = True +#maximum_upload_file_size = 30MB + # [debug] stores some debug settings. [debug] # 'ffmpeg': Set ffmpeg to True if you want to display DEBUG level log of ffmpeg. diff --git a/interface.py b/interface.py index 3eb95a6..c1645c2 100644 --- a/interface.py +++ b/interface.py @@ -187,10 +187,13 @@ def index(): time.sleep(0.1) tags_color_lookup = build_tags_color_lookup() + max_upload_file_size = util.parse_file_size(var.config.get("webinterface", "max_upload_file_size", fallback="30MB")) return render_template('index.html', dirs=get_all_dirs(), + upload_enabled=var.config.getboolean("webinterface", "upload_enabled", fallback=True), tags_color_lookup=tags_color_lookup, + max_upload_file_size=max_upload_file_size ) @@ -614,6 +617,9 @@ def library(): def upload(): global log + if not var.config.getboolean("webinterface", "upload_enabled", fallback=True): + abort(403) + file = request.files['file'] if not file: abort(400) diff --git a/templates/index.html b/templates/index.html index f7ca1ab..a0f56ee 100644 --- a/templates/index.html +++ b/templates/index.html @@ -327,7 +327,7 @@ - +{% if upload_enabled %}
@@ -375,6 +375,8 @@
+{% endif %} +
@@ -543,7 +545,7 @@
- + diff --git a/util.py b/util.py index e072279..73fa741 100644 --- a/util.py +++ b/util.py @@ -353,6 +353,32 @@ def get_media_duration(path): return 0 +def parse_time(human): + match = re.search("(?:(\d\d):)?(?:(\d\d):)?(\d\d(?:\.\d*)?)", human, flags=re.IGNORECASE) + if match: + if match[1] is None and match[2] is None: + return float(match[3]) + elif match[2] is None: + return float(match[3]) + 60 * int(match[1]) + else: + return float(match[3]) + 60 * int(match[2]) + 3600 * int(match[2]) + else: + raise ValueError("Invalid time string given.") + + +def parse_file_size(human): + units = {"B": 1, "KB": 1024, "MB": 1024*1024, "GB": 1024*1024*1024, "TB": 1024*1024*1024*1024, + "K": 1024, "M": 1024*1024, "G": 1024*1024*1024, "T": 1024*1024*1024*1024} + match = re.search("(\d+(?:\.\d*)?)\s*([A-Za-z]+)", human, flags=re.IGNORECASE) + if match: + num = float(match[1]) + unit = match[2].upper() + if unit in units: + return int(num * units[unit]) + + raise ValueError("Invalid file size given.") + + class LoggerIOWrapper(io.TextIOWrapper): def __init__(self, logger: logging.Logger, logging_level, fallback_io_buffer): super().__init__(fallback_io_buffer, write_through=True)