-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathvideo_library.py
More file actions
67 lines (52 loc) · 1.96 KB
/
video_library.py
File metadata and controls
67 lines (52 loc) · 1.96 KB
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
"""A video library class."""
from .video import Video
from pathlib import Path
import csv
# Helper Wrapper around CSV reader to strip whitespace from around
# each item.
def _csv_reader_with_strip(reader):
yield from ((item.strip() for item in line) for line in reader)
class VideoLibrary:
"""A class used to represent a Video Library."""
def __init__(self):
"""The VideoLibrary class is initialized."""
self._is_playing = None
self._is_paused = False
self._videos = {}
with open(Path(__file__).parent / "videos.txt") as video_file:
reader = _csv_reader_with_strip(
csv.reader(video_file, delimiter="|"))
for video_info in reader:
title, url, tags = video_info
self._videos[url] = Video(
title,
url,
[tag.strip() for tag in tags.split(",")] if tags else [],
)
def get_all_videos(self):
"""Returns all available video information from the video library."""
return list(self._videos.values())
def get_video(self, video_id):
"""Returns the video object (title, url, tags) from the video library.
Args:
video_id: The video url.
Returns:
The Video object for the requested video_id. None if the video
does not exist.
"""
return self._videos.get(video_id, None)
def get_video_playing(self):
"""Returns the playing video id."""
return self._is_playing
def is_video_paused(self):
"""Returns the paused video id."""
return self._is_paused
def set_video_playing(self, video_id):
"""Sets self._is_palying the respective video_id.
Args:
video_id: The video_id to be played.
"""
self._is_playing = video_id
def set_video_paused(self, status):
"""Swiches self._is_paused."""
self._is_paused = status