<commit_before>import sqlite3
import sys, unicodedata, urlparse
import xbmc, xbmcgui, xbmcaddon, xbmcvfs, xbmcplugin


base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])

xbmcplugin.setContent(addon_handle, 'movies')

__addon__     = xbmcaddon.Addon()
__addonid__   = __addon__.getAddonInfo('id')
__addonname__ = __addon__.getAddonInfo('name')
__author__    = __addon__.getAddonInfo('author')
__version__   = __addon__.getAddonInfo('version')
__language__  = __addon__.getLocalizedString


def display_episode_list(seriesList):
  for series in seriesList:
    episode = series['episode']
    label = u"S%02dE%02d - %s (%s, %s)"%(int(series['season']), int(episode['number']), series['title'], episode['title'], episode['firstAired'])
    li = xbmcgui.ListItem(label, iconImage='DefaultFolder.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=base_url, listitem=li, isFolder=False)
  xbmcplugin.endOfDirectory(addon_handle)

def get_database_file():
  folder, files = xbmcvfs.listdir('special://database/')
  for file in files:
    if 'MyVideos' in file:
      return xbmc.translatePath('special://database/' + file)

def get_last_episode(conn, idShow, season):
  episodeQuery = 'SELECT MAX(CAST(c13 AS INTEGER)), c00, c05 FROM episodeview WHERE idShow = ? AND c12 = ?'
  cursor = conn.cursor()
  cursor.execute(episodeQuery, (idShow, season))
  episode = cursor.fetchone()
  return { 'number': episode[0], 'title': episode[1], 'firstAired': episode[2] }


def get_tv_show_list():
  tvshowQuery = 'SELECT idShow, strTitle, MAX(CAST(c12 AS INTEGER)) FROM episodeview GROUP BY idShow ORDER BY strTitle'
  conn = sqlite3.connect(get_database_file())
  cursor = conn.cursor()
  tvshows = cursor.execute(tvshowQuery)

  episodeList = []
  for tvshow in tvshows:
    episodeList.append({ 'title': tvshow[1], 'season': tvshow[2], 'episode': get_last_episode(conn, tvshow[0], tvshow[2]) })
  return episodeList

displayEpisodeList(get_tv_show_list())
<commit_msg>bugfixes<commit_after>import sqlite3
import sys, unicodedata, urlparse
import xbmc, xbmcgui, xbmcaddon, xbmcvfs, xbmcplugin


base_url = sys.argv[0]
addon_handle = int(sys.argv[1])
args = urlparse.parse_qs(sys.argv[2][1:])

xbmcplugin.setContent(addon_handle, 'movies')

__addon__     = xbmcaddon.Addon()
__addonid__   = __addon__.getAddonInfo('id')
__addonname__ = __addon__.getAddonInfo('name')
__author__    = __addon__.getAddonInfo('author')
__version__   = __addon__.getAddonInfo('version')
__language__  = __addon__.getLocalizedString


def display_episode_list(seriesList):
  for series in seriesList:
    episode = series['episode']
    label = u"S%02dE%02d - %s (%s, %s)"%(int(series['season']), int(episode['number']), series['title'], episode['title'], episode['firstAired'])
    li = xbmcgui.ListItem(label, iconImage='DefaultFolder.png')
    xbmcplugin.addDirectoryItem(handle=addon_handle, url=base_url, listitem=li, isFolder=False)
  xbmcplugin.endOfDirectory(addon_handle)

def get_database_file():
  folder, files = xbmcvfs.listdir('special://database/')
  for file in files:
    if 'MyVideos' in file:
      return xbmc.translatePath('special://database/' + file)

def get_last_episode(conn, idShow, season):
  episodeQuery = 'SELECT MAX(CAST(c13 AS INTEGER)), c00, c05 FROM episodeview WHERE idShow = ? AND c12 = ?'
  cursor = conn.cursor()
  cursor.execute(episodeQuery, (idShow, season))
  episode = cursor.fetchone()
  return { 'number': episode[0], 'title': episode[1], 'firstAired': episode[2] }


def get_tv_show_list():
  tvshowQuery = 'SELECT idShow, strTitle, MAX(CAST(c12 AS INTEGER)) FROM episodeview GROUP BY idShow ORDER BY strTitle'
  conn = sqlite3.connect(get_database_file())
  cursor = conn.cursor()
  tvshows = cursor.execute(tvshowQuery)

  episodeList = []
  for tvshow in tvshows:
    episodeList.append({ 'title': tvshow[1], 'season': tvshow[2], 'episode': get_last_episode(conn, tvshow[0], tvshow[2]) })
  return episodeList

display_episode_list(get_tv_show_list())

{'fraction_non_alphanumeric': 0.13969674372358937, 'fraction_numerical': 0.013422818791946308, 'mean_word_length': 5.878632478632479, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3452272', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1438, 'n_words': 288}