def update_library(self, path=False): if debug.get(): log('remove_video setting set to %s' % (setting('remove_video'))) if path and setting('remove_video') == 'true': if debug.get(): log('removing video from video library %s' % (path)) videolibrary.remove_video(path) if debug.get(): log('update_library setting set to %s' % (setting('update_library'))) if setting('update_library') == 'true': if debug.get(): log('updating whole video library %s' % (path)) xbmc.executebuiltin('UpdateLibrary(video)') while not xbmc.getCondVisibility('Library.IsScanningVideo'): pass while xbmc.getCondVisibility('Library.IsScanningVideo'): xbmc.sleep(20) percent = (self.current - 1) * 100 / self.steps if self.enable: self.bar.update(percent, info('name'), lang(30531) % (self.module_title, lang(30513))) self.current += 1 self.module_current += 1 log('Progress.update_library: self.current=%s, self.module_current=%s' % (self.current, self.module_current))
def __init__(self): try: j = utilxbmc.xjson({ "jsonrpc": "2.0", "method": "Player.GetItem", "params": { "playerid": 1, "properties": ["file", "title", "showtitle", "playcount"] }, "id": 1 }) self.type = 'episode' self.episodeid = j['item']['id'] self.path = j['item']['file'] if setting('fm_alternate') == 'true' or [y for y in ("smb://", "nfs://") if self.path.lower().startswith(y)]: self.alt_method = True else: self.path = os.path.abspath(self.path) self.alt_method = False log("Episode: self.path=%s, self.alt_method=%s" % (self.path, self.alt_method)) self.title = j['item']['title'] self.showtitle = j['item']['showtitle'] self.playcount = j['item']['playcount'] self.rating = None except Exception as e: if debug.get(): log(debug.traceback.print_exc(), xbmc.LOGERROR) debug.exception_dialog(e)
def __rate_lib(self, progress): progress.start_module(lang(30204), self.RATE_LIB_STEPS) try: if not self.episodeid: raise Exception(lang(30601)) progress.update(lang(30522)) # updating rating utilxbmc.set_episode_rating(self.episodeid, self.rating) except Exception as e: if debug.get(): log(debug.traceback.print_exc(), xbmc.LOGERROR) debug.exception_dialog(e) finally: progress.finish_module()
def __preserve_playcount(self, progress): progress.start_module(lang(30701), self.PRESERVE_PLAYCOUNT_STEPS) try: if not self.episodeid: raise Exception(lang(30601)) progress.update(lang(30598)) # setting old playcount utilxbmc.set_episode_playcount(self.episodeid, self.playcount) except Exception as e: if debug.get(): log(debug.traceback.print_exc(), xbmc.LOGERROR) debug.exception_dialog(e) finally: progress.finish_module()
def __delete_files_alt(source, match, del_empty): log("delete files alt") # delete files from source if match count = 0 hidden = ['Thumbs.db', '.DS_Store'] dirs, files = xbmcvfs.listdir(source) for f in files: if os.path.splitext(f)[0].startswith(match): # Don't match copies of files if not re.search(r'(\(\d+\)$)', match): m = re.match(r'^(.((?!\(\d+\)$)))*$', os.path.splitext(f)[0]) if not (m and m.group(0).startswith(match)): continue f = os.path.join(source, f) log("xbmcvfs.delete: f=%s" % (f)) if not xbmcvfs.delete(f): raise ValueError('xbmcvfs.delete', f) else: for h in hidden: if os.path.splitext(f)[0].startswith(h): count += 1 # delete source directory if empty dirs, files = xbmcvfs.listdir(source) length = len(files) if del_empty and length > 0 and debug.get(): files_left = "" if length > 1: files_left = "%s (and %d more)" % (files[0], length - 1) log("xbmcvfs.listdir: file(s) left in folder=%s" % files_left) log("xbmcvfs.rmdir: del_empty=%d, length=%d, count=%d, source=%s" % (del_empty, length, count, source)) if del_empty and length == count: if count > 0: for h in hidden: f = os.path.join(source, h) log("xbmcvfs.delete: f=%s, count=%d" % (f, count)) if not xbmcvfs.delete(f): raise ValueError('xbmcvfs.delete', f) log("xbmcvfs.rmdir: source=%s" % (source)) if not xbmcvfs.rmdir(source): raise ValueError('xbmcvfs.rmdir', source)
def xjson(cmd): d = json.dumps(cmd) r = xbmc.executeJSONRPC(d) try: j = json.loads(r) except UnicodeDecodeError: j = json.loads(r.decode('utf-8', 'ignore')) if debug.get(): log("xsjson: %s" % cmd) for k in j: log("xsjson: %s => %s" % (k, j[k])) try: if 'result' in j: return j['result'] return None except KeyError: log("[%s] %s" % (params['method'], response['error']['message']), level=xbmc.LOGWARNING) return None
def __move(self, progress): progress.start_module(lang(30131), self.MOVE_STEPS) try: progress.update(lang(30590)) # detecting library place lib_source = os.path.dirname(os.path.dirname(os.path.dirname(self.path))) if self.destination == lib_source: raise Exception(lang(30602)) progress.update(lang(30506)) # moving files source = os.path.dirname(self.path) match = os.path.splitext(os.path.basename(self.path))[0] count = utilfile.count_manage_files(self.alt_method, source, match) if not dialog.warning(lang(30131), count): raise Exception(lang(30609)) log("Episode.__move: source=%s" % source) if setting('fm_episodes_structure') == '0': # multiple folders destination = os.path.join(self.destination, self.path.split(os.sep)[-3], self.path.split(os.sep)[-2]) else: # single folder destination = os.path.join(self.destination, self.path.split(os.sep)[-2]) log("Episode.__move: destination=%s, self.alt_method=%s" % (destination, self.alt_method)) utilfile.move_files(self.alt_method, source, destination, match, True) progress.update(lang(30513)) # updating library progress.update_library(self.path) self.path = os.path.join(destination, os.path.basename(self.path)) self.episodeid = utilxbmc.get_episodeid_by_path(self.path) if self.episodeid: # if still in lib source folders progress.update(lang(30514)) # setting watched utilxbmc.set_episode_playcount(self.episodeid, self.playcount+1) except OSError: dialog.error(lang(30610)) except ValueError as err: ValueErrorHandler(err) except Exception as e: if debug.get(): log(debug.traceback.print_exc(), xbmc.LOGERROR) debug.exception_dialog(e) finally: progress.finish_module()
def __delete(self, progress): progress.start_module(lang(30132), self.DELETE_STEPS) try: progress.update(lang(30516)) # deleting files source = os.path.dirname(self.path) remove_empty = setting('fm_episodes_remove_empty') == 'true' match = os.path.splitext(os.path.basename(self.path))[0] log("Episode.__delete: match=%s" % match) count = utilfile.count_manage_files(self.alt_method, source, match) if not dialog.warning(lang(30132), count): raise Exception(lang(30609)) utilfile.delete_files(self.alt_method, source, match, remove_empty) progress.update(lang(30513)) # updating library progress.update_library(self.path) self.episodeid = None self.path = None except ValueError as err: ValueErrorHandler(err) except Exception as e: if debug.get(): log(debug.traceback.print_exc(), xbmc.LOGERROR) debug.exception_dialog(e) finally: progress.finish_module()