-
Notifications
You must be signed in to change notification settings - Fork 0
/
video_class.py
39 lines (28 loc) · 1.14 KB
/
video_class.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
from dateutil.parser import parse
class Video:
def __init__(self, video_dict):
"""
Parses the json data given by Google Takeout into a Video
object.
:param video_dict: The dict for a watched video
"""
self.title = video_dict.get("title")
self.url = video_dict.get("titleUrl")
time_str = video_dict.get("time")
self.time = parse(time_str) if time_str else None
sub_info = video_dict.get("subtitles")
self.channel_name = sub_info[0].get("name") if sub_info else "Unknown"
self.channel_url = sub_info[0].get("url") if sub_info else "Unknown"
def __repr__(self):
return f'{self.title} by @{self.channel_name}'
def __str__(self):
return self.__repr__()
def __eq__(self, other):
return self.url == other.url
def __hash__(self):
return hash(self.url)
class VideoByChannel(Video):
def __eq__(self, other):
return self.channel_url == other.channel_url
def __hash__(self):
return hash(self.channel_url if self.channel_url is not "Unknown" else self.url)