13 Commits

Author SHA1 Message Date
fbc843ad6d Finished the History class 2025-02-26 20:36:11 +01:00
DjMaestr0
166712515d updated History class 2025-02-19 08:34:32 +01:00
DjMaestr0
bafa23131a Merge branch 'main' of https://git.umbrasolis.de/fedir/shadowtube into history-class 2025-02-19 08:30:30 +01:00
DjMaestr0
782ab1783d updating branch 2025-02-18 21:34:33 +01:00
72fd5457e6 Merge pull request 'Added a license header to types.py.' (#10) from License_headers into main
Reviewed-on: #10
2025-02-18 20:21:13 +01:00
6c6c09a158 Added a license header to types.py. 2025-02-18 20:19:39 +01:00
82f8a61d16 Merge pull request '#6: Implemented the video class.' (#7) from Video_class into main
Reviewed-on: #7
2025-02-18 19:39:13 +01:00
f8e1012f3e Merge branch 'main' into Video_class 2025-02-18 19:38:46 +01:00
0dc358d053 Merge pull request 'Added separate History class' (#5) from history-class into main
Reviewed-on: #5
2025-02-18 18:43:53 +01:00
DjMaestr0
7abf7a939f Adding history class 2025-02-18 18:29:29 +01:00
DjMaestr0
172b29e56a history-class
e Please enter the commit message for your changes. Lines starting
here is the history class
2025-02-18 18:23:24 +01:00
bdcaf3747b Merge pull request '#2: Added license headers.' (#3) from License_headers into main
Reviewed-on: #3
2025-02-18 17:50:20 +01:00
8f802ed046 Added license headers. 2025-02-18 17:46:37 +01:00
7 changed files with 178 additions and 0 deletions

View File

@@ -1,3 +1,19 @@
#
# Copyright (c) 2025 Fedir Kovalov.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import shadowtube.preprocess as prep
import shadowtube.recommend as rec

View File

@@ -1,3 +1,19 @@
#
# Copyright (c) 2025 Fedir Kovalov.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import requests
from io import BytesIO
from PIL import Image, ImageTk

View File

@@ -1,2 +1,18 @@
#
# Copyright (c) 2025 Fedir Kovalov.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from .preprocess import *
from .recommend import *

81
shadowtube/history.py Normal file
View File

@@ -0,0 +1,81 @@
import json
from typing import Iterator
from .types import Video
from abc import ABC, abstractmethod
class History(ABC): # Abstract class
@abstractmethod
def __len__(self) -> int:
pass
@staticmethod
def parse_history(filename: str) -> "History":
return FreeTubeHistory(filename)
@abstractmethod
def is_this_type(self, filename: str) -> bool:
pass
@abstractmethod
def get_video(self, index: int) -> Video:
pass
@abstractmethod
def __iter__(self) -> Iterator[Video]:
pass
class FreeTubeHistory(History):
def __init__(self, filename: str) -> None:
parsed_data = []
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 = FreeTubeHistory._fix_unquoted_values(line)
parsed_data.append(json.loads(fixed_line))
self._parsed_data = parsed_data
@staticmethod
def _fix_unquoted_values(line: str) -> str:
"""Attempts to fix unquoted values by adding quotes around them."""
import re
def replacer(match):
key, value = match.groups()
if not (value.startswith('"') and value.endswith('"')):
value = f'"{value}"' # Add quotes around the value
return f'"{key}":{value}'
fixed_line = re.sub(r'"(\w+)":(\w+)', replacer, line)
return fixed_line
@staticmethod
def _to_video(entry) -> Video:
return Video(
id=entry["videoId"],
title=entry["title"],
description=entry["description"],
watch_time=entry["timeWatched"],
watch_progress=entry["watchProgress"],
)
def __len__(self):
return len(self._parsed_data)
def is_this_type(self, filename: str) -> bool:
raise NotImplementedError()
def get_video(self, index: int) -> Video:
return FreeTubeHistory._to_video(self._parsed_data[index])
def __iter__(self):
for entry in self._parsed_data:
yield FreeTubeHistory._to_video(entry)

View File

@@ -1,3 +1,19 @@
#
# Copyright (c) 2025 Fedir Kovalov.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import json
import math
from typing import List

View File

@@ -1,3 +1,19 @@
#
# Copyright (c) 2025 Fedir Kovalov.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import sqlite3
from random import sample

View File

@@ -1,3 +1,20 @@
#
# Copyright (c) 2025 Fedir Kovalov.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
class Video:
def __init__(
self,