diff --git a/bazarr/api.py b/bazarr/api.py index 5e6873ead..08d81cf51 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -2014,10 +2014,16 @@ class SubtitleNameInfo(Resource): if 'subtitle_language' in guessit_result: result['subtitle_language'] = str(guessit_result['subtitle_language']) + result['episode'] = 0 if 'episode' in guessit_result: - result['episode'] = int(guessit_result['episode']) - else: - result['episode'] = 0 + if isinstance(guessit_result['episode'], list): + # for multiple episodes file, choose the first episode number + if len(guessit_result['episode']): + # make sure that guessit returned a list of more than 0 items + result['episode'] = int(guessit_result['episode'][0]) + elif isinstance(guessit_result['episode'], (str, int)): + # if single episode (should be int but just in case we cast it to int) + result['episode'] = int(guessit_result['episode']) if 'season' in guessit_result: result['season'] = int(guessit_result['season'])