diff --git a/tcd/__init__.py b/tcd/__init__.py index 47de9cb..f003264 100644 --- a/tcd/__init__.py +++ b/tcd/__init__.py @@ -36,6 +36,7 @@ def main(): default=str(Path.home()) + '/.config/tcd/settings.json', help='Settings file location') parser.add_argument(f'--{Arguments.Name.DEBUG}', action='store_true', help='Print debug messages') + parser.add_argument(f'--{Arguments.Name.LOG}', action='store_true', help='Save log file') Arguments(parser.parse_args().__dict__) Settings(Arguments().settings_file, diff --git a/tcd/arguments.py b/tcd/arguments.py index 7446bed..e4e8643 100644 --- a/tcd/arguments.py +++ b/tcd/arguments.py @@ -27,6 +27,7 @@ class Name: FORMAT: str = 'format' TIMEZONE: str = 'timezone' DEBUG: str = 'debug' + LOG: str = 'log' def __init__(self, arguments: Optional[Dict[str, Union[str, bool, int]]] = None): """ @@ -49,6 +50,7 @@ def __init__(self, arguments: Optional[Dict[str, Union[str, bool, int]]] = None) self.print_formats: bool = arguments[Arguments.Name.FORMATS] self.print_version: bool = arguments[Arguments.Name.VERSION] self.output: str = arguments[Arguments.Name.OUTPUT] + self.log: bool = arguments[Arguments.Name.LOG] # Optional or prompted arguments self.client_id: Optional[str] = arguments[Arguments.Name.CLIENT_ID] diff --git a/tcd/downloader.py b/tcd/downloader.py index 8631729..412467f 100644 --- a/tcd/downloader.py +++ b/tcd/downloader.py @@ -88,6 +88,7 @@ def video(self, video: Video) -> None: # Special case for JSON # Build JSON object before writing it if 'json' in self.formats: + Logger().log('Downloading JSON data', Log.VERBOSE) output: str = Pipe(Settings().config['formats']['json']['output']).output(video.data) os.makedirs(os.path.dirname(output), exist_ok=True) @@ -129,6 +130,7 @@ def video(self, video: Video) -> None: # For each format (ignore json this time) for format_name in [x for x in self.formats if x not in ['json']]: + Logger().log(f'Formatting chat using: {format_name}', Log.VERBOSE) # Get (formatted_comment, comment), output comment_tuple, output = formatter.use(format_name) diff --git a/tcd/logger.py b/tcd/logger.py index 3f3215e..52e19cd 100644 --- a/tcd/logger.py +++ b/tcd/logger.py @@ -1,4 +1,5 @@ import time +from datetime import datetime from typing import List, Optional from .arguments import Arguments @@ -15,9 +16,9 @@ class Log: PROGRESS: str = 'progress' def __init__(self, message: str = '', log_type: str = REGULAR): - self.message: str = message + self.message: str = message.strip() self.type: str = log_type - self.timestamp: float = time.time() + self.timestamp: str = datetime.utcfromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S') def __str__(self) -> str: if self.type in [Log.DEBUG, Log.ERROR, Log.CRITICAL]: @@ -53,6 +54,10 @@ def log(self, message: str = '', log_type: str = Log.REGULAR, retain: bool = Tru if retain and log.type is not Log.PREVIEW: self.logs.append(log) + # Save log when debugging + if Arguments().log: + self.save() + # Print if self.should_print_type(log.type): print(log) @@ -75,7 +80,7 @@ def should_print_type(log_type: str) -> bool: return False # Progress - default output - if log_type == Log.PROGRESS and (Arguments().debug or Arguments().verbose or Arguments().preview): + if log_type == Log.PROGRESS and (Arguments().verbose or Arguments().preview): return False # Debug