Skip to content

Commit

Permalink
fix: correct logging implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
biodrone committed Sep 9, 2023
1 parent 3a4136a commit 485f585
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions streamdl_proto_srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
import os

from streamlink.exceptions import PluginError, NoPluginError
from streamlink.session import Streamlink
from streamlink.options import Options
Expand Down Expand Up @@ -55,25 +54,31 @@ def get_stream(r):
stream = session.streams(url=(r.site + "/" + r.user), options=options)

if not stream:
# logger.warning(f"No streams found for user {user}")
logger.warning(f"No streams found for user {r.user}")
return {"error": 404}
else:
try:
return {"url": stream[r.quality if r.quality else "best"].url}
except KeyError:
# logger.critical("Stream quality not found - exiting")
logger.critical("Stream quality not found - exiting")
return {"error": 414}
except NoPluginError:
# logger.warning(f"Streamlink is unable to handle the {url}")
logger.warning(f"Streamlink is unable to handle the {r.url}")
return {"error": 101}
except PluginError as err:
# logger.warning(f"Plugin error: {err}")
logger.warning(f"Plugin error: {err}")
return {"error": 102}


if __name__ == "__main__":
logging.basicConfig()
try:
serve()
except KeyboardInterrupt as e:
print("\nClosing Due To Keyboard Interrupt...")

logging.basicConfig(
level=os.environ.get("LOG_LEVEL", "DEBUG"),
format="%(asctime)s| %(name)s - %(levelname)s - %(message)s",
)

logger = logging.getLogger(__name__)

0 comments on commit 485f585

Please sign in to comment.