cplay-ng

simple curses audio player
git clone https://git.ce9e.org/cplay-ng.git

commit
5eb8ad099e088e9d6427a60cb23503597c913a1a
parent
94749edd6bd5c994ac650edc71676004b3385779
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-09-03 16:56
make filter search recursive

Diffstat

M cplay.py 30 ++++++++++++++++++++++++++----

1 files changed, 26 insertions, 4 deletions


diff --git a/cplay.py b/cplay.py

@@ -248,8 +248,8 @@ class List:
  248   248                 return True
  249   249         return False
  250   250 
  251    -1     def format_item(self, item):
  252    -1         if app.verbose:
   -1   251     def format_item(self, item, force_verbose=False):
   -1   252         if app.verbose or force_verbose:
  253   253             name = os.path.relpath(item, filelist.path)
  254   254         else:
  255   255             name = os.path.basename(item)
@@ -311,6 +311,7 @@ class HelpList(List):
  311   311 class Filelist(List):
  312   312     def __init__(self):
  313   313         super().__init__()
   -1   314         self.path = None
  314   315         self.input = Input()
  315   316         self.set_path(os.getcwd())
  316   317 
@@ -320,8 +321,13 @@ class Filelist(List):
  320   321             title += 'search "%s"/' % self.input.str
  321   322         return title
  322   323 
   -1   324     def format_item(self, item):
   -1   325         return super().format_item(item, force_verbose=self.input.str)
   -1   326 
  323   327     def set_path(self, path, prev=None):
  324    -1         self.path = path
   -1   328         if path != self.path:
   -1   329             self.path = path
   -1   330             self.search_cache = []
  325   331         self.all_items = []
  326   332         self.input.str = ''
  327   333 
@@ -338,10 +344,26 @@ class Filelist(List):
  338   344             self.position = 0
  339   345             self.cursor = 0
  340   346 
   -1   347     def build_search_cache(self, root):
   -1   348         results = []
   -1   349         for path, is_dir in listdir(root):
   -1   350             ext = path.rsplit('.', 1)[-1]
   -1   351             if is_dir:
   -1   352                 children = self.build_search_cache(path)
   -1   353                 if children:
   -1   354                     results.append(path)
   -1   355                     results += children
   -1   356             elif ext in AUDIO_EXTENSIONS or ext == 'm3u':
   -1   357                 results.append(path)
   -1   358         return results
   -1   359 
  341   360     def filter(self, query):
   -1   361         if not self.search_cache:
   -1   362             self.search_cache = self.build_search_cache(self.path)
   -1   363 
  342   364         if query:
  343   365             self.items = []
  344    -1             for path in self.all_items:
   -1   366             for path in self.search_cache:
  345   367                 if str_match(query, self.format_item(path)):
  346   368                     self.items.append(path)
  347   369         else: