Skip to content

Commit

Permalink
feat(autofc2): log_level in config
Browse files Browse the repository at this point in the history
Fixes #20
  • Loading branch information
hizkifw committed Apr 12, 2022
1 parent df96899 commit b6f31b5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ Where the `autofc2.json` file looks like this:

```json
{
"autofc2": {
"log_level": "info"
},
"default_params": {
"quality": "3Mbps",
"latency": "mid",
Expand Down
28 changes: 27 additions & 1 deletion fc2_live_dl/autofc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def get_config(self):
raise ex
else:
self.logger.warn("Warning: unable to load config, using last valid one")
self.logger.warn(ex)
return self.last_valid_config

def clone(self, obj):
Expand Down Expand Up @@ -62,6 +63,30 @@ async def noop():
if channel_id not in channels:
tasks[channel_id].cancel()

async def config_watcher(self):
last_log_level = Logger.loglevel

while True:
await asyncio.sleep(1)

config = self.get_config()

if "autofc2" not in config:
continue

log_level = config["autofc2"]["log_level"]
if log_level == last_log_level:
continue

last_log_level = log_level

if log_level not in Logger.LOGLEVELS:
self.logger.error(f"Invalid log level {log_level}")
continue

Logger.loglevel = Logger.LOGLEVELS[log_level]
self.logger.info(f"Setting log level to {log_level}")

async def handle_channel(self, channel_id):
params = self.get_channel_params(channel_id)
async with FC2LiveDL(params) as fc2:
Expand All @@ -70,11 +95,12 @@ async def handle_channel(self, channel_id):
async def _main(self):
tasks = {}
sleep_task = None
config_task = asyncio.create_task(self.config_watcher())
try:
while True:
self.reload_channels_list(tasks)
sleep_task = asyncio.create_task(asyncio.sleep(1))
task_arr = [sleep_task]
task_arr = [config_task, sleep_task]
for channel in tasks.keys():
if tasks[channel].done():
tasks[channel] = asyncio.create_task(
Expand Down

0 comments on commit b6f31b5

Please sign in to comment.