From 7cffc27019248979b291ca3bb72af4da4f5e7cef Mon Sep 17 00:00:00 2001 From: mainaksamuel Date: Tue, 6 Jul 2021 14:19:38 +0300 Subject: [PATCH 1/6] Part 1 implementation --- python/src/video.py | 3 ++ python/src/video_player.py | 84 +++++++++++++++++++++++++++++++++----- 2 files changed, 77 insertions(+), 10 deletions(-) diff --git a/python/src/video.py b/python/src/video.py index 52da9082..f58a1a31 100644 --- a/python/src/video.py +++ b/python/src/video.py @@ -29,3 +29,6 @@ def video_id(self) -> str: def tags(self) -> Sequence[str]: """Returns the list of tags of a video.""" return self._tags + + def __str__(self): + return f"{self.title} ({self.video_id}) [{' '.join(self.tags)}]" diff --git a/python/src/video_player.py b/python/src/video_player.py index bb79af87..b57648d8 100644 --- a/python/src/video_player.py +++ b/python/src/video_player.py @@ -1,6 +1,21 @@ """A video player class.""" from .video_library import VideoLibrary +from .video import Video +import enum + + +class Messages(enum.Enum): + NOT_PLAYING = "No video is currently playing" + NOT_PAUSED = "Video is not paused" + NOT_EXISTS = "Video does not exist" + NOT_AVAILABLE = "No videos available" + + +class PlayingStatus(enum.Enum): + PLAYING = "PLAYING" + PAUSED = "PAUSED" + STOPPED = "STOPPED" class VideoPlayer: @@ -8,6 +23,8 @@ class VideoPlayer: def __init__(self): self._video_library = VideoLibrary() + self.currently_playing = None + self.playing_status = None def number_of_videos(self): num_videos = len(self._video_library.get_all_videos()) @@ -15,8 +32,14 @@ def number_of_videos(self): def show_all_videos(self): """Returns all videos.""" + print("Here's a list of all available videos:") + library = [] + for video in self._video_library.get_all_videos(): + library.append(video.__str__()) - print("show_all_videos needs implementation") + library.sort() + for video in library: + print(video) def play_video(self, video_id): """Plays the respective video. @@ -24,32 +47,73 @@ def play_video(self, video_id): Args: video_id: The video_id to be played. """ - print("play_video needs implementation") + video = self._video_library.get_video(video_id) + if not video: + print("Cannot play video:", Messages.NOT_EXISTS.value) + else: + self.play_known_video(video) + + def play_known_video(self, video: Video): + """Plays a known video that exists in the Video Library + + Args: + video: An already known video that exists in the video library + """ + if self.playing_status in [PlayingStatus.PLAYING, PlayingStatus.PAUSED]: + self.stop_video() + + print("Playing video:", video.title) + self.currently_playing = video + self.playing_status = PlayingStatus.PLAYING def stop_video(self): """Stops the current video.""" - - print("stop_video needs implementation") + if self.playing_status == PlayingStatus.STOPPED or not self.currently_playing: + print("Cannot stop video:", Messages.NOT_PLAYING.value) + else: + print("Stopping video:", self.currently_playing.title) + self.playing_status = PlayingStatus.STOPPED def play_random_video(self): """Plays a random video from the video library.""" + import random - print("play_random_video needs implementation") + try: + video = random.choice(self._video_library.get_all_videos()) + self.play_known_video(video) + except IndexError: + print(Messages.NOT_AVAILABLE.value) def pause_video(self): """Pauses the current video.""" - - print("pause_video needs implementation") + if self.playing_status == PlayingStatus.PLAYING: + print("Pausing video:", self.currently_playing.title) + self.playing_status = PlayingStatus.PAUSED + elif self.playing_status == PlayingStatus.PAUSED: + print("Video already paused:", self.currently_playing.title) + else: + print("Cannot pause video:", Messages.NOT_PLAYING.value) def continue_video(self): """Resumes playing the current video.""" - - print("continue_video needs implementation") + if self.playing_status == PlayingStatus.PAUSED: + print("Continuing video:", self.currently_playing.title) + self.playing_status = PlayingStatus.PLAYING + elif self.playing_status == PlayingStatus.STOPPED or not self.currently_playing: + print("Cannot continue video:", Messages.NOT_PLAYING.value) + else: + print("Cannot continue video:", Messages.NOT_PAUSED.value) def show_playing(self): """Displays video currently playing.""" + if self.playing_status == PlayingStatus.STOPPED or not self.currently_playing: + print(Messages.NOT_PLAYING.value) + + if self.playing_status == PlayingStatus.PLAYING: + print("Currently playing:", self.currently_playing.__str__()) - print("show_playing needs implementation") + if self.playing_status == PlayingStatus.PAUSED: + print("Currently playing:", self.currently_playing.__str__(), "-", PlayingStatus.PAUSED.value) def create_playlist(self, playlist_name): """Creates a playlist with a given name. From 1f380f60c612f01749442a5ed8d2f22ae9ae62aa Mon Sep 17 00:00:00 2001 From: mainaksamuel Date: Tue, 6 Jul 2021 19:00:11 +0300 Subject: [PATCH 2/6] Part2 - Implementation of Video Playlist --- python/src/video_player.py | 105 ++++++++++++++++++++++++++++------- python/src/video_playlist.py | 26 +++++++++ 2 files changed, 112 insertions(+), 19 deletions(-) diff --git a/python/src/video_player.py b/python/src/video_player.py index b57648d8..f4501f6f 100644 --- a/python/src/video_player.py +++ b/python/src/video_player.py @@ -2,14 +2,21 @@ from .video_library import VideoLibrary from .video import Video +from .video_playlist import Playlist + import enum class Messages(enum.Enum): - NOT_PLAYING = "No video is currently playing" - NOT_PAUSED = "Video is not paused" - NOT_EXISTS = "Video does not exist" - NOT_AVAILABLE = "No videos available" + NO_VIDEO_PLAYING = "No video is currently playing" + VIDEO_NOT_PAUSED = "Video is not paused" + VIDEO_NOT_EXISTS = "Video does not exist" + VIDEOS_NOT_AVAILABLE = "No videos available" + PLAYLIST_NAME_EXISTS = "A playlist with the same name already exists" + PLAYLIST_NOT_EXIST = "Playlist does not exist" + VIDEO_IN_PLAYLIST = "Video already added" + VIDEO_NOT_IN_PLAYLIST = "Video is not in playlist" + NO_VIDEOS_IN_PLAYLIST = "No videos here yet" class PlayingStatus(enum.Enum): @@ -25,6 +32,7 @@ def __init__(self): self._video_library = VideoLibrary() self.currently_playing = None self.playing_status = None + self.playlists = {} def number_of_videos(self): num_videos = len(self._video_library.get_all_videos()) @@ -49,7 +57,7 @@ def play_video(self, video_id): """ video = self._video_library.get_video(video_id) if not video: - print("Cannot play video:", Messages.NOT_EXISTS.value) + print("Cannot play video:", Messages.VIDEO_NOT_EXISTS.value) else: self.play_known_video(video) @@ -69,7 +77,7 @@ def play_known_video(self, video: Video): def stop_video(self): """Stops the current video.""" if self.playing_status == PlayingStatus.STOPPED or not self.currently_playing: - print("Cannot stop video:", Messages.NOT_PLAYING.value) + print("Cannot stop video:", Messages.NO_VIDEO_PLAYING.value) else: print("Stopping video:", self.currently_playing.title) self.playing_status = PlayingStatus.STOPPED @@ -82,7 +90,7 @@ def play_random_video(self): video = random.choice(self._video_library.get_all_videos()) self.play_known_video(video) except IndexError: - print(Messages.NOT_AVAILABLE.value) + print(Messages.VIDEOS_NOT_AVAILABLE.value) def pause_video(self): """Pauses the current video.""" @@ -92,7 +100,7 @@ def pause_video(self): elif self.playing_status == PlayingStatus.PAUSED: print("Video already paused:", self.currently_playing.title) else: - print("Cannot pause video:", Messages.NOT_PLAYING.value) + print("Cannot pause video:", Messages.NO_VIDEO_PLAYING.value) def continue_video(self): """Resumes playing the current video.""" @@ -100,14 +108,14 @@ def continue_video(self): print("Continuing video:", self.currently_playing.title) self.playing_status = PlayingStatus.PLAYING elif self.playing_status == PlayingStatus.STOPPED or not self.currently_playing: - print("Cannot continue video:", Messages.NOT_PLAYING.value) + print("Cannot continue video:", Messages.NO_VIDEO_PLAYING.value) else: - print("Cannot continue video:", Messages.NOT_PAUSED.value) + print("Cannot continue video:", Messages.VIDEO_NOT_PAUSED.value) def show_playing(self): """Displays video currently playing.""" if self.playing_status == PlayingStatus.STOPPED or not self.currently_playing: - print(Messages.NOT_PLAYING.value) + print(Messages.NO_VIDEO_PLAYING.value) if self.playing_status == PlayingStatus.PLAYING: print("Currently playing:", self.currently_playing.__str__()) @@ -121,7 +129,12 @@ def create_playlist(self, playlist_name): Args: playlist_name: The playlist name. """ - print("create_playlist needs implementation") + name = playlist_name.lower() + if not name in self.playlists: + self.playlists[name] = Playlist(playlist_name) + print("Successfully created new playlist:", self.playlists[name]) + else: + print("Cannot create playlist:", Messages.PLAYLIST_NAME_EXISTS.value) def add_to_playlist(self, playlist_name, video_id): """Adds a video to a playlist with a given name. @@ -130,12 +143,30 @@ def add_to_playlist(self, playlist_name, video_id): playlist_name: The playlist name. video_id: The video_id to be added. """ - print("add_to_playlist needs implementation") + video = self._video_library.get_video(video_id) + name = playlist_name.lower() + if name in self.playlists and video: + if self.playlists[name].add_video(video): + print(f"Added video to {playlist_name}:", video.title) + else: + print(f"Cannot add video to {playlist_name}:", Messages.VIDEO_IN_PLAYLIST.value ) + elif name not in self.playlists: + print(f"Cannot add video to {playlist_name}:", Messages.PLAYLIST_NOT_EXIST.value) + elif not video: + print(f"Cannot add video to {playlist_name}:", Messages.VIDEO_NOT_EXISTS.value) + else: + pass def show_all_playlists(self): """Display all playlists.""" - - print("show_all_playlists needs implementation") + if self.playlists: + playlist_names = list(self.playlists) + playlist_names.sort() + print("Showing all playlists:") + for name in playlist_names: + print(self.playlists[name]) + else: + print("No playlists exist yet") def show_playlist(self, playlist_name): """Display all videos in a playlist with a given name. @@ -143,7 +174,17 @@ def show_playlist(self, playlist_name): Args: playlist_name: The playlist name. """ - print("show_playlist needs implementation") + name = playlist_name.lower() + if name in self.playlists: + playlist = self.playlists[name] + print("Showing playlist:", playlist_name) + if len(playlist.videos) > 0: + for video in playlist.videos: + print(video) + else: + print(Messages.NO_VIDEOS_IN_PLAYLIST.value) + else: + print(f"Cannot show playlist {playlist_name}:", Messages.PLAYLIST_NOT_EXIST.value) def remove_from_playlist(self, playlist_name, video_id): """Removes a video to a playlist with a given name. @@ -152,7 +193,19 @@ def remove_from_playlist(self, playlist_name, video_id): playlist_name: The playlist name. video_id: The video_id to be removed. """ - print("remove_from_playlist needs implementation") + name = playlist_name.lower() + video = self._video_library.get_video(video_id) + if name in self.playlists: + playlist = self.playlists[name] + if video: + if self.playlists[name].remove_video(video): + print(f"Removed video from {playlist_name}:", video) + else: + print(f"Cannot remove video from {playlist}:", Messages.VIDEO_NOT_IN_PLAYLIST.value ) + else: + print(f"Cannot remove video from {playlist_name}:", Messages.VIDEO_NOT_EXISTS.value) + else: + print(f"Cannot remove video from {playlist_name}:", Messages.PLAYLIST_NOT_EXIST.value) def clear_playlist(self, playlist_name): """Removes all videos from a playlist with a given name. @@ -160,7 +213,16 @@ def clear_playlist(self, playlist_name): Args: playlist_name: The playlist name. """ - print("clears_playlist needs implementation") + name = playlist_name.lower() + if name in self.playlists: + playlist = self.playlists[name] + if len(playlist.videos) == 0: + print(Messages.NO_VIDEOS_IN_PLAYLIST.value) + else: + playlist.clear_videos() + print(f"Successfully removed all videos from {playlist_name}") + else: + print(f"Cannot clear playlist {playlist_name}:", Messages.PLAYLIST_NOT_EXIST.value) def delete_playlist(self, playlist_name): """Deletes a playlist with a given name. @@ -168,7 +230,12 @@ def delete_playlist(self, playlist_name): Args: playlist_name: The playlist name. """ - print("deletes_playlist needs implementation") + name = playlist_name.lower() + if name in self.playlists: + self.playlists.pop(name) + print("Deleted playlist:", name) + else: + print(f"Cannot delete playlist {playlist_name}:", Messages.PLAYLIST_NOT_EXIST.value) def search_videos(self, search_term): """Display all the videos whose titles contain the search_term. diff --git a/python/src/video_playlist.py b/python/src/video_playlist.py index 5836da4a..1b84b342 100644 --- a/python/src/video_playlist.py +++ b/python/src/video_playlist.py @@ -1,5 +1,31 @@ """A video playlist class.""" +from .video import Video class Playlist: """A class used to represent a Playlist.""" + + def __init__(self, playlist_name: str): + self.name = playlist_name + self.videos = [] + + def __str__(self) -> str: + return self.name + + def add_video(self, video: Video) -> bool: + """Adds a video to the playlist""" + if video in self.videos: + return False + self.videos.append(video) + return True + + def remove_video(self, video: Video) -> bool: + """Removes a video from the playlist""" + if video in self.videos: + self.videos.remove(video) + return True + return False + + def clear_videos(self): + """Removes all videos from playlist""" + self.videos.clear() From 917b78ec6b4c2418310c115eb19c0665bbc2a24b Mon Sep 17 00:00:00 2001 From: mainaksamuel Date: Tue, 6 Jul 2021 21:31:10 +0300 Subject: [PATCH 3/6] Part3 - Implemented Searching for videos --- python/src/video.py | 9 ++++++++ python/src/video_player.py | 44 ++++++++++++++++++++++++++++++++------ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/python/src/video.py b/python/src/video.py index f58a1a31..7aa000f6 100644 --- a/python/src/video.py +++ b/python/src/video.py @@ -32,3 +32,12 @@ def tags(self) -> Sequence[str]: def __str__(self): return f"{self.title} ({self.video_id}) [{' '.join(self.tags)}]" + + def __eq__(self, other): + return self.__str__() == other.__str__() + + def __lt__(self, other): + return self.__str__() < other.__str__() + + def __gt__(self, other): + return self.__str__() > other.__str__() diff --git a/python/src/video_player.py b/python/src/video_player.py index f4501f6f..63a17750 100644 --- a/python/src/video_player.py +++ b/python/src/video_player.py @@ -41,10 +41,7 @@ def number_of_videos(self): def show_all_videos(self): """Returns all videos.""" print("Here's a list of all available videos:") - library = [] - for video in self._video_library.get_all_videos(): - library.append(video.__str__()) - + library = self._video_library.get_all_videos() library.sort() for video in library: print(video) @@ -237,13 +234,36 @@ def delete_playlist(self, playlist_name): else: print(f"Cannot delete playlist {playlist_name}:", Messages.PLAYLIST_NOT_EXIST.value) + def play_selected_video(self, results: list[Video]): + print("Would you like to play any of the above? If yes, specify the number of the video.") + print("If your answer is not a valid number, we will assume it's a no.") + + user_choice = input().strip() + if user_choice.isdecimal() and int(user_choice) <= len(results): + user_choice = int(user_choice) + self.play_known_video(results[user_choice - 1]) + else: + pass + def search_videos(self, search_term): """Display all the videos whose titles contain the search_term. Args: search_term: The query to be used in search. """ - print("search_videos needs implementation") + results = [] + for video in self._video_library.get_all_videos(): + if search_term.lower() in video.title.lower(): + results.append(video) + + if len(results) == 0: + print(f"No search results for {search_term}") + else: + results.sort() + print(f"Here are the results for {search_term}:") + for (index, hit) in enumerate(results): + print(f"{index + 1}) {hit}") + self.play_selected_video(results) def search_videos_tag(self, video_tag): """Display all videos whose tags contains the provided tag. @@ -251,7 +271,19 @@ def search_videos_tag(self, video_tag): Args: video_tag: The video tag to be used in search. """ - print("search_videos_tag needs implementation") + results = [] + for video in self._video_library.get_all_videos(): + video_tags = [tag.lower() for tag in video.tags] + if video_tag.lower() in video_tags: + results.append(video) + if len(results) == 0: + print(f"No search results for {video_tag}:") + else: + results.sort() + print(f"Here are the results for {video_tag}:") + for (index, hit) in enumerate(results): + print(f"{index + 1}) {hit}") + self.play_selected_video(results) def flag_video(self, video_id, flag_reason=""): """Mark a video as flagged. From 699ae6d356b4ec4e565dadd6ffe5ccf211dbb1d9 Mon Sep 17 00:00:00 2001 From: mainaksamuel Date: Wed, 7 Jul 2021 00:28:53 +0300 Subject: [PATCH 4/6] Part4 - Flagging and Allowing Videos --- python/src/video.py | 14 ++++++ python/src/video_player.py | 88 +++++++++++++++++++++++++++----------- 2 files changed, 77 insertions(+), 25 deletions(-) diff --git a/python/src/video.py b/python/src/video.py index 7aa000f6..14a876fb 100644 --- a/python/src/video.py +++ b/python/src/video.py @@ -10,6 +10,7 @@ def __init__(self, video_title: str, video_id: str, video_tags: Sequence[str]): """Video constructor.""" self._title = video_title self._video_id = video_id + self._flag = None # Turn the tags into a tuple here so it's unmodifiable, # in case the caller changes the 'video_tags' they passed to us @@ -30,6 +31,19 @@ def tags(self) -> Sequence[str]: """Returns the list of tags of a video.""" return self._tags + @property + def flag(self): + """Returns a flag reason""" + return self._flag + + def set_flag(self, flag_reason: str): + """Flags video with a supplied reason""" + self._flag = flag_reason + + def allow(self): + """Remove flag from video""" + self._flag = None + def __str__(self): return f"{self.title} ({self.video_id}) [{' '.join(self.tags)}]" diff --git a/python/src/video_player.py b/python/src/video_player.py index 63a17750..fc9f67a1 100644 --- a/python/src/video_player.py +++ b/python/src/video_player.py @@ -17,12 +17,15 @@ class Messages(enum.Enum): VIDEO_IN_PLAYLIST = "Video already added" VIDEO_NOT_IN_PLAYLIST = "Video is not in playlist" NO_VIDEOS_IN_PLAYLIST = "No videos here yet" + VIDEO_IS_FLAGGED = "Video is already flagged" + VIDEO_NOT_FLAGGED = "Video is not flagged" -class PlayingStatus(enum.Enum): +class VideoStatus(enum.Enum): PLAYING = "PLAYING" PAUSED = "PAUSED" STOPPED = "STOPPED" + FLAGGED = "FLAGGED" class VideoPlayer: @@ -44,7 +47,10 @@ def show_all_videos(self): library = self._video_library.get_all_videos() library.sort() for video in library: - print(video) + if video.flag: + print(video, f"- {VideoStatus.FLAGGED.value} (reason: {video.flag})") + else: + print(video) def play_video(self, video_id): """Plays the respective video. @@ -64,61 +70,65 @@ def play_known_video(self, video: Video): Args: video: An already known video that exists in the video library """ - if self.playing_status in [PlayingStatus.PLAYING, PlayingStatus.PAUSED]: + if self.playing_status in [VideoStatus.PLAYING, VideoStatus.PAUSED]: self.stop_video() - print("Playing video:", video.title) - self.currently_playing = video - self.playing_status = PlayingStatus.PLAYING + if video.flag: + print(f"Cannot play video: Video is currently flagged (reason: {video.flag})") + else: + print("Playing video:", video.title) + self.currently_playing = video + self.playing_status = VideoStatus.PLAYING def stop_video(self): """Stops the current video.""" - if self.playing_status == PlayingStatus.STOPPED or not self.currently_playing: + if self.playing_status == VideoStatus.STOPPED or not self.currently_playing: print("Cannot stop video:", Messages.NO_VIDEO_PLAYING.value) else: print("Stopping video:", self.currently_playing.title) - self.playing_status = PlayingStatus.STOPPED + self.playing_status = VideoStatus.STOPPED def play_random_video(self): """Plays a random video from the video library.""" import random + unflagged_library = [video for video in self._video_library.get_all_videos() if not video.flag] try: - video = random.choice(self._video_library.get_all_videos()) + video = random.choice(unflagged_library) self.play_known_video(video) except IndexError: print(Messages.VIDEOS_NOT_AVAILABLE.value) def pause_video(self): """Pauses the current video.""" - if self.playing_status == PlayingStatus.PLAYING: + if self.playing_status == VideoStatus.PLAYING: print("Pausing video:", self.currently_playing.title) - self.playing_status = PlayingStatus.PAUSED - elif self.playing_status == PlayingStatus.PAUSED: + self.playing_status = VideoStatus.PAUSED + elif self.playing_status == VideoStatus.PAUSED: print("Video already paused:", self.currently_playing.title) else: print("Cannot pause video:", Messages.NO_VIDEO_PLAYING.value) def continue_video(self): """Resumes playing the current video.""" - if self.playing_status == PlayingStatus.PAUSED: + if self.playing_status == VideoStatus.PAUSED: print("Continuing video:", self.currently_playing.title) - self.playing_status = PlayingStatus.PLAYING - elif self.playing_status == PlayingStatus.STOPPED or not self.currently_playing: + self.playing_status = VideoStatus.PLAYING + elif self.playing_status == VideoStatus.STOPPED or not self.currently_playing: print("Cannot continue video:", Messages.NO_VIDEO_PLAYING.value) else: print("Cannot continue video:", Messages.VIDEO_NOT_PAUSED.value) def show_playing(self): """Displays video currently playing.""" - if self.playing_status == PlayingStatus.STOPPED or not self.currently_playing: + if self.playing_status == VideoStatus.STOPPED or not self.currently_playing: print(Messages.NO_VIDEO_PLAYING.value) - if self.playing_status == PlayingStatus.PLAYING: + if self.playing_status == VideoStatus.PLAYING: print("Currently playing:", self.currently_playing.__str__()) - if self.playing_status == PlayingStatus.PAUSED: - print("Currently playing:", self.currently_playing.__str__(), "-", PlayingStatus.PAUSED.value) + if self.playing_status == VideoStatus.PAUSED: + print("Currently playing:", self.currently_playing.__str__(), "-", VideoStatus.PAUSED.value) def create_playlist(self, playlist_name): """Creates a playlist with a given name. @@ -143,7 +153,9 @@ def add_to_playlist(self, playlist_name, video_id): video = self._video_library.get_video(video_id) name = playlist_name.lower() if name in self.playlists and video: - if self.playlists[name].add_video(video): + if video.flag: + print(f"Cannot add video to {playlist_name}: Video is currently flagged (reason: {video.flag})") + elif self.playlists[name].add_video(video): print(f"Added video to {playlist_name}:", video.title) else: print(f"Cannot add video to {playlist_name}:", Messages.VIDEO_IN_PLAYLIST.value ) @@ -177,7 +189,10 @@ def show_playlist(self, playlist_name): print("Showing playlist:", playlist_name) if len(playlist.videos) > 0: for video in playlist.videos: - print(video) + if video.flag: + print(video, f"- {VideoStatus.FLAGGED.value} (reason: {video.flag})") + else: + print(video) else: print(Messages.NO_VIDEOS_IN_PLAYLIST.value) else: @@ -252,7 +267,8 @@ def search_videos(self, search_term): search_term: The query to be used in search. """ results = [] - for video in self._video_library.get_all_videos(): + unflagged_library = [video for video in self._video_library.get_all_videos() if not video.flag] + for video in unflagged_library: if search_term.lower() in video.title.lower(): results.append(video) @@ -272,7 +288,8 @@ def search_videos_tag(self, video_tag): video_tag: The video tag to be used in search. """ results = [] - for video in self._video_library.get_all_videos(): + unflagged_library = [video for video in self._video_library.get_all_videos() if not video.flag] + for video in unflagged_library: video_tags = [tag.lower() for tag in video.tags] if video_tag.lower() in video_tags: results.append(video) @@ -292,7 +309,19 @@ def flag_video(self, video_id, flag_reason=""): video_id: The video_id to be flagged. flag_reason: Reason for flagging the video. """ - print("flag_video needs implementation") + video = self._video_library.get_video(video_id) + if video: + if not video.flag: + if flag_reason =="": + flag_reason = "Not supplied" + if self.playing_status in [VideoStatus.PLAYING, VideoStatus.PAUSED] and video == self.currently_playing: + self.stop_video() + video.set_flag(flag_reason) + print("Successfully flagged video:", video.title, f"(reason: {video.flag})") + else: + print("Cannot flag video:", Messages.VIDEO_IS_FLAGGED.value) + else: + print("Cannot flag video:", Messages.VIDEO_NOT_EXISTS.value) def allow_video(self, video_id): """Removes a flag from a video. @@ -300,4 +329,13 @@ def allow_video(self, video_id): Args: video_id: The video_id to be allowed again. """ - print("allow_video needs implementation") + video = self._video_library.get_video(video_id) + + if video : + if video.flag: + video.allow() + print("Successfully removed flag from video:", video.title) + elif not video.flag: + print("Cannot remove flag from video:", Messages.VIDEO_NOT_FLAGGED.value) + else: + print("Cannot remove flag from video:", Messages.VIDEO_NOT_EXISTS.value) From bf6135e8620f4f441d9b749266aa13e9d10e4809 Mon Sep 17 00:00:00 2001 From: mainaksamuel Date: Wed, 7 Jul 2021 01:16:52 +0300 Subject: [PATCH 5/6] Show number of videos in `show_playlist` command --- python/src/video_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/src/video_player.py b/python/src/video_player.py index fc9f67a1..f1b6a938 100644 --- a/python/src/video_player.py +++ b/python/src/video_player.py @@ -186,7 +186,7 @@ def show_playlist(self, playlist_name): name = playlist_name.lower() if name in self.playlists: playlist = self.playlists[name] - print("Showing playlist:", playlist_name) + print("Showing playlist:", playlist_name, f"({len(playlist.videos)}) video{''.join(['s' for _ in range(1) if len(playlist.videos) > 1])}") if len(playlist.videos) > 0: for video in playlist.videos: if video.flag: From fa46c46a1fb65c48afd6a16423ebcaee048360b9 Mon Sep 17 00:00:00 2001 From: mainaksamuel Date: Wed, 7 Jul 2021 01:22:24 +0300 Subject: [PATCH 6/6] Removed `__str__()` from method calls --- python/src/video_player.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/src/video_player.py b/python/src/video_player.py index f1b6a938..67cca837 100644 --- a/python/src/video_player.py +++ b/python/src/video_player.py @@ -125,10 +125,10 @@ def show_playing(self): print(Messages.NO_VIDEO_PLAYING.value) if self.playing_status == VideoStatus.PLAYING: - print("Currently playing:", self.currently_playing.__str__()) + print("Currently playing:", self.currently_playing) if self.playing_status == VideoStatus.PAUSED: - print("Currently playing:", self.currently_playing.__str__(), "-", VideoStatus.PAUSED.value) + print("Currently playing:", self.currently_playing, "-", VideoStatus.PAUSED.value) def create_playlist(self, playlist_name): """Creates a playlist with a given name.