From 166712515df699f3f53cf9331867d4238d15814c Mon Sep 17 00:00:00 2001 From: DjMaestr0 Date: Wed, 19 Feb 2025 08:34:32 +0100 Subject: [PATCH] updated History class --- shadowtube/history.py | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/shadowtube/history.py b/shadowtube/history.py index fbc2766..84b0702 100644 --- a/shadowtube/history.py +++ b/shadowtube/history.py @@ -1,18 +1,36 @@ +import json + class History: #Abstract class - def __init__(self, filename): - self.history = list() + def __init__(self, filename: str): + #self.history = list() + pass def __size__(self): - return len(history) - - def parse_history(self, filename): - return history + pass - def is_this_type(self, filename): # bool function, - return false # returns false if Youtube history + @staticmethod + def parse_history(self, filename: str): + parsed_data = [] - def get_video(self, index): - return history[index] + with open(filename, "r", encoding="utf-8") as file: + for line in file: + line = line.strip() + if not line: + continue + try: + parsed_data.append(json.loads(line)) + except json.JSONDecodeError: + fixed_line = fix_unquoted_values(line) + parsed_data.append(json.loads(fixed_line)) + + return parsed_data + + def is_this_type(self, filename: str): # bool function, + pass # returns false if Youtube history + + def get_video(self, index: int): + pass def __iter__(self): - return iter(history) + pass +