Skip to content

Commit 41cf727

Browse files
committed
keep user-metadata intact when reloading
1 parent d06eed7 commit 41cf727

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

castero/database.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,16 @@ def reload(self, display=None) -> None:
226226
else:
227227
new_feed = Feed(file=feed.key)
228228

229+
# keep user metadata for episodes intact
230+
new_episodes = new_feed.parse_episodes()
231+
old_episodes = self.episodes(feed)
232+
for new_ep in new_episodes:
233+
matching_olds = [old_ep for old_ep in old_episodes if old_ep.title == new_ep.title]
234+
if len(matching_olds) == 1:
235+
new_ep.replace_from(matching_olds[0])
236+
229237
self.replace_feed(new_feed)
230-
self.replace_episodes(new_feed, new_feed.parse_episodes())
238+
self.replace_episodes(new_feed, new_episodes)
231239

232240
if display is not None:
233241
display.change_status("Feeds successfully reloaded")

castero/episode.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ def check_downloaded(self) -> bool:
170170
self._downloaded = True
171171
return self._downloaded
172172

173+
def replace_from(self, episode) -> None:
174+
"""Replace user-specific metadata from the given episode.
175+
176+
Args:
177+
episode: the source Episode
178+
"""
179+
self._played = episode._played
180+
173181
@property
174182
def downloaded(self) -> bool:
175183
"""Determines whether the episode is downloaded.

0 commit comments

Comments
 (0)