Fix channel cleanup removing priority channels
This commit is contained in:
1 parent
bd9d818b21
commit
c0d6d8eb60
2 files changed
+29
-19
No files matched your search
+19
-12
@@ -58,9 +58,10 @@ class Channel:
|
|||||||
self.points: Optional[int] = None
|
self.points: Optional[int] = None
|
||||||
self._stream: Optional[Stream] = None
|
self._stream: Optional[Stream] = None
|
||||||
self._pending_stream_up: Optional[asyncio.Task[Any]] = None
|
self._pending_stream_up: Optional[asyncio.Task[Any]] = None
|
||||||
# Priority channels are considered first when switching channels,
|
# Priority channels are:
|
||||||
# and if we're watching a non-priority channel,
|
# • considered first when switching channels
|
||||||
# a priority channel going up triggers a switch
|
# • if we're watching a non-priority channel, a priority channel going up triggers a switch
|
||||||
|
# • not cleaned up unless they're streaming a game we haven't selected
|
||||||
self.priority: bool = priority
|
self.priority: bool = priority
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -120,6 +121,13 @@ class Channel:
|
|||||||
"""
|
"""
|
||||||
return self._stream is not None
|
return self._stream is not None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def offline(self) -> bool:
|
||||||
|
"""
|
||||||
|
Returns True if the streamer is offline and isn't about to come online, False otherwise.
|
||||||
|
"""
|
||||||
|
return self._stream is None and self._pending_stream_up is None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pending_online(self) -> bool:
|
def pending_online(self) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -210,35 +218,34 @@ class Channel:
|
|||||||
The 'stream-up' event is sent before the stream actually goes online,
|
The 'stream-up' event is sent before the stream actually goes online,
|
||||||
so just wait a bit and check if it's actually online by then.
|
so just wait a bit and check if it's actually online by then.
|
||||||
"""
|
"""
|
||||||
self.display()
|
|
||||||
await asyncio.sleep(ONLINE_DELAY.total_seconds())
|
await asyncio.sleep(ONLINE_DELAY.total_seconds())
|
||||||
online = await self.check_online()
|
online = await self.check_online()
|
||||||
self._pending_stream_up = None
|
self._pending_stream_up = None # for 'display' to work properly
|
||||||
self.display()
|
self.display()
|
||||||
if online:
|
if online:
|
||||||
self._twitch.on_online(self)
|
self._twitch.on_online(self)
|
||||||
|
|
||||||
def set_online(self):
|
def set_online(self):
|
||||||
"""
|
"""
|
||||||
Sets the channel status to OFFLINE.
|
Sets the channel status to PENDING_ONLINE, where after ONLINE_DELAY,
|
||||||
|
it's going to be set to ONLINE.
|
||||||
|
|
||||||
This is called externally, if we receive an event about this happening.
|
This is called externally, if we receive an event about this happening.
|
||||||
"""
|
"""
|
||||||
if self.online or self.pending_online:
|
if self.offline:
|
||||||
# we're already online, or about to be
|
self._pending_stream_up = asyncio.create_task(self._online_delay())
|
||||||
return
|
self.display()
|
||||||
self._pending_stream_up = asyncio.create_task(self._online_delay())
|
|
||||||
# display is called from within the task
|
|
||||||
|
|
||||||
def set_offline(self):
|
def set_offline(self):
|
||||||
"""
|
"""
|
||||||
Sets the channel status to OFFLINE.
|
Sets the channel status to OFFLINE. Cancels PENDING_ONLINE if applicable.
|
||||||
|
|
||||||
This is called externally, if we receive an event about this happening.
|
This is called externally, if we receive an event about this happening.
|
||||||
"""
|
"""
|
||||||
if self._pending_stream_up is not None:
|
if self._pending_stream_up is not None:
|
||||||
self._pending_stream_up.cancel()
|
self._pending_stream_up.cancel()
|
||||||
self._pending_stream_up = None
|
self._pending_stream_up = None
|
||||||
|
self.display()
|
||||||
if self.online:
|
if self.online:
|
||||||
self._stream = None
|
self._stream = None
|
||||||
self.display()
|
self.display()
|
||||||
|
|||||||
@@ -204,25 +204,28 @@ class Twitch:
|
|||||||
self.restart_watching()
|
self.restart_watching()
|
||||||
self.change_state(State.CHANNELS_CLEANUP)
|
self.change_state(State.CHANNELS_CLEANUP)
|
||||||
elif self._state is State.CHANNELS_CLEANUP:
|
elif self._state is State.CHANNELS_CLEANUP:
|
||||||
# remove all channels that are offline,
|
|
||||||
# or aren't streaming the game we want anymore
|
|
||||||
if self.game is None:
|
if self.game is None:
|
||||||
# remove everything
|
# remove everything
|
||||||
to_remove: List[Channel] = list(self.channels.values())
|
to_remove: List[Channel] = list(self.channels.values())
|
||||||
else:
|
else:
|
||||||
|
# remove all channels that:
|
||||||
to_remove = [
|
to_remove = [
|
||||||
channel for channel in self.channels.values()
|
channel
|
||||||
if not (channel.online or channel.pending_online)
|
for channel in self.channels.values()
|
||||||
|
if channel.offline # are offline
|
||||||
|
or not channel.priority # aren't prioritized
|
||||||
|
# aren't streaming the game we want anymore
|
||||||
or channel.game is None or channel.game != self.game
|
or channel.game is None or channel.game != self.game
|
||||||
]
|
]
|
||||||
self.websocket.remove_topics(
|
self.websocket.remove_topics(
|
||||||
WebsocketTopic.as_str("Channel", "VideoPlayback", channel.id)
|
WebsocketTopic.as_str("Channel", "VideoPlayback", channel.id)
|
||||||
for channel in to_remove
|
for channel in to_remove
|
||||||
)
|
)
|
||||||
|
watching_channel = self.watching_channel.get_with_default(None)
|
||||||
|
if watching_channel is not None and watching_channel in to_remove:
|
||||||
|
# we're removing a channel we're watching
|
||||||
|
self.stop_watching()
|
||||||
for channel in to_remove:
|
for channel in to_remove:
|
||||||
if self.is_watching(channel):
|
|
||||||
# we're removing a channel we're watching
|
|
||||||
self.stop_watching()
|
|
||||||
del self.channels[channel.id]
|
del self.channels[channel.id]
|
||||||
channel.remove()
|
channel.remove()
|
||||||
self.gui.channels.shrink()
|
self.gui.channels.shrink()
|
||||||
|
|||||||
Reference in new issue
Block a user