def createListing(episodes, showname): # TODO maybe localize
	listing = []
	for item in episodes:
		status = item[len(item)-1]
		statusstring = ''
		if status == 0:
			statusstring = localize(30301)
		elif status == 1:
			statusstring = localize(30302)
		elif status == 2:
			statusstring = localize(30303)
		if(item[0] == 0):
			episode = localize(30304) + " " + ('%02d' % item[1])
		else:
			episode = "S" + ('%02d' % item[0]) + "E" + ('%02d' % item[1])
		if item[3]:
			airedstring = "(" + item[3] + ")"
		else:
			airedstring = "(" + localize(30305) + ")"
		title = episode + " [" + statusstring + "]" + ": " + unicode(item[2], "utf-8") + " " + airedstring
		mode = util.getMode()
		mode.mode = "episode"
		mode.episode = Episode(int(item[0]), int(item[1]), str(item[2]), str(item[3]))
		listitem = xbmcgui.ListItem(title, statusstring, path="file", thumbnailImage="thumb.png", iconImage="iconimage.png")
		# Add manual search to context menu
		mode2 = ModeClass("manualsearch")
		mode2.show = mode.show
		mode2.episode = Episode(int(item[0]), int(item[1]), str(item[2]), str(item[3]))
		contextmenuitem = (localize(30004),"XBMC.Container.Update(%s)" % (sys.argv[0] + urllib.quote_plus(pickle.dumps(mode2)) + '/'))
		listitem.addContextMenuItems([contextmenuitem])
		listing.append([pickle.dumps(mode), listitem, True])
	return listing
def createTrackerListing(searchresult):
	listing = []
	for item in searchresult:
		title = item[0] + " " + str(item[3]) + "/" + str(item[4])
		listitem = xbmcgui.ListItem(title, path="file", thumbnailImage="thumb.png", iconImage="iconimage.png")
		#rpdb2.start_embedded_debugger('pw')
		setting = xbmcplugin.getSetting(thisPlugin, "usemagnetlink")
		magnetlink = (setting == localize(33002))
		mode = ModeClass("magnet")
		mode.torrent = Torrent(item[2])
		
		#This is a missunderstanding item[1] is URL to detailed torrent information on TPB not .torrent file
		#if magnetlink:
		#	mode = ModeClass("magnet")
		#	retmode = pickle.dumps(mode)
		#else:
		#	mode = ModeClass("torrent")
		#	retmode = pickle.dumps(mode)
		listing.append([pickle.dumps(mode), listitem, False])
	return listing
def createShowList():
	json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["title", "file", "thumbnail", "art"], "sort": { "method": "title" } }, "id": 1}')
	json_query = unicode(json_query, 'utf-8', errors='ignore')
	json_response = simplejson.loads(json_query)
	listing = []
	shows = json_response['result']['tvshows']
	for items in shows:
		mode = util.getMode()
		mode.mode = "tvshow"
		mode.show = TvShow(items["title"], int(items["tvshowid"]))
		title = items['title']
		listitem = xbmcgui.ListItem(title)
		listitem.setIconImage("")
		listitem.setThumbnailImage(items['thumbnail'])
		if database.getScraperId(items["tvshowid"]) != -1:
			mode2 = ModeClass("changetvshow")
			mode2.show = TvShow(items["title"], int(items["tvshowid"]))
			contextmenuitem = (localize(30003),"XBMC.Container.Update(%s)" % (sys.argv[0] + pickle.dumps(mode2) + '/'))
			listitem.addContextMenuItems([contextmenuitem])
		listing.append([pickle.dumps(mode) , listitem, True])
	return listing