def sortedEpisodes(m, season=None):
 episodes = []
 seasons = season
 if (season is None):
  seasons = sortedSeasons(m)
 elif (not isinstance(season, (tuple, list))):
  seasons = [season]
 for s in seasons:
  eps_indx = m.get('episodes', {}).get(s, {}).keys()
  eps_indx.sort()
  for e in eps_indx:
   episodes.append(m['episodes'][s][e])
 return episodes

def sortedEpisodes ( m , season = None ) : episodes = [ ] seasons = season if ( season is None ) : seasons = sortedSeasons ( m ) elif ( not isinstance ( season , ( tuple , list ) ) ) : seasons = [ season ] for s in seasons : eps_indx = m . get ( 'episodes' , { } ) . get ( s , { } ) . keys ( ) eps_indx . sort ( ) for e in eps_indx : episodes . append ( m [ 'episodes' ] [ s ] [ e ] ) return episodes
return a sorted list of episodes of the given series .