Fix Backup Videoteca
This commit is contained in:
+48
-21
@@ -3,16 +3,18 @@
|
|||||||
# Backup and restore video library
|
# Backup and restore video library
|
||||||
# ------------------------------------------------------------
|
# ------------------------------------------------------------
|
||||||
|
|
||||||
import datetime, xbmc
|
import datetime, xbmc, os, shutil
|
||||||
|
|
||||||
from core import ziptools, videolibrarytools, filetools
|
from zipfile import ZipFile
|
||||||
|
from core import videolibrarytools, filetools
|
||||||
from platformcode import logger, config, platformtools, xbmc_videolibrary
|
from platformcode import logger, config, platformtools, xbmc_videolibrary
|
||||||
from distutils.dir_util import copy_tree
|
from distutils.dir_util import copy_tree
|
||||||
from specials import videolibrary
|
from specials import videolibrary
|
||||||
|
|
||||||
temp_path = u'' + xbmc.translatePath("special://userdata/addon_data/plugin.video.kod/temp/")
|
temp_path = u'' + xbmc.translatePath("special://userdata/addon_data/plugin.video.kod/temp/")
|
||||||
movies_path = u'' + filetools.join(temp_path, "movies")
|
videolibrary_temp_path = u'' + xbmc.translatePath("special://userdata/addon_data/plugin.video.kod/temp/videolibrary")
|
||||||
tvshows_path = u'' + filetools.join(temp_path, "tvshows")
|
movies_path = u'' + filetools.join(videolibrary_temp_path, "movies")
|
||||||
|
tvshows_path = u'' + filetools.join(videolibrary_temp_path, "tvshows")
|
||||||
videolibrary_movies_path = u'' + videolibrarytools.MOVIES_PATH
|
videolibrary_movies_path = u'' + videolibrarytools.MOVIES_PATH
|
||||||
videolibrary_tvshows_path = u'' + videolibrarytools.TVSHOWS_PATH
|
videolibrary_tvshows_path = u'' + videolibrarytools.TVSHOWS_PATH
|
||||||
|
|
||||||
@@ -26,11 +28,11 @@ def export_videolibrary(item):
|
|||||||
zip_file = u'' + xbmc.translatePath(zip_file_folder + "KoD_video_library-" + str(datetime.date.today()) + ".zip")
|
zip_file = u'' + xbmc.translatePath(zip_file_folder + "KoD_video_library-" + str(datetime.date.today()) + ".zip")
|
||||||
|
|
||||||
p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80003))
|
p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80003))
|
||||||
p_dialog.update(0)
|
# p_dialog.update(0)
|
||||||
|
|
||||||
if filetools.exists(temp_path):
|
if filetools.exists(videolibrary_temp_path):
|
||||||
filetools.rmdirtree(temp_path)
|
shutil.rmtree(videolibrary_temp_path)
|
||||||
filetools.mkdir(temp_path)
|
filetools.mkdir(videolibrary_temp_path)
|
||||||
p_dialog.update(25)
|
p_dialog.update(25)
|
||||||
filetools.mkdir(movies_path)
|
filetools.mkdir(movies_path)
|
||||||
copy_tree(videolibrary_movies_path, movies_path)
|
copy_tree(videolibrary_movies_path, movies_path)
|
||||||
@@ -39,10 +41,8 @@ def export_videolibrary(item):
|
|||||||
copy_tree(videolibrary_tvshows_path, tvshows_path)
|
copy_tree(videolibrary_tvshows_path, tvshows_path)
|
||||||
p_dialog.update(75)
|
p_dialog.update(75)
|
||||||
|
|
||||||
zipper = ziptools.ziptools()
|
zip(videolibrary_temp_path, zip_file)
|
||||||
zipper.zip(temp_path, zip_file)
|
shutil.rmtree(temp_path)
|
||||||
|
|
||||||
filetools.rmdirtree(temp_path)
|
|
||||||
|
|
||||||
p_dialog.update(100)
|
p_dialog.update(100)
|
||||||
xbmc.sleep(1000)
|
xbmc.sleep(1000)
|
||||||
@@ -60,21 +60,21 @@ def import_videolibrary(item):
|
|||||||
return
|
return
|
||||||
|
|
||||||
p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80007))
|
p_dialog = platformtools.dialog_progress_bg(config.get_localized_string(20000), config.get_localized_string(80007))
|
||||||
p_dialog.update(0)
|
# p_dialog.update(0)
|
||||||
|
|
||||||
if filetools.exists(temp_path):
|
if filetools.exists(temp_path):
|
||||||
filetools.rmdirtree(temp_path)
|
shutil.rmtree(temp_path)
|
||||||
filetools.mkdir(temp_path)
|
filetools.mkdir(videolibrary_temp_path)
|
||||||
|
|
||||||
unzipper = ziptools.ziptools()
|
unzip(videolibrary_temp_path, zip_file)
|
||||||
unzipper.extract(zip_file, temp_path)
|
|
||||||
p_dialog.update(20)
|
p_dialog.update(20)
|
||||||
|
|
||||||
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
|
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
|
||||||
xbmc_videolibrary.clean()
|
xbmc_videolibrary.clean()
|
||||||
p_dialog.update(30)
|
p_dialog.update(30)
|
||||||
filetools.rmdirtree(videolibrary_movies_path)
|
xbmc.sleep(1000)
|
||||||
filetools.rmdirtree(videolibrary_tvshows_path)
|
shutil.rmtree(videolibrary_movies_path)
|
||||||
|
shutil.rmtree(videolibrary_tvshows_path)
|
||||||
p_dialog.update(50)
|
p_dialog.update(50)
|
||||||
|
|
||||||
config.verify_directories_created()
|
config.verify_directories_created()
|
||||||
@@ -84,7 +84,7 @@ def import_videolibrary(item):
|
|||||||
if filetools.exists(tvshows_path):
|
if filetools.exists(tvshows_path):
|
||||||
copy_tree(tvshows_path, videolibrary_tvshows_path)
|
copy_tree(tvshows_path, videolibrary_tvshows_path)
|
||||||
p_dialog.update(90)
|
p_dialog.update(90)
|
||||||
filetools.rmdirtree(temp_path)
|
shutil.rmtree(temp_path)
|
||||||
|
|
||||||
p_dialog.update(100)
|
p_dialog.update(100)
|
||||||
xbmc.sleep(1000)
|
xbmc.sleep(1000)
|
||||||
@@ -93,4 +93,31 @@ def import_videolibrary(item):
|
|||||||
|
|
||||||
videolibrary.update_videolibrary()
|
videolibrary.update_videolibrary()
|
||||||
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
|
if config.is_xbmc() and config.get_setting("videolibrary_kodi"):
|
||||||
xbmc_videolibrary.update()
|
xbmc_videolibrary.update()
|
||||||
|
|
||||||
|
|
||||||
|
def zip(dir, file):
|
||||||
|
smb = False
|
||||||
|
if file.lower().startswith('smb://'):
|
||||||
|
temp = file
|
||||||
|
file = filetools.join(temp_path, os.path.split(file)[-1])
|
||||||
|
smb = True
|
||||||
|
with ZipFile(file, "w") as zf:
|
||||||
|
abs_src = os.path.abspath(dir)
|
||||||
|
for dirname, subdirs, files in os.walk(dir):
|
||||||
|
for filename in files:
|
||||||
|
absname = os.path.abspath(os.path.join(dirname, filename))
|
||||||
|
arcname = absname[len(abs_src) + 1:]
|
||||||
|
zf.write(absname, arcname)
|
||||||
|
zf.close()
|
||||||
|
if smb:
|
||||||
|
filetools.move(file, temp)
|
||||||
|
|
||||||
|
def unzip(dir, file):
|
||||||
|
if file.lower().startswith('smb://'):
|
||||||
|
temp = filetools.join(temp_path, os.path.split(file)[-1])
|
||||||
|
filetools.copy(file, temp)
|
||||||
|
file = temp
|
||||||
|
|
||||||
|
with ZipFile(file, 'r') as zf:
|
||||||
|
zf.extractall(dir)
|
||||||
Reference in New Issue
Block a user