-
Notifications
You must be signed in to change notification settings - Fork 0
/
sovietscloset.py
135 lines (105 loc) · 3.46 KB
/
sovietscloset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import json
from dataclasses import dataclass
from datetime import datetime
from typing import Any, TypeVar
class SovietsCloset:
@dataclass
class BunnyCdn:
pullZone: str
videoLibraryId: str
@dataclass
class Video:
game: "SovietsCloset.Game"
playlist: "SovietsCloset.Playlist"
title: str
url: str
id: int
date: str
number: int
bunnyId: str | None
new: bool
def __eq__(self, other: "SovietsCloset.Video") -> bool:
return (
self.id == other.id
and self.date == other.date
and self.number == other.number
and self.bunnyId == other.bunnyId
and self.new == other.new
)
@dataclass
class Category:
title: str
url: str
name: str
slug: str
enabled: bool
recentlyUpdated: bool
@dataclass
class Playlist(Category):
game: "SovietsCloset.Game"
videos: list["SovietsCloset.Video"]
def __eq__(self, other: "SovietsCloset.Playlist") -> bool:
return SovietsCloset.Category.__eq__(self, other)
def __iter__(self):
yield from self.videos
def __getitem__(self, i: int):
return self.videos[i]
@dataclass
class Game(Category):
playlists: list["SovietsCloset.Playlist"]
def __eq__(self, other: "SovietsCloset.Game") -> bool:
return SovietsCloset.Category.__eq__(self, other)
def __iter__(self):
yield from self.playlists
def __getitem__(self, i: int):
return self.playlists[i]
@property
def videos(self):
for playlist in self.playlists:
yield from playlist
timestamp: datetime
bunnyCdn: BunnyCdn
games: list[Game]
_filename: str
_json: dict[str, Any]
def __init__(self, filename: str = "sovietscloset.json"):
self._filename = filename
self._json = json.load(open(filename))
self.timestamp = datetime.utcfromtimestamp(self._json["timestamp"])
self.bunny_cdn = SovietsCloset.BunnyCdn(**self._json["bunnyCdn"])
self.games = list()
for game in self._json["games"]:
playlists = list[SovietsCloset.Playlist]()
for playlist in game["playlists"]:
playlist["game"] = None
for i, video in enumerate(playlist["videos"]):
video["game"] = None
video["playlist"] = None
playlist["videos"][i] = SovietsCloset.Video(**video)
playlists.append(SovietsCloset.Playlist(**playlist))
game["playlists"] = playlists
self.games.append(SovietsCloset.Game(**game))
for game in self.games:
for playlist in game:
playlist.game = game
for video in playlist:
video.game = game
video.playlist = playlist
def __iter__(self):
yield from self.games
def __getitem__(self, i: int):
return self.games[i]
@property
def playlists(self):
for game in self.games:
yield from game.playlists
@property
def videos(self):
for playlist in self.playlists:
yield from playlist
SovietsClosetType = TypeVar(
"SovietsClosetType",
SovietsCloset.Game,
SovietsCloset.Playlist,
SovietsCloset.Video,
)