Skip to content

Commit b7aa5a1

Browse files
committed
Added absolute episode number to the database to help properly match video to subtitles. It must be implemented in each provider's matching method to benefit from that.
1 parent f0ae7d6 commit b7aa5a1

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

bazarr/app/database.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class TableBlacklistMovie(Base):
152152
class TableEpisodes(Base):
153153
__tablename__ = 'table_episodes'
154154

155+
absoluteEpisode = mapped_column(Integer)
155156
audio_codec = mapped_column(Text)
156157
audio_language = mapped_column(Text)
157158
created_at_timestamp = mapped_column(DateTime)

bazarr/sonarr/sync/parser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,5 @@ def episodeParser(episode):
182182
'audio_codec': audioCodec,
183183
'episode_file_id': episode['episodeFile']['id'],
184184
'audio_language': str(audio_language),
185-
'file_size': episode['episodeFile']['size']}
185+
'file_size': episode['episodeFile']['size'],
186+
'absoluteEpisode': episode.get('absoluteEpisodeNumber')}

bazarr/subtitles/refiners/database.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def refine_from_db(path, video):
3232
TableEpisodes.path,
3333
TableShows.imdbId,
3434
TableEpisodes.sonarrSeriesId,
35-
TableEpisodes.sonarrEpisodeId)
35+
TableEpisodes.sonarrEpisodeId,
36+
TableEpisodes.absoluteEpisode)
3637
.select_from(TableEpisodes)
3738
.join(TableShows)
3839
.where((TableEpisodes.path == path_mappings.path_replace_reverse(path)))) \
@@ -42,6 +43,7 @@ def refine_from_db(path, video):
4243
video.series = _TITLE_RE.sub('', data.seriesTitle)
4344
video.season = int(data.season)
4445
video.episode = int(data.episode)
46+
video.absolute_episode = int(data.absoluteEpisode) if data.absoluteEpisode else None
4547
video.title = data.episodeTitle
4648

4749
# Only refine year as a fallback
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""empty message
2+
3+
Revision ID: df76a4410347
4+
Revises: 4274a5dfc4ad
5+
Create Date: 2025-11-19 07:36:46.102169
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'df76a4410347'
14+
down_revision = '4274a5dfc4ad'
15+
branch_labels = None
16+
depends_on = None
17+
18+
bind = op.get_context().bind
19+
insp = sa.inspect(bind)
20+
21+
22+
def column_exists(table_name, column_name):
23+
columns = insp.get_columns(table_name)
24+
return any(c["name"] == column_name for c in columns)
25+
26+
27+
def upgrade():
28+
# ### commands auto generated by Alembic - please adjust! ###
29+
if not column_exists('table_episodes', 'absoluteEpisode'):
30+
with op.batch_alter_table('table_episodes', schema=None) as batch_op:
31+
batch_op.add_column(sa.Column('absoluteEpisode', sa.INT(), nullable=True))
32+
# ### end Alembic commands ###
33+
34+
35+
def downgrade():
36+
pass

0 commit comments

Comments
 (0)