- elif data in ('Downloads:', 'Cds:', 'Comentarios:',
- 'Formato:'):
- self.attr = data[:-1].lower()
- elif data == 'Subido por:':
- self.attr = 'autor'
- elif data == 'el':
- self.attr = 'fecha'
+ self.attr_depth = 0
+ elif data in ('Downloads:', 'Cds:', 'Comentarios:', 'Formato:'):
+ self.attr = data[:-1].lower()
+ self.attr_depth = 0
+ self.cur[self.attr] = ''
+ elif data == 'Subido por:':
+ self.attr = 'autor'
+ self.attr_depth = 0
+ self.cur[self.attr] = ''
+ elif data == 'el':
+ self.attr = 'fecha'
+ self.attr_depth = 0
+ self.cur[self.attr] = ''
+
+
+def filter_subtitles(subs, filters):
+ def is_good(sub, filter):
+ def is_any_good(sub, filter):
+ for value in sub.values():
+ if value.lower().find(filter) >= 0:
+ return True
+
+ field = None
+ if len(filter) > 2 and filter[1] == ':':
+ field = filter[0]
+ filter = filter[2:]
+ filter = filter.lower()
+
+ if field is None:
+ return is_any_good(sub, filter)
+ elif field == 't':
+ key = 'titulo'
+ elif field == 'd':
+ key = 'desc'
+ elif field == 'a':
+ key = 'autor'
+ elif field == 'f':
+ key = 'formato'
+ elif field == 'c':
+ key = 'comentarios'
+ elif field == 'C':
+ key = 'cds'
+ elif field == 'F':
+ key = 'fecha'
+ elif field == 'D':
+ key = 'downloads'
+ else:
+ # Not a recognizer field identifier, use the raw filter
+ return is_any_good(sub, field + ':' + filter)
+
+ return sub[key].lower().find(filter) >= 0
+
+ if not filters:
+ return subs
+
+ result = []
+ for sub in subs:
+ for filter in filters:
+ if not is_good(sub, filter):
+ break
+ else:
+ result.append(sub)
+ return result