class ImageLoader: def __init__(self): self.fs = FS() self.db = TexturesSQL(self.fs._path('database://Textures13.db')) def load_to_cache(self, url): if not url: return False if self.db.url_exists(url): return True self.details = ImageDetails(url) if not self.fs.exists(self.details.file_path): try: self.auth = Auth() self.cookie = self.auth.get_cookies() cook = self.mycookie if self.cookie == None else self.cookie response = xbmcup.net.http.get(url, cookies=cook, verify=False, proxies=PROXIES) if (self.cookie == None): self.mycookie = response.cookies except xbmcup.net.http.exceptions.RequestException: print(traceback.format_exc()) else: if (response.status_code == 200): file = self.fs.file(self.details.file_path, "w") file.write(response.content) file.close() self.details.get_image_info() self.db.AddCachedTexture(self.details)
class ImageDetails: url = '' file = '' # cachedurl hash = '' # imagehash width = 0 height = 0 file_path = '' size = 0 def __init__(self, url): self.url = url self.crc = KodiCrc32() self.fs = FS() self.get_cache_file_name() # https://github.com/xbmc/xbmc/blob/master/xbmc/TextureCacheJob.cpp def get_image_hash(self): self.hash = "BADHASH" st = xbmcvfs.Stat(self.file_path) time = st.st_mtime() self.size = st.st_size() if time == None: time = st.st_ctime() if time or self.size: self.hash = 'd' + str(time) + 's' + str(self.size) return self.hash return self.hash def get_cache_file_name(self): self.crc.ComputeFromLowerCase(self.url) fname = self.crc.in_hex[2:] + self.url[-4:] self.file = fname[0] + '/' + fname self.file_path = self.fs._path('thumbnails://' + self.file) return self.file_path def get_image_size(self): try: fn = self.file_path.decode( 'utf8') if IS_WIN_PLATFORM else self.file_path input = open(fn, 'rb') self.width, self.height = get_image_size_from_bytesio( input, self.size) input.close() except: print(traceback.format_exc()) return None def get_image_info(self): self.get_image_hash() self.get_image_size()
def __init__(self): self.fs = FS() self.db = TexturesSQL(self.fs._path('database://Textures13.db'))
def __init__(self, url): self.url = url self.crc = KodiCrc32() self.fs = FS() self.get_cache_file_name()