# Build missing subtitles clause depending on only_monitored
missing_subtitles_clause=[
(TableShows.languages!='None'),
(TableEpisodes.missing_subtitles!='[]')
]
ifsettings.sonarr.getboolean('only_monitored'):
monitored_only_query_string=' AND monitored = "True"'
else:
monitored_only_query_string=""
c.execute(
"SELECT tvdbId, title, path_substitution(path), languages, hearing_impaired, sonarrSeriesId, poster, audio_language, forced FROM table_shows ORDER BY sortTitle ASC LIMIT ? OFFSET ?",
(page_size,offset,))
data=c.fetchall()
c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1")
languages=c.fetchall()
c.execute(
"SELECT table_shows.sonarrSeriesId, COUNT(table_episodes.missing_subtitles) FROM table_shows LEFT JOIN table_episodes ON table_shows.sonarrSeriesId=table_episodes.sonarrSeriesId WHERE table_shows.languages IS NOT 'None' AND table_episodes.missing_subtitles IS NOT '[]'"+monitored_only_query_string+" GROUP BY table_shows.sonarrSeriesId")
missing_subtitles_list=c.fetchall()
c.execute(
"SELECT table_shows.sonarrSeriesId, COUNT(table_episodes.missing_subtitles) FROM table_shows LEFT JOIN table_episodes ON table_shows.sonarrSeriesId=table_episodes.sonarrSeriesId WHERE table_shows.languages IS NOT 'None'"+monitored_only_query_string+" GROUP BY table_shows.sonarrSeriesId")