fix statistics: media file sum

- exclude invalid episodes from counting
refactor statistics code