Make global filters take precedence over track filter
This commit is contained in:
parent
8a9425c662
commit
0ef5db476b
|
|
@ -15,6 +15,12 @@ class Filter:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.payload = None
|
self.payload = None
|
||||||
self.tag: str = None
|
self.tag: str = None
|
||||||
|
self.preload: bool = False
|
||||||
|
|
||||||
|
def set_preload(self) -> bool:
|
||||||
|
"""Internal method to set whether or not the filter was preloaded."""
|
||||||
|
self.preload = True
|
||||||
|
return self.preload
|
||||||
|
|
||||||
|
|
||||||
class Equalizer(Filter):
|
class Equalizer(Filter):
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,17 @@ class Filters:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._filters: List[Filter] = []
|
self._filters: List[Filter] = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def has_preload(self):
|
||||||
|
"""Property which checks if any applied filters were preloaded"""
|
||||||
|
return any(f for f in self._filters if f.preload == True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def empty(self):
|
||||||
|
"""Property which checks if the filter list is empty"""
|
||||||
|
return len(self._filters) == 0
|
||||||
|
|
||||||
|
|
||||||
def add_filter(self, *, filter: Filter):
|
def add_filter(self, *, filter: Filter):
|
||||||
"""Adds a filter to the list of filters applied"""
|
"""Adds a filter to the list of filters applied"""
|
||||||
if any(f for f in self._filters if f.tag == filter.tag):
|
if any(f for f in self._filters if f.tag == filter.tag):
|
||||||
|
|
@ -55,7 +66,9 @@ class Filters:
|
||||||
"""Removes all filters from the list"""
|
"""Removes all filters from the list"""
|
||||||
self._filters = []
|
self._filters = []
|
||||||
|
|
||||||
|
def get_preload_filters(self):
|
||||||
|
"""Get all preloaded filters"""
|
||||||
|
return [f for f in self._filters if f.preload == True]
|
||||||
|
|
||||||
def get_all_payloads(self):
|
def get_all_payloads(self):
|
||||||
"""Returns a formatted dict of all the filter payloads"""
|
"""Returns a formatted dict of all the filter payloads"""
|
||||||
|
|
@ -336,13 +349,21 @@ class Player(VoiceProtocol):
|
||||||
"noReplace": ignore_if_playing
|
"noReplace": ignore_if_playing
|
||||||
}
|
}
|
||||||
|
|
||||||
# Apply track filters
|
|
||||||
if track.filters:
|
|
||||||
# First lets remove all filters quickly
|
|
||||||
await self.reset_filters()
|
|
||||||
|
|
||||||
|
# Remove preloaded filters if last track had any
|
||||||
|
if self.filters.has_preload:
|
||||||
|
for filter in self.filters.get_preload_filters():
|
||||||
|
await self.remove_filter(filter_tag=filter.tag)
|
||||||
|
|
||||||
|
# Global filters take precedence over track filters
|
||||||
|
# So if no global filters are detected, lets apply any
|
||||||
|
# necessary track filters
|
||||||
|
|
||||||
|
if self.filters.empty and track.filters:
|
||||||
# Now apply all filters
|
# Now apply all filters
|
||||||
for filter in track.filters:
|
for filter in track.filters:
|
||||||
|
# Set preload for filter
|
||||||
|
filter.set_preload()
|
||||||
await self.add_filter(filter=filter)
|
await self.add_filter(filter=filter)
|
||||||
|
|
||||||
if end > 0:
|
if end > 0:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue