Skip to content

Commit

Permalink
Merge branch 'development' into dynaconf
Browse files Browse the repository at this point in the history
# Conflicts:
#	bazarr/app/config.py
#	bazarr/utilities/analytics.py
  • Loading branch information
morpheus65535 committed Sep 8, 2023
2 parents f2cce0a + af54c65 commit cb633d3
Show file tree
Hide file tree
Showing 34 changed files with 175 additions and 142 deletions.
5 changes: 2 additions & 3 deletions bazarr/api/badges/badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import ast

from functools import reduce
from flask_restx import Resource, Namespace, fields
from flask_restx import Resource, Namespace, fields, marshal

from app.database import get_exclusion_clause, TableEpisodes, TableShows, TableMovies, database, select
from app.get_providers import get_throttled_providers
Expand All @@ -31,7 +31,6 @@ class Badges(Resource):
})

@authenticate
@api_ns_badges.marshal_with(get_model, code=200)
@api_ns_badges.response(401, 'Not Authenticated')
@api_ns_badges.doc(parser=None)
def get(self):
Expand Down Expand Up @@ -74,4 +73,4 @@ def get(self):
'radarr_signalr': "LIVE" if radarr_signalr_client.connected else "",
'announcements': len(get_all_announcements()),
}
return result
return marshal(result, self.get_model)
11 changes: 5 additions & 6 deletions bazarr/api/episodes/blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pretty

from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal

from app.database import TableEpisodes, TableShows, TableBlacklist, database, select
from subtitles.tools.delete import delete_subtitles
Expand Down Expand Up @@ -39,7 +39,6 @@ class EpisodesBlacklist(Resource):
})

@authenticate
@api_ns_episodes_blacklist.marshal_with(get_response_model, envelope='data', code=200)
@api_ns_episodes_blacklist.response(401, 'Not Authenticated')
@api_ns_episodes_blacklist.doc(parser=get_request_parser)
def get(self):
Expand All @@ -63,7 +62,7 @@ def get(self):
if length > 0:
stmt = stmt.limit(length).offset(start)

return [postprocess({
return marshal([postprocess({
'seriesTitle': x.seriesTitle,
'episode_number': x.episode_number,
'episodeTitle': x.episodeTitle,
Expand All @@ -73,7 +72,7 @@ def get(self):
'language': x.language,
'timestamp': pretty.date(x.timestamp),
'parsed_timestamp': x.timestamp.strftime('%x %X')
}) for x in database.execute(stmt).all()]
}) for x in database.execute(stmt).all()], self.get_response_model, envelope='data')

post_request_parser = reqparse.RequestParser()
post_request_parser.add_argument('seriesid', type=int, required=True, help='Series ID')
Expand All @@ -88,7 +87,7 @@ def get(self):
@api_ns_episodes_blacklist.response(200, 'Success')
@api_ns_episodes_blacklist.response(401, 'Not Authenticated')
@api_ns_episodes_blacklist.response(404, 'Episode not found')
@api_ns_episodes_blacklist.response(410, 'Subtitles file not found or permission issue.')
@api_ns_episodes_blacklist.response(500, 'Subtitles file not found or permission issue.')
def post(self):
"""Add an episodes subtitles to blacklist"""
args = self.post_request_parser.parse_args()
Expand Down Expand Up @@ -126,7 +125,7 @@ def post(self):
event_stream(type='episode-history')
return '', 200
else:
return 'Subtitles file not found or permission issue.', 410
return 'Subtitles file not found or permission issue.', 500

delete_request_parser = reqparse.RequestParser()
delete_request_parser.add_argument('all', type=str, required=False, help='Empty episodes subtitles blacklist')
Expand Down
7 changes: 3 additions & 4 deletions bazarr/api/episodes/episodes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8

from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal

from app.database import TableEpisodes, database, select
from api.swaggerui import subtitles_model, subtitles_language_model, audio_language_model
Expand Down Expand Up @@ -37,7 +37,6 @@ class Episodes(Resource):
})

@authenticate
@api_ns_episodes.marshal_with(get_response_model, envelope='data', code=200)
@api_ns_episodes.doc(parser=get_request_parser)
@api_ns_episodes.response(200, 'Success')
@api_ns_episodes.response(401, 'Not Authenticated')
Expand Down Expand Up @@ -76,7 +75,7 @@ def get(self):
else:
return "Series or Episode ID not provided", 404

return [postprocess({
return marshal([postprocess({
'audio_language': x.audio_language,
'episode': x.episode,
'missing_subtitles': x.missing_subtitles,
Expand All @@ -88,4 +87,4 @@ def get(self):
'subtitles': x.subtitles,
'title': x.title,
'sceneName': x.sceneName,
}) for x in stmt_query]
}) for x in stmt_query], self.get_response_model, envelope='data')
15 changes: 8 additions & 7 deletions bazarr/api/episodes/episodes_subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EpisodesSubtitles(Resource):
@api_ns_episodes_subtitles.response(401, 'Not Authenticated')
@api_ns_episodes_subtitles.response(404, 'Episode not found')
@api_ns_episodes_subtitles.response(409, 'Unable to save subtitles file. Permission or path mapping issue?')
@api_ns_episodes_subtitles.response(410, 'Episode file not found. Path mapping issue?')
@api_ns_episodes_subtitles.response(500, 'Custom error messages')
def patch(self):
"""Download an episode subtitles"""
args = self.patch_request_parser.parse_args()
Expand All @@ -60,7 +60,7 @@ def patch(self):
episodePath = path_mappings.path_replace(episodeInfo.path)

if not os.path.exists(episodePath):
return 'Episode file not found. Path mapping issue?', 410
return 'Episode file not found. Path mapping issue?', 500

sceneName = episodeInfo.sceneName or "None"

Expand All @@ -79,13 +79,14 @@ def patch(self):
try:
result = list(generate_subtitles(episodePath, [(language, hi, forced)], audio_language, sceneName,
title, 'series', profile_id=get_profile_id(episode_id=sonarrEpisodeId)))
if result:
if isinstance(result, list) and len(result):
result = result[0]
history_log(1, sonarrSeriesId, sonarrEpisodeId, result)
send_notifications(sonarrSeriesId, sonarrEpisodeId, result.message)
store_subtitles(result.path, episodePath)
else:
event_stream(type='episode', payload=sonarrEpisodeId)
return 'No subtitles found', 500
except OSError:
return 'Unable to save subtitles file. Permission or path mapping issue?', 409
else:
Expand All @@ -106,7 +107,7 @@ def patch(self):
@api_ns_episodes_subtitles.response(401, 'Not Authenticated')
@api_ns_episodes_subtitles.response(404, 'Episode not found')
@api_ns_episodes_subtitles.response(409, 'Unable to save subtitles file. Permission or path mapping issue?')
@api_ns_episodes_subtitles.response(410, 'Episode file not found. Path mapping issue?')
@api_ns_episodes_subtitles.response(500, 'Episode file not found. Path mapping issue?')
def post(self):
"""Upload an episode subtitles"""
args = self.post_request_parser.parse_args()
Expand All @@ -124,7 +125,7 @@ def post(self):
episodePath = path_mappings.path_replace(episodeInfo.path)

if not os.path.exists(episodePath):
return 'Episode file not found. Path mapping issue?', 410
return 'Episode file not found. Path mapping issue?', 500

audio_language = get_audio_profile_languages(episodeInfo.audio_language)
if len(audio_language) and isinstance(audio_language[0], dict):
Expand Down Expand Up @@ -178,7 +179,7 @@ def post(self):
@api_ns_episodes_subtitles.response(204, 'Success')
@api_ns_episodes_subtitles.response(401, 'Not Authenticated')
@api_ns_episodes_subtitles.response(404, 'Episode not found')
@api_ns_episodes_subtitles.response(410, 'Subtitles file not found or permission issue.')
@api_ns_episodes_subtitles.response(500, 'Subtitles file not found or permission issue.')
def delete(self):
"""Delete an episode subtitles"""
args = self.delete_request_parser.parse_args()
Expand Down Expand Up @@ -211,4 +212,4 @@ def delete(self):
sonarr_episode_id=sonarrEpisodeId):
return '', 204
else:
return 'Subtitles file not found or permission issue.', 410
return 'Subtitles file not found or permission issue.', 500
5 changes: 2 additions & 3 deletions bazarr/api/episodes/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from subtitles.upgrade import get_upgradable_episode_subtitles, _language_still_desired

import pretty
from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal
from ..utils import authenticate, postprocess

api_ns_episodes_history = Namespace('Episodes History', description='List episodes history events')
Expand Down Expand Up @@ -53,7 +53,6 @@ class EpisodesHistory(Resource):
})

@authenticate
@api_ns_episodes_history.marshal_with(get_response_model, code=200)
@api_ns_episodes_history.response(401, 'Not Authenticated')
@api_ns_episodes_history.doc(parser=get_request_parser)
def get(self):
Expand Down Expand Up @@ -176,4 +175,4 @@ def get(self):
.where(TableEpisodes.title.is_not(None))) \
.scalar()

return {'data': episode_history, 'total': count}
return marshal({'data': episode_history, 'total': count}, self.get_response_model)
5 changes: 2 additions & 3 deletions bazarr/api/episodes/wanted.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import operator

from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal
from functools import reduce

from app.database import get_exclusion_clause, TableEpisodes, TableShows, database, select, func
Expand Down Expand Up @@ -41,7 +41,6 @@ class EpisodesWanted(Resource):
})

@authenticate
@api_ns_episodes_wanted.marshal_with(get_response_model, code=200)
@api_ns_episodes_wanted.response(401, 'Not Authenticated')
@api_ns_episodes_wanted.doc(parser=get_request_parser)
def get(self):
Expand Down Expand Up @@ -96,4 +95,4 @@ def get(self):
.where(wanted_condition)) \
.scalar()

return {'data': results, 'total': count}
return marshal({'data': results, 'total': count}, self.get_response_model)
5 changes: 2 additions & 3 deletions bazarr/api/files/files.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8

from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal

from utilities.filesystem import browse_bazarr_filesystem

Expand All @@ -21,7 +21,6 @@ class BrowseBazarrFS(Resource):
})

@authenticate
@api_ns_files.marshal_with(get_response_model, code=200)
@api_ns_files.response(401, 'Not Authenticated')
@api_ns_files.doc(parser=get_request_parser)
def get(self):
Expand All @@ -37,4 +36,4 @@ def get(self):
return []
for item in result['directories']:
data.append({'name': item['name'], 'children': True, 'path': item['path']})
return data
return marshal(data, self.get_response_model)
5 changes: 2 additions & 3 deletions bazarr/api/files/files_radarr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8

from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal

from radarr.filesystem import browse_radarr_filesystem

Expand All @@ -22,7 +22,6 @@ class BrowseRadarrFS(Resource):
})

@authenticate
@api_ns_files_radarr.marshal_with(get_response_model, code=200)
@api_ns_files_radarr.response(401, 'Not Authenticated')
@api_ns_files_radarr.doc(parser=get_request_parser)
def get(self):
Expand All @@ -38,4 +37,4 @@ def get(self):
return []
for item in result['directories']:
data.append({'name': item['name'], 'children': True, 'path': item['path']})
return data
return marshal(data, self.get_response_model)
5 changes: 2 additions & 3 deletions bazarr/api/files/files_sonarr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding=utf-8

from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal

from sonarr.filesystem import browse_sonarr_filesystem

Expand All @@ -22,7 +22,6 @@ class BrowseSonarrFS(Resource):
})

@authenticate
@api_ns_files_sonarr.marshal_with(get_response_model, code=200)
@api_ns_files_sonarr.response(401, 'Not Authenticated')
@api_ns_files_sonarr.doc(parser=get_request_parser)
def get(self):
Expand All @@ -38,4 +37,4 @@ def get(self):
return []
for item in result['directories']:
data.append({'name': item['name'], 'children': True, 'path': item['path']})
return data
return marshal(data, self.get_response_model)
5 changes: 2 additions & 3 deletions bazarr/api/history/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import itertools

from dateutil import rrule
from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal
from functools import reduce

from app.database import TableHistory, TableHistoryMovie, database, select
Expand Down Expand Up @@ -41,7 +41,6 @@ class HistoryStats(Resource):
})

@authenticate
@api_ns_history_stats.marshal_with(get_response_model, code=200)
@api_ns_history_stats.response(401, 'Not Authenticated')
@api_ns_history_stats.doc(parser=get_request_parser)
def get(self):
Expand Down Expand Up @@ -121,4 +120,4 @@ def get(self):
sorted_data_series = sorted(data_series, key=lambda i: i['date'])
sorted_data_movies = sorted(data_movies, key=lambda i: i['date'])

return {'series': sorted_data_series, 'movies': sorted_data_movies}
return marshal({'series': sorted_data_series, 'movies': sorted_data_movies}, self.get_response_model)
11 changes: 5 additions & 6 deletions bazarr/api/movies/blacklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pretty

from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal

from app.database import TableMovies, TableBlacklistMovie, database, select
from subtitles.tools.delete import delete_subtitles
Expand Down Expand Up @@ -37,7 +37,6 @@ class MoviesBlacklist(Resource):
})

@authenticate
@api_ns_movies_blacklist.marshal_with(get_response_model, envelope='data', code=200)
@api_ns_movies_blacklist.response(401, 'Not Authenticated')
@api_ns_movies_blacklist.doc(parser=get_request_parser)
def get(self):
Expand All @@ -59,15 +58,15 @@ def get(self):
if length > 0:
data = data.limit(length).offset(start)

return [postprocess({
return marshal([postprocess({
'title': x.title,
'radarrId': x.radarrId,
'provider': x.provider,
'subs_id': x.subs_id,
'language': x.language,
'timestamp': pretty.date(x.timestamp),
'parsed_timestamp': x.timestamp.strftime('%x %X'),
}) for x in data.all()]
}) for x in data.all()], self.get_response_model, envelope='data')

post_request_parser = reqparse.RequestParser()
post_request_parser.add_argument('radarrid', type=int, required=True, help='Radarr ID')
Expand All @@ -81,7 +80,7 @@ def get(self):
@api_ns_movies_blacklist.response(200, 'Success')
@api_ns_movies_blacklist.response(401, 'Not Authenticated')
@api_ns_movies_blacklist.response(404, 'Movie not found')
@api_ns_movies_blacklist.response(410, 'Subtitles file not found or permission issue.')
@api_ns_movies_blacklist.response(500, 'Subtitles file not found or permission issue.')
def post(self):
"""Add a movies subtitles to blacklist"""
args = self.post_request_parser.parse_args()
Expand Down Expand Up @@ -119,7 +118,7 @@ def post(self):
event_stream(type='movie-history')
return '', 200
else:
return 'Subtitles file not found or permission issue.', 410
return 'Subtitles file not found or permission issue.', 500

delete_request_parser = reqparse.RequestParser()
delete_request_parser.add_argument('all', type=str, required=False, help='Empty movies subtitles blacklist')
Expand Down
5 changes: 2 additions & 3 deletions bazarr/api/movies/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pretty
import ast

from flask_restx import Resource, Namespace, reqparse, fields
from flask_restx import Resource, Namespace, reqparse, fields, marshal
from functools import reduce

from app.database import TableMovies, TableHistoryMovie, TableBlacklistMovie, database, select, func
Expand Down Expand Up @@ -52,7 +52,6 @@ class MoviesHistory(Resource):
})

@authenticate
@api_ns_movies_history.marshal_with(get_response_model, code=200)
@api_ns_movies_history.response(401, 'Not Authenticated')
@api_ns_movies_history.doc(parser=get_request_parser)
def get(self):
Expand Down Expand Up @@ -167,4 +166,4 @@ def get(self):
.where(TableMovies.title.is_not(None))) \
.scalar()

return {'data': movie_history, 'total': count}
return marshal({'data': movie_history, 'total': count}, self.get_response_model)
Loading

0 comments on commit cb633d3

Please sign in to comment.