REFACTOR: Path manager now creates directories
This commit is contained in:
@@ -1,20 +1,53 @@
|
|||||||
|
import os
|
||||||
# Description: This file contains the PathManager class which is responsible for managing the paths of the stream data.
|
# Description: This file contains the PathManager class which is responsible for managing the paths of the stream data.
|
||||||
|
|
||||||
class PathManager():
|
class PathManager():
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.root_path = "stream_data"
|
||||||
|
self.vods_path = os.path.join(self.root_path, "vods")
|
||||||
|
self.stream_path = os.path.join(self.root_path, "stream")
|
||||||
|
self.profile_pictures_path = os.path.join(self.root_path, "profile_pictures")
|
||||||
|
|
||||||
|
self._create_root_directories()
|
||||||
|
|
||||||
|
def _create_root_directories(self):
|
||||||
|
"""
|
||||||
|
Create directories for stream data if they do not exist
|
||||||
|
"""
|
||||||
|
if not os.path.exists(self.vods_path):
|
||||||
|
os.makedirs(self.vods_path)
|
||||||
|
|
||||||
|
if not os.path.exists(self.stream_path):
|
||||||
|
os.makedirs(self.stream_path)
|
||||||
|
|
||||||
|
if not os.path.exists(self.profile_pictures_path):
|
||||||
|
os.makedirs(self.profile_pictures_path)
|
||||||
|
|
||||||
|
# Fix permissions
|
||||||
|
os.chmod(self.vods_path, 0o777)
|
||||||
|
os.chmod(self.stream_path, 0o777)
|
||||||
|
os.chmod(self.profile_pictures_path, 0o777)
|
||||||
|
|
||||||
def get_vods_path(self, username):
|
def get_vods_path(self, username):
|
||||||
return f"stream_data/vods/{username}"
|
return os.path.join(self.vods_path, username)
|
||||||
|
|
||||||
def get_stream_path(self, username):
|
def get_stream_path(self, username):
|
||||||
return f"stream_data/stream/{username}"
|
return os.path.join(self.stream_path, username)
|
||||||
|
|
||||||
def get_stream_file_path(self, username):
|
def get_stream_file_path(self, username):
|
||||||
return f"{self.get_stream_path(username)}/index.m3u8"
|
return os.path.join(self.get_stream_path(username), "index.m3u8")
|
||||||
|
|
||||||
def get_current_stream_thumbnail_file_path(self, username):
|
def get_current_stream_thumbnail_file_path(self, username):
|
||||||
return f"{self.get_stream_path(username)}/index.jpg"
|
return os.path.join(self.get_stream_path(username), "index.jpg")
|
||||||
|
|
||||||
def get_vod_file_path(self, username, vod_id):
|
def get_vod_file_path(self, username, vod_id):
|
||||||
return f"{self.get_vods_path(username)}/{vod_id}.mp4"
|
return os.path.join(self.get_vods_path(username), f"{vod_id}.mp4")
|
||||||
|
|
||||||
def get_vod_thumbnail_file_path(self, username, vod_id):
|
def get_vod_thumbnail_file_path(self, username, vod_id):
|
||||||
return f"{self.get_vods_path(username)}/{vod_id}.jpg"
|
return os.path.join(self.get_vods_path(username), f"{vod_id}.png")
|
||||||
|
|
||||||
|
def get_profile_picture_file_path(self, username):
|
||||||
|
return os.path.join(self.profile_pictures_path, f"{username}.png")
|
||||||
|
|
||||||
|
def get_profile_picture_path(self):
|
||||||
|
return self.profile_pictures_path
|
||||||
@@ -143,7 +143,7 @@ def get_vod_tags(vod_id: int):
|
|||||||
""", (vod_id,))
|
""", (vod_id,))
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
def create_local_directories(username: str):
|
def create_user_directories(username: str):
|
||||||
"""
|
"""
|
||||||
Create directories for user stream data if they do not exist
|
Create directories for user stream data if they do not exist
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user