From 8fba73e3fbed0ee7f86add04e4de60494ff75212 Mon Sep 17 00:00:00 2001 From: phyzical <5182053+phyzical@users.noreply.github.com> Date: Sat, 23 Sep 2023 12:24:27 +0800 Subject: [PATCH 1/7] Exposes the file_size of subtitles to api --- bazarr/api/swaggerui.py | 3 ++- bazarr/api/utils.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bazarr/api/swaggerui.py b/bazarr/api/swaggerui.py index b225f1532..13c4c4a5f 100644 --- a/bazarr/api/swaggerui.py +++ b/bazarr/api/swaggerui.py @@ -15,7 +15,8 @@ "code3": fields.String(), "path": fields.String(), "forced": fields.Boolean(), - "hi": fields.Boolean() + "hi": fields.Boolean(), + "file_size": fields.Integer(), } subtitles_language_model = { diff --git a/bazarr/api/utils.py b/bazarr/api/utils.py index 5f47b40b7..fe65ff712 100644 --- a/bazarr/api/utils.py +++ b/bazarr/api/utils.py @@ -67,7 +67,8 @@ def postprocess(item): "code2": language[0], "code3": alpha3_from_alpha2(language[0]), "forced": False, - "hi": False} + "hi": False, + "file_size": subs[2]} if len(language) > 1: item['subtitles'][i].update( { From 19ea2c35d7edd028bd439894223706632a73f016 Mon Sep 17 00:00:00 2001 From: phyzical <5182053+phyzical@users.noreply.github.com> Date: Sat, 23 Sep 2023 12:24:59 +0800 Subject: [PATCH 2/7] add an api alias for /v1 --- bazarr/app/server.py | 1 + libs/flask_restx/api.py | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bazarr/app/server.py b/bazarr/app/server.py index c9d14bd31..d2fe9368e 100644 --- a/bazarr/app/server.py +++ b/bazarr/app/server.py @@ -18,6 +18,7 @@ app = create_app() ui_bp.register_blueprint(api_bp, url_prefix='/api') +ui_bp.register_blueprint(api_bp, url_prefix='/api/v1', name="api_alias") # Mute UserWarning with flask-restx and Flask >= 2.2.0. Will be raised as an exception in 2.3.0 # https://github.com/python-restx/flask-restx/issues/485 warnings.filterwarnings('ignore', message='The setup method ') diff --git a/libs/flask_restx/api.py b/libs/flask_restx/api.py index 450cbaa9a..11dd8c688 100644 --- a/libs/flask_restx/api.py +++ b/libs/flask_restx/api.py @@ -873,9 +873,13 @@ def _deferred_blueprint_init(self, setup_state): setup_state.add_url_rule = MethodType( Api._blueprint_setup_add_url_rule_patch, setup_state ) - if not setup_state.first_registration: - raise ValueError("flask-restx blueprints can only be registered once.") - self._init_app(setup_state.app) + + # https://github.com/flask-restful/flask-restful/issues/509 + # if not setup_state.first_registration: + # raise ValueError("flask-restx blueprints can only be registered once.") + # self._init_app(setup_state.app) + if setup_state.first_registration: + self._init_app(setup_state.app) def mediatypes_method(self): """Return a method that returns a list of mediatypes""" From e7bad544479496b597a61caf40caa5a7d891b64a Mon Sep 17 00:00:00 2001 From: phyzical <5182053+phyzical@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:39:53 +0800 Subject: [PATCH 3/7] revert api update --- libs/flask_restx/api.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libs/flask_restx/api.py b/libs/flask_restx/api.py index 11dd8c688..67bee66d3 100644 --- a/libs/flask_restx/api.py +++ b/libs/flask_restx/api.py @@ -874,12 +874,9 @@ def _deferred_blueprint_init(self, setup_state): Api._blueprint_setup_add_url_rule_patch, setup_state ) - # https://github.com/flask-restful/flask-restful/issues/509 - # if not setup_state.first_registration: - # raise ValueError("flask-restx blueprints can only be registered once.") - # self._init_app(setup_state.app) - if setup_state.first_registration: - self._init_app(setup_state.app) + if not setup_state.first_registration: + raise ValueError("flask-restx blueprints can only be registered once.") + self._init_app(setup_state.app) def mediatypes_method(self): """Return a method that returns a list of mediatypes""" From 0e6ff32f264ec7dc7efee57a95d7a95aefed9511 Mon Sep 17 00:00:00 2001 From: Jack <5182053+phyzical@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:40:44 +0800 Subject: [PATCH 4/7] Update libs/flask_restx/api.py --- libs/flask_restx/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/flask_restx/api.py b/libs/flask_restx/api.py index 67bee66d3..450cbaa9a 100644 --- a/libs/flask_restx/api.py +++ b/libs/flask_restx/api.py @@ -873,7 +873,6 @@ def _deferred_blueprint_init(self, setup_state): setup_state.add_url_rule = MethodType( Api._blueprint_setup_add_url_rule_patch, setup_state ) - if not setup_state.first_registration: raise ValueError("flask-restx blueprints can only be registered once.") self._init_app(setup_state.app) From 72b094554ea6759d6077037255d58e83a920bbda Mon Sep 17 00:00:00 2001 From: Jack <5182053+phyzical@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:40:49 +0800 Subject: [PATCH 5/7] Update bazarr/app/server.py --- bazarr/app/server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bazarr/app/server.py b/bazarr/app/server.py index d2fe9368e..c9d14bd31 100644 --- a/bazarr/app/server.py +++ b/bazarr/app/server.py @@ -18,7 +18,6 @@ app = create_app() ui_bp.register_blueprint(api_bp, url_prefix='/api') -ui_bp.register_blueprint(api_bp, url_prefix='/api/v1', name="api_alias") # Mute UserWarning with flask-restx and Flask >= 2.2.0. Will be raised as an exception in 2.3.0 # https://github.com/python-restx/flask-restx/issues/485 warnings.filterwarnings('ignore', message='The setup method ') From 70687584f4ff78a8562db5bf489351ed40ee5025 Mon Sep 17 00:00:00 2001 From: Jack <5182053+phyzical@users.noreply.github.com> Date: Tue, 10 Oct 2023 10:04:12 +0800 Subject: [PATCH 6/7] Update utils.py Add a safer check, default to 0 size --- bazarr/api/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bazarr/api/utils.py b/bazarr/api/utils.py index fe65ff712..a61d50527 100644 --- a/bazarr/api/utils.py +++ b/bazarr/api/utils.py @@ -62,13 +62,14 @@ def postprocess(item): item['subtitles'] = ast.literal_eval(item['subtitles']) for i, subs in enumerate(item['subtitles']): language = subs[0].split(':') + file_size = subs[2] if len(subs) > 2 else 0 item['subtitles'][i] = {"path": path_replace(subs[1]), "name": language_from_alpha2(language[0]), "code2": language[0], "code3": alpha3_from_alpha2(language[0]), "forced": False, "hi": False, - "file_size": subs[2]} + "file_size": file_size} if len(language) > 1: item['subtitles'][i].update( { From dcd24050a44283495d4f404aabae99c084e7ce95 Mon Sep 17 00:00:00 2001 From: Jack <5182053+phyzical@users.noreply.github.com> Date: Tue, 10 Oct 2023 10:04:25 +0800 Subject: [PATCH 7/7] Update bazarr/api/swaggerui.py --- bazarr/api/swaggerui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazarr/api/swaggerui.py b/bazarr/api/swaggerui.py index 13c4c4a5f..e8eb979a2 100644 --- a/bazarr/api/swaggerui.py +++ b/bazarr/api/swaggerui.py @@ -16,7 +16,7 @@ "path": fields.String(), "forced": fields.Boolean(), "hi": fields.Boolean(), - "file_size": fields.Integer(), + "file_size": fields.Integer() } subtitles_language_model = {