Skip to content

Commit

Permalink
style: reformat with black
Browse files Browse the repository at this point in the history
  • Loading branch information
hizkifw committed May 13, 2024
1 parent f1b7111 commit 1afab74
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
17 changes: 9 additions & 8 deletions fc2_live_dl/autofc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ async def update(self, event: CallbackEvent):

self._channel_metrics[event.channel_id]["event_type"] = event.type
if event.type == CallbackEvent.Type.FRAGMENT_PROGRESS:
self._channel_metrics[event.channel_id][
"fragments_downloaded"
] = event.data["fragments_downloaded"]
self._channel_metrics[event.channel_id][
"total_downloaded"
] = event.data["total_size"]
self._channel_metrics[event.channel_id]["fragments_downloaded"] = (
event.data["fragments_downloaded"]
)
self._channel_metrics[event.channel_id]["total_downloaded"] = (
event.data["total_size"]
)

async def promstr(self):
async with self._lock:
Expand Down Expand Up @@ -80,6 +80,7 @@ async def wait_for_debounce(self, duration):
await asyncio.sleep(duration - diff)
self._last_startup_time = time.time()


class AutoFC2:
default_args = {
"config": "autofc2.json",
Expand Down Expand Up @@ -141,8 +142,8 @@ async def noop():
async def debounce_channel(self, channel_id):
config = self.get_config()
debounce_time = 0
if 'autofc2' in config and 'debounce_time' in config['autofc2']:
debounce_time = config['autofc2']['debounce_time']
if "autofc2" in config and "debounce_time" in config["autofc2"]:
debounce_time = config["autofc2"]["debounce_time"]

if channel_id not in self.channel_state:
self.channel_state[channel_id] = ChannelState()
Expand Down
20 changes: 14 additions & 6 deletions fc2_live_dl/fc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ async def _main_loop(self):
self._ws.receive_json(), self.heartbeat_interval
)
except asyncio.TimeoutError:
self._logger.debug(f'Got no messages for {self.heartbeat_interval} seconds, sending heartbeat')
self._logger.debug(
f"Got no messages for {self.heartbeat_interval} seconds, sending heartbeat"
)
await self._try_heartbeat()
continue

Expand Down Expand Up @@ -222,13 +224,19 @@ async def wait_for_online(self, interval):
if await self.is_online():
break
except Exception as e:
description = f'{e.__class__.__name__}: {e}'
self._logger.warn(f'Error when checking if stream is live: {description}')
current_interval = min(current_interval * 2, self.MAX_LIVE_CHECK_INTERVAL)
self._logger.debug(f'Next check in {current_interval} seconds')
description = f"{e.__class__.__name__}: {e}"
self._logger.warn(
f"Error when checking if stream is live: {description}"
)
current_interval = min(
current_interval * 2, self.MAX_LIVE_CHECK_INTERVAL
)
self._logger.debug(f"Next check in {current_interval} seconds")
else:
if current_interval != interval:
self._logger.debug(f'Successfully fetched live status, restoring check interval of {interval} seconds')
self._logger.debug(
f"Successfully fetched live status, restoring check interval of {interval} seconds"
)
current_interval = interval

for _ in range(current_interval):
Expand Down
6 changes: 4 additions & 2 deletions fc2_live_dl/hls.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _get_fragment_id(fragment_url):
"""Take url and return filename part of it"""
if not fragment_url:
return fragment_url
return fragment_url.split('?')[0].split('/')[-1]
return fragment_url.split("?")[0].split("/")[-1]

async def _fill_queue(self):
last_fragment_timestamp = time.time()
Expand All @@ -56,7 +56,9 @@ async def _fill_queue(self):
frags_numbers = [self._get_fragment_id(url) for url in frags]

try:
new_idx = 1 + frags_numbers.index(self._get_fragment_id(last_fragment))
new_idx = 1 + frags_numbers.index(
self._get_fragment_id(last_fragment)
)
except ValueError:
new_idx = 0

Expand Down
8 changes: 5 additions & 3 deletions fc2_live_dl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ def _split_lines(self, text, width):
elif text.startswith("A|"):
return self.flatten(
[
argparse.HelpFormatter._split_lines(self, x, width)
if len(x) >= width
else x
(
argparse.HelpFormatter._split_lines(self, x, width)
if len(x) >= width
else x
)
for x in text[2:].splitlines()
]
)
Expand Down

0 comments on commit 1afab74

Please sign in to comment.