Browse files

fixed up the case for TV episodes where you have more than 1 file for…

… a given season/episode of a TV show
  • Loading branch information...
Jason Paryani
Jason Paryani committed Jul 26, 2012
1 parent ce2f2ec commit 533e31abc76c20ffcedcd162f83c8cddff678d2b
Showing with 6 additions and 2 deletions.
  1. +6 −2
@@ -147,8 +147,12 @@ def _fetch_episodes( self ):
self.episodes = []
for tvshow in self.tvshows:
lastplayed = ""
- for item in tvshow[5]:
- playcount = item['playcount']
+ episode_sorter = lambda item: (int(item['season']), int(item['episode']))
+ for key, group in itertools.groupby(sorted(tvshow[5], key=episode_sorter), episode_sorter):
+ playcount = 0
+ for item in sorted(group, key=lambda x: (x['lastplayed'], x['episodeid'])):
+ # sort first by lastplayed, so we're certain to always get the latest played item upon final iteration of the loop. Then sort by episodeid, mainly for the case where lastplayed is empty for all items, and we want the latest episodeid to be the one chosen (higher episodeid equals being added later to xbmc)
+ playcount += int(item['playcount'])
if playcount != 0:
# this episode has been watched, record play date (we need it for sorting the final list) and continue to next episode
lastplayed = item['lastplayed']

0 comments on commit 533e31a

Please sign in to comment.