Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/ci.yml
  • Loading branch information
morpheus65535 committed Nov 28, 2023
2 parents a09cc34 + cb2023d commit 8282899
Show file tree
Hide file tree
Showing 209 changed files with 36,985 additions and 1,220 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/build_test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

python3 "${ROOT_DIRECTORY}"/bazarr.py &
python3 "${ROOT_DIRECTORY}"/bazarr.py --no-update &
PID=$!

sleep 30
Expand Down
28 changes: 3 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,8 @@ jobs:
Frontend:
runs-on: ubuntu-latest
steps:
- name: Get source branch name
uses: haya14busa/action-cond@v1
id: branch_ref
with:
cond: ${{ github.event_name == 'pull_request' }}
if_true: ${{ github.head_ref }}
if_false: ${{ github.ref_name }}

- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ steps.branch_ref.outputs.value }}
fetch-depth: 1
uses: actions/checkout@v4

- name: Cache node_modules
uses: actions/cache@v3
Expand Down Expand Up @@ -83,19 +72,8 @@ jobs:
needs: Frontend

steps:
- name: Get source branch name
uses: haya14busa/action-cond@v1
id: branch_ref
with:
cond: ${{ github.event_name == 'pull_request' }}
if_true: ${{ github.head_ref }}
if_false: ${{ github.ref_name }}

- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ steps.branch_ref.outputs.value }}
fetch-depth: 1
uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v4
Expand All @@ -113,7 +91,7 @@ jobs:

- name: Unit Tests
run: |
python3 bazarr.py &
python3 bazarr.py --no-update &
PID=$!
sleep 15
if kill -s 0 $PID
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_beta_to_dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
exit 1
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
ref: development
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release_dev_to_master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
exit 1
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: development
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Merge development -> master
uses: devmasx/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_bazarr_execution.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
exit 1
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
ref: development
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ If you need something that is not already part of Bazarr, feel free to create a
- Titulky.com
- TuSubtitulo
- TVSubtitles
- Whisper (requires [ahmetoner/whisper-asr-webservice](https://github.com/ahmetoner/whisper-asr-webservice))
- Wizdom
- XSubs
- Yavka.net
Expand Down
13 changes: 10 additions & 3 deletions bazarr/api/episodes/episodes_subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sonarr.history import history_log
from app.notifier import send_notifications
from subtitles.indexer.series import store_subtitles
from app.event_handler import event_stream
from app.event_handler import event_stream, show_message
from app.config import settings

from ..utils import authenticate
Expand Down Expand Up @@ -69,6 +69,12 @@ def patch(self):
language = args.get('language')
hi = args.get('hi').capitalize()
forced = args.get('forced').capitalize()
if hi == 'True':
language_str = f'{language}:hi'
elif forced == 'True':
language_str = f'{language}:forced'
else:
language_str = language

audio_language_list = get_audio_profile_languages(episodeInfo.audio_language)
if len(audio_language_list) > 0:
Expand All @@ -88,7 +94,8 @@ def patch(self):
store_subtitles(result.path, episodePath)
else:
event_stream(type='episode', payload=sonarrEpisodeId)
return 'No subtitles found', 500
show_message(f'No {language_str.upper()} subtitles found')
return '', 204
except OSError:
return 'Unable to save subtitles file. Permission or path mapping issue?', 409
else:
Expand Down Expand Up @@ -162,7 +169,7 @@ def post(self):
provider = "manual"
score = 360
history_log(4, sonarrSeriesId, sonarrEpisodeId, result, fake_provider=provider, fake_score=score)
if not settings.general.getboolean('dont_notify_manual_actions'):
if not settings.general.dont_notify_manual_actions:
send_notifications(sonarrSeriesId, sonarrEpisodeId, result.message)
store_subtitles(result.path, episodePath)
except OSError:
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/episodes/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get(self):
del item['external_subtitles']

if item['score']:
item['score'] = str(round((int(item['score']) * 100 / 360), 2)) + "%"
item['score'] = f"{round((int(item['score']) * 100 / 360), 2)}%"

# Make timestamp pretty
if item['timestamp']:
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/movies/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def get(self):
del item['external_subtitles']

if item['score']:
item['score'] = str(round((int(item['score']) * 100 / 120), 2)) + "%"
item['score'] = f"{round((int(item['score']) * 100 / 120), 2)}%"

# Make timestamp pretty
if item['timestamp']:
Expand Down
13 changes: 10 additions & 3 deletions bazarr/api/movies/movies_subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from radarr.history import history_log_movie
from app.notifier import send_notifications_movie
from subtitles.indexer.movies import store_subtitles_movie
from app.event_handler import event_stream
from app.event_handler import event_stream, show_message
from app.config import settings

from ..utils import authenticate
Expand Down Expand Up @@ -67,6 +67,12 @@ def patch(self):
language = args.get('language')
hi = args.get('hi').capitalize()
forced = args.get('forced').capitalize()
if hi == 'True':
language_str = f'{language}:hi'
elif forced == 'True':
language_str = f'{language}:forced'
else:
language_str = language

audio_language_list = get_audio_profile_languages(movieInfo.audio_language)
if len(audio_language_list) > 0:
Expand All @@ -85,7 +91,8 @@ def patch(self):
store_subtitles_movie(result.path, moviePath)
else:
event_stream(type='movie', payload=radarrId)
return 'No subtitles found', 500
show_message(f'No {language_str.upper()} subtitles found')
return '', 204
except OSError:
return 'Unable to save subtitles file. Permission or path mapping issue?', 409
else:
Expand Down Expand Up @@ -158,7 +165,7 @@ def post(self):
provider = "manual"
score = 120
history_log_movie(4, radarrId, result, fake_provider=provider, fake_score=score)
if not settings.general.getboolean('dont_notify_manual_actions'):
if not settings.general.dont_notify_manual_actions:
send_notifications_movie(radarrId, result.message)
store_subtitles_movie(result.path, moviePath)
except OSError:
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/providers/providers_episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def post(self):
result = result[0]
if isinstance(result, ProcessSubtitlesResult):
history_log(2, sonarrSeriesId, sonarrEpisodeId, result)
if not settings.general.getboolean('dont_notify_manual_actions'):
if not settings.general.dont_notify_manual_actions:
send_notifications(sonarrSeriesId, sonarrEpisodeId, result.message)
store_subtitles(result.path, episodePath)
elif isinstance(result, str):
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/providers/providers_movies.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def post(self):
result = result[0]
if isinstance(result, ProcessSubtitlesResult):
history_log_movie(2, radarrId, result)
if not settings.general.getboolean('dont_notify_manual_actions'):
if not settings.general.dont_notify_manual_actions:
send_notifications_movie(radarrId, result.message)
store_subtitles_movie(result.path, moviePath)
elif isinstance(result, str):
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/subtitles/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def patch(self):

# apply chmod if required
chmod = int(settings.general.chmod, 8) if not sys.platform.startswith(
'win') and settings.general.getboolean('chmod_enabled') else None
'win') and settings.general.chmod_enabled else None
if chmod:
os.chmod(subtitles_path, chmod)

Expand Down
4 changes: 2 additions & 2 deletions bazarr/api/system/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class SystemAccount(Resource):
@api_ns_system_account.response(400, 'Unknown action')
@api_ns_system_account.response(403, 'Authentication failed')
@api_ns_system_account.response(406, 'Browser must be closed to invalidate basic authentication')
@api_ns_system_account.response(500, 'Unknown authentication type define in config.ini')
@api_ns_system_account.response(500, 'Unknown authentication type define in config')
def post(self):
"""Login or logout from Bazarr UI when using form login"""
args = self.post_request_parser.parse_args()
if settings.auth.type != 'form':
return 'Unknown authentication type define in config.ini', 500
return 'Unknown authentication type define in config', 500

action = args.get('action')
if action == 'login':
Expand Down
3 changes: 2 additions & 1 deletion bazarr/api/system/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ def get(self):

except Exception:
logging.exception(
'BAZARR cannot parse releases caching file: ' + os.path.join(args.config_dir, 'config', 'releases.txt'))
f'BAZARR cannot parse releases caching file: '
f'{os.path.join(args.config_dir, "config", "releases.txt")}')
return marshal(filtered_releases, self.get_response_model, envelope='data')
4 changes: 2 additions & 2 deletions bazarr/api/system/searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get(self):
search_list = []

if query:
if settings.general.getboolean('use_sonarr'):
if settings.general.use_sonarr:
# Get matching series
search_list += database.execute(
select(TableShows.title,
Expand All @@ -36,7 +36,7 @@ def get(self):
.order_by(TableShows.title)) \
.all()

if settings.general.getboolean('use_radarr'):
if settings.general.use_radarr:
# Get matching movies
search_list += database.execute(
select(TableMovies.title,
Expand Down
27 changes: 18 additions & 9 deletions bazarr/api/system/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from flask import request, jsonify
from flask_restx import Resource, Namespace
from dynaconf.validator import ValidationError

from api.utils import None_Keys
from app.database import TableLanguagesProfiles, TableSettingsLanguages, TableSettingsNotifier, \
update_profile_id_list, database, insert, update, delete, select
from app.event_handler import event_stream
Expand Down Expand Up @@ -65,11 +67,12 @@ def post(self):
update(TableLanguagesProfiles)
.values(
name=item['name'],
cutoff=item['cutoff'] if item['cutoff'] != 'null' else None,
cutoff=item['cutoff'] if item['cutoff'] not in None_Keys else None,
items=json.dumps(item['items']),
mustContain=str(item['mustContain']),
mustNotContain=str(item['mustNotContain']),
originalFormat=item['originalFormat'] if item['originalFormat'] != 'null' else None,
originalFormat=int(item['originalFormat']) if item['originalFormat'] not in None_Keys else
None,
)
.where(TableLanguagesProfiles.profileId == item['profileId']))
existing.remove(item['profileId'])
Expand All @@ -80,11 +83,12 @@ def post(self):
.values(
profileId=item['profileId'],
name=item['name'],
cutoff=item['cutoff'] if item['cutoff'] != 'null' else None,
cutoff=item['cutoff'] if item['cutoff'] not in None_Keys else None,
items=json.dumps(item['items']),
mustContain=str(item['mustContain']),
mustNotContain=str(item['mustNotContain']),
originalFormat=item['originalFormat'] if item['originalFormat'] != 'null' else None,
originalFormat=int(item['originalFormat']) if item['originalFormat'] not in None_Keys else
None,
))
for profileId in existing:
# Remove deleted profiles
Expand All @@ -97,9 +101,9 @@ def post(self):

event_stream("languages")

if settings.general.getboolean('use_sonarr'):
if settings.general.use_sonarr:
scheduler.add_job(list_missing_subtitles, kwargs={'send_event': True})
if settings.general.getboolean('use_radarr'):
if settings.general.use_radarr:
scheduler.add_job(list_missing_subtitles_movies, kwargs={'send_event': True})

# Update Notification
Expand All @@ -112,6 +116,11 @@ def post(self):
url=item['url'])
.where(TableSettingsNotifier.name == item['name']))

save_settings(zip(request.form.keys(), request.form.listvalues()))
event_stream("settings")
return '', 204
try:
save_settings(zip(request.form.keys(), request.form.listvalues()))
except ValidationError as e:
event_stream("settings")
return e.message, 406
else:
event_stream("settings")
return '', 204
2 changes: 1 addition & 1 deletion bazarr/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def postprocess(item):
"hi": language[1] == 'hi',
}
)
if settings.general.getboolean('embedded_subs_show_desired') and item.get('profileId'):
if settings.general.embedded_subs_show_desired and item.get('profileId'):
desired_lang_list = get_desired_languages(item['profileId'])
item['subtitles'] = [x for x in item['subtitles'] if x['code2'] in desired_lang_list or x['path']]
item['subtitles'] = sorted(item['subtitles'], key=itemgetter('name', 'forced'))
Expand Down
2 changes: 1 addition & 1 deletion bazarr/api/webhooks/plex.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def post(self):
if media_type == 'episode':
try:
episode_imdb_id = [x['imdb'] for x in ids if 'imdb' in x][0]
r = requests.get('https://imdb.com/title/{}'.format(episode_imdb_id),
r = requests.get(f'https://imdb.com/title/{episode_imdb_id}',
headers={"User-Agent": os.environ["SZ_USER_AGENT"]})
soup = bso(r.content, "html.parser")
script_tag = soup.find(id='__NEXT_DATA__')
Expand Down
2 changes: 1 addition & 1 deletion bazarr/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create_app():
else:
app.config["DEBUG"] = False

socketio.init_app(app, path=base_url.rstrip('/')+'/api/socket.io', cors_allowed_origins='*',
socketio.init_app(app, path=f'{base_url.rstrip("/")}/api/socket.io', cors_allowed_origins='*',
async_mode='threading', allow_upgrades=False, transports='polling')

@app.errorhandler(404)
Expand Down
Loading

0 comments on commit 8282899

Please sign in to comment.