def download_cache_hook(count, blockSize, totalSize): global pDialog global start_time global downloaded fn = "images.zip" if not (pDialog.iscanceled()): downloaded = downloaded + blockSize if downloaded > totalSize: downloaded = totalSize try: percent = int(min((count*blockSize*100)/totalSize, 100)) except: percent = 100 if count != 0: time_elapsed = time.time() - start_time kbs = downloaded / time_elapsed dl_left = totalSize - downloaded time_remaining = int(dl_left) / int(kbs) time_total = time_remaining + time_elapsed kbs = common.convert_bytes(kbs) dia_l1 = common.get_lstring(32010) + ": " + fn dia_l2 = common.get_lstring(32011) + ": " + str(common.convert_bytes(downloaded)) + "/" + str(common.convert_bytes(totalSize)) + " @ " + str(kbs) + "/s" dia_l3 = common.get_lstring(32012) + ": " + str(datetime.timedelta(seconds=int(time_elapsed))) + "/" + str(datetime.timedelta(seconds=int(time_total))) + " (" + common.get_lstring(32013) + ": " + str(datetime.timedelta(seconds=int(time_remaining))) + ")" pDialog.update(percent, dia_l1, dia_l2, dia_l3) else: if not percent==100: raise "Cancelled"
def Get_Tools(): dimg = common.get_image_path(xbmc.translatePath(os.path.join( addonpath, 'resources', 'images', 'icons', 'default' ))) clean_rss = xbmc.translatePath(os.path.join(dimg, "clear_rss.png")) clean_ico = xbmc.translatePath(os.path.join(dimg, "clear_icons.png")) clean_all = xbmc.translatePath(os.path.join(dimg, "clear_cache.png")) dl = xbmc.translatePath(os.path.join(dimg, "dl_cache.png")) string_crss = common.get_lstring(30810) string_cthumb = common.get_lstring(30811) string_cboth = common.get_lstring(30812) string_cdlimg = common.get_lstring(30813) addLinkTool(string_crss, 'plugin://plugin.video.tas?mode=4&url=clean_rss', clean_rss) addLinkTool(string_cthumb, 'plugin://plugin.video.tas?mode=4&url=clean_ico', clean_ico) addLinkTool(string_cboth, 'plugin://plugin.video.tas?mode=4&url=clean_all', clean_all) addLinkTool(string_cdlimg, 'plugin://plugin.video.tas?mode=4&url=download_img', dl)
def Generate_Index(): dimg = common.get_image_path(xbmc.translatePath(os.path.join( addonpath, 'resources', 'images', 'icons', 'default' ))) latest = xbmc.translatePath(os.path.join(dimg, "latest.png")) notables = xbmc.translatePath(os.path.join(dimg, "not.png")) bbs = xbmc.translatePath(os.path.join(dimg, "bbs.png")) tools = xbmc.translatePath(os.path.join(dimg, "tools.png")) string_latest_videos = common.get_lstring(30800) string_notables = common.get_lstring(30801) string_bbs = common.get_lstring(30802) string_ad_util = common.get_lstring(30803) addDir(string_latest_videos,'http://tasvideos.org/publications.rss',2, latest, common.get_category_fanthumb("Latest Videos", "Fanart")) addDir(string_notables,'http://tasvideos.org/notables.rss',1, notables, common.get_category_fanthumb("Notables", "Fanart")) addDir(string_bbs,'http://tasvideos.org/systems.rss',1, bbs, common.get_category_fanthumb("Browse By System", "Fanart")) addDir(string_ad_util,'none',3, tools, common.get_category_fanthumb("Addon Utilities", "Fanart"))
def download_cache(): global pDialog global start_time global downloaded downloaded = 0 error = 0 start_time = time.time() pDialog = xbmcgui.DialogProgress() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32100) ret = pDialog.create(dia_title, dia_l1) filename = 'images.zip' archive = xbmc.translatePath(os.path.join( 'special://profile/addon_data/plugin.video.tas/', 'cache', filename)) remoteaddr = 'http://xbmc-plugin-video-tas.googlecode.com/files/' try: urllib.urlretrieve(remoteaddr + filename,archive, reporthook=download_cache_hook) except: error = 1 dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32040) ok = dialog.ok(dia_title, dia_l1) if not error==1: unzip_downloaded_cache() dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32042) dia_l2 = common.get_lstring(32043) ok = dialog.ok(dia_title, dia_l1, dia_l2) return
def clean_rss_int(): count = 1 dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32020) dia_l2 = common.get_lstring(32101) ret = dialog.yesno(dia_title, dia_l1, dia_l2) if ret==1: dir = xbmc.translatePath(os.path.join( 'special://profile/addon_data/plugin.video.tas/', 'cache', 'feeds')) pDialog = xbmcgui.DialogProgress() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32022) nret = pDialog.create(dia_title, dia_l1) for subdir, dirs, files in os.walk(dir): total = int(len(files)) for file in files: if not (pDialog.iscanceled()): percent = int(((float(count) / total) * 100)) count = count + 1 cfile = xbmc.translatePath(os.path.join( 'special://profile/addon_data/plugin.video.tas/', 'cache', 'feeds', file)) dia_removing = common.get_lstring(32025) + ":" pDialog.update(percent, dia_removing, file) os.remove(cfile) else: dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32102) ok = dialog.ok(dia_title, dia_l1) return "C" else: dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32102) ok = dialog.ok(dia_title, dia_l1) return "C" return
def init_addon(): path = xbmc.translatePath(os.path.join(addonsavepath , 'cache', 'images')) if os.path.isdir(path)==False: os.makedirs(path) path = xbmc.translatePath(os.path.join(addonsavepath , 'cache', 'feeds')) if os.path.isdir(path)==False: os.makedirs(path) frf = xbmc.translatePath(os.path.join( addonsavepath, 'startup.txt' )) firstrun = os.path.isfile(frf) if firstrun==False: dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32001) dia_l2 = common.get_lstring(32002) dia_l3 = common.get_lstring(32003) dialog = xbmcgui.Dialog() ret = dialog.yesno(dia_title, dia_l1, dia_l2, dia_l3) if ret==1: util.download_cache() file = open(frf, 'w') file.write("Startup Completed") file.close()
def clean_ico_int(): count = 1 dialog = xbmcgui.Dialog() ret = 1 if ret==1: dir = xbmc.translatePath(os.path.join( addonsavepath, 'cache', 'images')) pDialog = xbmcgui.DialogProgress() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32030) nret = pDialog.create(dia_title, dia_l1) for subdir, dirs, files in os.walk(dir): total = int(len(files)) for file in files: if not (pDialog.iscanceled()): percent = int(((float(count) / total) * 100)) count = count + 1 cfile = xbmc.translatePath(os.path.join( addonsavepath, 'cache', 'images', file)) dia_l1 = common.get_lstring(32030) + ": " + file pDialog.update(percent, dia_l1) os.remove(cfile) else: dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32032) ok = dialog.ok(dia_l1, dia_l1) return "C" else: dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32032) ok = dialog.ok(dia_title, dia_l1) return "C" dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32049) ok = dialog.ok(dia_title, dia_l1) return
def unzip_downloaded_cache(): filename = 'images.zip' archive = xbmc.translatePath(os.path.join( 'special://profile/addon_data/plugin.video.tas/', 'cache', filename)) outdir = xbmc.translatePath(os.path.join( 'special://profile/addon_data/plugin.video.tas/', 'cache', 'images')) pDialog = xbmcgui.DialogProgress() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32044) ret = pDialog.create(dia_title, dia_l1) count = 0 zfobj = zipfile.ZipFile(archive) ico_total = len(zfobj.namelist()) for name in zfobj.namelist(): count = count + 1 percent = int(((float(count) / ico_total) * 100)) outfile = open(os.path.join(outdir, name), 'wb') outfile.write(zfobj.read(name)) outfile.close() dia_l1 = common.get_lstring(32045) + ":" dia_l2 = common.get_lstring(32046) + ": " + str(name) dia_l3 = common.get_lstring(32047) + ": " + str(count) + " " + common.get_lstring(32048) + " " + str(ico_total) pDialog.update(int(percent), dia_l1, dia_l2, dia_l3 ) zfobj.close() os.remove(archive) return
def clean_rss(): count = 1 dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32020) dia_l2 = common.get_lstring(32021) ret = dialog.yesno(dia_title, dia_l1, dia_l2) if ret==1: dir = xbmc.translatePath(os.path.join( addonsavepath, 'cache', 'feeds')) pDialog = xbmcgui.DialogProgress() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32022) nret = pDialog.create(dia_title, dia_l1) for subdir, dirs, files in os.walk(dir): total = int(len(files)) for file in files: if not (pDialog.iscanceled()): percent = int(((float(count) / total) * 100)) count = count + 1 cfile = xbmc.translatePath(os.path.join( addonsavepath, 'cache', 'feeds', file)) dia_l1 = common.get_lstring(32025) + ": " pDialog.update(percent, dia_l1, file) os.remove(cfile) else: dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32023) ok = dialog.ok(dia_title, dia_l1) return else: dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32023) ok = dialog.ok(dia_title, dia_l1) return dialog = xbmcgui.Dialog() dia_title = common.get_lstring(32000) dia_l1 = common.get_lstring(32024) ok = dialog.ok(dia_title, dia_l1) return