def search(bot,mess,args): """search all paths for matches - search [include -exclude]""" if not args: args = ['/'] matches = [] # search all library paths dirs = [bot.lib_video_dir,bot.lib_video_file, bot.lib_audio_dir,bot.lib_audio_file] for d in dirs: matches.extend(util.matches(d,args)) if len(matches)==0: return 'Found 0 matches' # reply with matches based on max_matches setting if len(matches)>1: maxm = bot.opt('library.max_matches') if maxm<1 or len(matches)<=maxm: return 'Found '+str(len(matches))+' matches: '+util.list2str(matches) else: return 'Found '+str(len(matches))+' matches' return 'Found '+str(len(matches))+' match: '+str(matches[0])
def random_chat(bot, mess, args): """play random song - random [include -exclude]""" if not bot.has_plugin('library'): return 'This command not available because plugin "library" not loaded' # check if a search term was passed if not args: matches = bot.lib_audio_file else: matches = util.matches(bot.lib_audio_file, args) if len(matches) == 0: return 'Found 0 matches' # play a random audio file from the matches rand = random.randint(0, len(matches) - 1) match = bot.library_translate(matches[rand]) result = bot.xbmc('Player.Open', {'item': {'file': match}}) if 'error' in result.keys(): s = 'Unable to open: ' + match log.error(s) return s bot.run_cmd('fullscreen', ['on']) return 'Playing "' + match + '"'
def random_chat(bot,mess,args): """play random song - random [include -exclude]""" if not bot.has_plugin('library'): return 'This command not available because plugin "library" not loaded' # check if a search term was passed if not args: matches = bot.lib_audio_file else: matches = util.matches(bot.lib_audio_file,args) if len(matches)==0: return 'Found 0 matches' # play a random audio file from the matches rand = random.randint(0,len(matches)-1) match = bot.library_translate(matches[rand]) result = bot.xbmc('Player.Open',{'item':{'file':match}}) if 'error' in result.keys(): s = 'Unable to open: '+match log.error(s) return s bot.run_cmd('fullscreen',['on']) return 'Playing "'+match+'"'
def __errors(self,mess,args): """list errors - errors [*] [search1 search2]""" if not self.errors: return 'No errors' if not args: args = ['-startup'] if '*' in args: matches = self.errors else: matches = util.matches(self.errors,args,sort=False) if not matches: return 'No matching errors' return util.list2str(matches)
def _file(bot, args, dirs): """helper function for video() and audio()""" if not args: return 'You must specify a search term' # find matches and respond if len(matches)!=1 matches = util.matches(dirs, args) if len(matches) == 0: return 'Found 0 matches' if len(matches) > 1: maxm = bot.opt('library.max_matches') if maxm < 1 or len(matches) <= maxm: return 'Found ' + str( len(matches)) + ' matches: ' + util.list2str(matches) else: return 'Found ' + str(len(matches)) + ' matches' # translate library path if necessary match = bot.library_translate(matches[0]) # if there was 1 match, play the file, and check for not found error result = bot.xbmc('Player.Open', {'item': {'file': match}}) if 'error' in result.keys(): s = 'Unable to open: ' + match log.error(s) return s bot.run_cmd('fullscreen', ['on']) # clear last_played bot.last_played = None if bot.has_plugin('bookmark'): bot.last_resume = None return 'Playing "' + match + '"'
def _file(bot,args,dirs): """helper function for video() and audio()""" if not args: return 'You must specify a search term' # find matches and respond if len(matches)!=1 matches = util.matches(dirs,args) if len(matches)==0: return 'Found 0 matches' if len(matches)>1: maxm = bot.opt('library.max_matches') if maxm<1 or len(matches)<=maxm: return 'Found '+str(len(matches))+' matches: '+util.list2str(matches) else: return 'Found '+str(len(matches))+' matches' # translate library path if necessary match = bot.library_translate(matches[0]) # if there was 1 match, play the file, and check for not found error result = bot.xbmc('Player.Open',{'item':{'file':match}}) if 'error' in result.keys(): s = 'Unable to open: '+match log.error(s) return s bot.run_cmd('fullscreen',['on']) # clear last_played bot.last_played = None if bot.has_plugin('bookmark'): bot.last_resume = None return 'Playing "'+match+'"'
def _files(bot, args, dirs, pid): """helper function for videos() and audios()""" if not args: return 'You must specify a search term' cmd = ' '.join(args) # check for item# as last arg and @ for item match string last = args[-1] num = None search = None if last.startswith('@'): search = util.get_args(last[1:]) elif last.startswith('#'): try: num = int(last[1:]) - 1 except ValueError: pass # default is 0 if not specified if (search is not None) or (num is not None): args = args[:-1] if not search and not num: num = 0 # find matches and respond if len(matches)!=1 matches = util.matches(dirs, args) if len(matches) == 0: return 'Found 0 matches' # default to top dir if every match is a sub dir matches = util.reducetree(matches) if len(matches) > 1: maxm = bot.opt('library.max_matches') if maxm < 1 or len(matches) <= maxm: return 'Found ' + str( len(matches)) + ' matches: ' + util.list2str(matches) else: return 'Found ' + str(len(matches)) + ' matches' # translate library path if necessary match = bot.library_translate(matches[0]) # if there was 1 match, add the whole directory to a playlist # also check for an error opening the directory bot.xbmc('Playlist.Clear', {'playlistid': pid}) result = bot.xbmc('Playlist.Add', { 'playlistid': pid, 'item': { 'directory': match } }, timeout=60) if 'error' in result.keys(): s = 'Unable to open: ' + match log.error(s) return s msg = '' # find first item matching @search if search: params = {'playlistid': pid, 'properties': ['file']} items = bot.xbmc('Playlist.GetItems', params)['result']['items'] items = [x['file'] for x in items] item_matches = util.matches(items, search, False) if len(item_matches): num = items.index(item_matches[0]) msg += 'Found matching item "%s" --- ' % os.path.basename( item_matches[0]) else: num = 0 msg += 'No item matching "%s" --- ' % ' '.join(search) bot.xbmc('Player.Open', {'item': {'playlistid': pid, 'position': num}}) bot.run_cmd('fullscreen', ['on']) # set last_played for bookmarking bot.last_played = (pid, matches[0]) return msg + 'Playlist from "' + match + '" starting with #' + str(num + 1)
def _files(bot,args,dirs,pid): """helper function for videos() and audios()""" if not args: return 'You must specify a search term' cmd = ' '.join(args) # check for item# as last arg and @ for item match string last = args[-1] num = None search = None if last.startswith('@'): search = util.get_args(last[1:]) elif last.startswith('#'): try: num = int(last[1:])-1 except ValueError: pass # default is 0 if not specified if (search is not None) or (num is not None): args = args[:-1] if not search and not num: num = 0 # find matches and respond if len(matches)!=1 matches = util.matches(dirs,args) if len(matches)==0: return 'Found 0 matches' # default to top dir if every match is a sub dir matches = util.reducetree(matches) if len(matches)>1: maxm = bot.opt('library.max_matches') if maxm<1 or len(matches)<=maxm: return 'Found '+str(len(matches))+' matches: '+util.list2str(matches) else: return 'Found '+str(len(matches))+' matches' # translate library path if necessary match = bot.library_translate(matches[0]) # if there was 1 match, add the whole directory to a playlist # also check for an error opening the directory bot.xbmc('Playlist.Clear',{'playlistid':pid}) result = bot.xbmc('Playlist.Add',{'playlistid':pid,'item': {'directory':match}},timeout=60) if 'error' in result.keys(): s = 'Unable to open: '+match log.error(s) return s msg = '' # find first item matching @search if search: params = {'playlistid':pid,'properties':['file']} items = bot.xbmc('Playlist.GetItems',params)['result']['items'] items = [x['file'] for x in items] item_matches = util.matches(items,search,False) if len(item_matches): num = items.index(item_matches[0]) msg += 'Found matching item "%s" --- ' % os.path.basename(item_matches[0]) else: num = 0 msg += 'No item matching "%s" --- ' % ' '.join(search) bot.xbmc('Player.Open',{'item':{'playlistid':pid,'position':num}}) bot.run_cmd('fullscreen',['on']) # set last_played for bookmarking bot.last_played = (pid,matches[0]) return msg+'Playlist from "'+match+'" starting with #'+str(num+1)