mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
Fix patch on android
Create own unzip method since zipfile is no longer reliable.
This commit is contained in:
parent
8dad5bdd74
commit
419afcce3c
4 changed files with 80 additions and 32 deletions
|
@ -6,17 +6,14 @@ import json
|
|||
import logging
|
||||
import Queue
|
||||
import threading
|
||||
import urllib
|
||||
import shutil
|
||||
import os
|
||||
import zipfile
|
||||
|
||||
import xbmc
|
||||
import xbmcvfs
|
||||
|
||||
from libraries import requests
|
||||
from helper.utils import should_stop, delete_folder
|
||||
from helper import settings, stop, event, window, kodi_version
|
||||
from helper import settings, stop, event, window, kodi_version, unzip
|
||||
from emby import Emby
|
||||
from emby.core import api
|
||||
from emby.core.exceptions import HTTPException
|
||||
|
@ -300,13 +297,13 @@ def get_objects(src, filename):
|
|||
''' Download objects dependency to temp cache folder.
|
||||
'''
|
||||
temp = xbmc.translatePath('special://temp/emby').decode('utf-8')
|
||||
final = os.path.join(temp, "objects")
|
||||
restart = not xbmcvfs.exists(final + '/') # add slash for verification
|
||||
restart = not xbmcvfs.exists(os.path.join(temp, "objects") + '/')
|
||||
path = os.path.join(temp, filename)
|
||||
|
||||
if not xbmcvfs.exists(path):
|
||||
delete_folder()
|
||||
|
||||
LOG.info(src)
|
||||
path = os.path.join(temp, filename)
|
||||
LOG.info("From %s to %s", src, path)
|
||||
try:
|
||||
response = requests.get(src, stream=True, verify=False)
|
||||
response.raise_for_status()
|
||||
|
@ -318,16 +315,6 @@ def get_objects(src, filename):
|
|||
dl.close()
|
||||
del response
|
||||
|
||||
with zipfile.ZipFile(path) as zf:
|
||||
zf.extractall(temp)
|
||||
|
||||
dirs, files = xbmcvfs.listdir('zip://%s' % urllib.quote_plus(path))
|
||||
extracted = os.path.join(temp, dirs[0])
|
||||
|
||||
try:
|
||||
shutil.copytree(src=os.path.join(extracted, "objects"), dst=final)
|
||||
delete_folder(extracted)
|
||||
unzip(path, temp, "objects")
|
||||
|
||||
return restart
|
||||
except Exception as error:
|
||||
raise
|
||||
|
|
|
@ -153,6 +153,7 @@ class Service(xbmc.Monitor):
|
|||
return
|
||||
|
||||
if get_objects(zipfile, label + '.zip'): # no patch applied previously
|
||||
LOG.info("No previous patch found.")
|
||||
dialog("ok", heading="{emby}", line1=_(33135))
|
||||
xbmc.executebuiltin('RestartApp')
|
||||
else:
|
||||
|
|
|
@ -14,6 +14,7 @@ from utils import JSONRPC
|
|||
from utils import indent
|
||||
from utils import write_xml
|
||||
from utils import compare_version
|
||||
from utils import unzip
|
||||
|
||||
from wrapper import progress
|
||||
from wrapper import catch
|
||||
|
|
|
@ -7,6 +7,7 @@ import logging
|
|||
import os
|
||||
import re
|
||||
import unicodedata
|
||||
import urllib
|
||||
from uuid import uuid4
|
||||
|
||||
import xbmc
|
||||
|
@ -277,7 +278,6 @@ def delete_recursive(path, dirs):
|
|||
''' Delete files and dirs recursively.
|
||||
'''
|
||||
for directory in dirs:
|
||||
|
||||
dirs2, files = xbmcvfs.listdir(os.path.join(path, directory.decode('utf-8')))
|
||||
|
||||
for file in files:
|
||||
|
@ -286,6 +286,65 @@ def delete_recursive(path, dirs):
|
|||
delete_recursive(os.path.join(path, directory.decode('utf-8')), dirs2)
|
||||
xbmcvfs.rmdir(os.path.join(path, directory.decode('utf-8')))
|
||||
|
||||
def unzip(path, dest, folder=None):
|
||||
|
||||
''' Unzip file. zipfile module seems to fail on android.
|
||||
'''
|
||||
path = urllib.quote_plus(path)
|
||||
root = "zip://" + path + '/'
|
||||
|
||||
if folder:
|
||||
|
||||
xbmcvfs.mkdir(os.path.join(dest, folder))
|
||||
dest = os.path.join(dest, folder)
|
||||
root = get_zip_directory(root, folder)
|
||||
|
||||
dirs, files = xbmcvfs.listdir(root)
|
||||
|
||||
if dirs:
|
||||
unzip_recursive(root, dirs, dest)
|
||||
|
||||
for file in files:
|
||||
unzip_file(os.path.join(root, file.decode('utf-8')), os.path.join(dest, file.decode('utf-8')))
|
||||
|
||||
LOG.info("Unzipped %s", path)
|
||||
|
||||
def unzip_recursive(path, dirs, dest):
|
||||
|
||||
for directory in dirs:
|
||||
|
||||
dirs_dir = os.path.join(path, directory.decode('utf-8'))
|
||||
dest_dir = os.path.join(dest, directory.decode('utf-8'))
|
||||
xbmcvfs.mkdir(dest_dir)
|
||||
LOG.info("unzip: %s to %s", dirs_dir, dest_dir)
|
||||
|
||||
dirs2, files = xbmcvfs.listdir(dirs_dir)
|
||||
|
||||
if dirs2:
|
||||
unzip_recursive(dirs_dir, dirs2, dest_dir)
|
||||
|
||||
for file in files:
|
||||
unzip_file(os.path.join(dirs_dir, file.decode('utf-8')), os.path.join(dest_dir, file.decode('utf-8')))
|
||||
|
||||
def unzip_file(path, dest):
|
||||
|
||||
''' Unzip specific file. Path should start with zip://
|
||||
'''
|
||||
xbmcvfs.copy(path, dest)
|
||||
LOG.info("unzip: %s to %s", path, dest)
|
||||
|
||||
def get_zip_directory(path, folder):
|
||||
|
||||
dirs, files = xbmcvfs.listdir(path)
|
||||
|
||||
if folder in dirs:
|
||||
return os.path.join(path, folder)
|
||||
|
||||
for directory in dirs:
|
||||
result = get_zip_directory(os.path.join(path, directory.decode('utf-8')), folder)
|
||||
if result:
|
||||
return result
|
||||
|
||||
def normalize_string(text):
|
||||
|
||||
''' For theme media, do not modify unless
|
||||
|
|
Loading…
Reference in a new issue