Skip to content

Commit aa66345

Browse files
committed
🔧 Adding
Facade Pattern
1 parent ca3a638 commit aa66345

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Subsystem: Complex Video conversion Library
2+
3+
class VideoFile:
4+
def __init__(self, filename):
5+
self.filename = filename
6+
print(f"[VideoFile] Loaded video file: {filename}")
7+
8+
9+
class OggCompressionCodec:
10+
def __str__(self):
11+
return "OggCompressionCodec"
12+
13+
14+
class MPEG4CompressionCodec:
15+
def __str__(self):
16+
return "MPEG4CompressionCodec"
17+
18+
19+
class CodecFactory:
20+
def extract(self, file: VideoFile):
21+
print(f"[CodecFactory] Extracting codec from {file.filename}")
22+
return OggCompressionCodec() if file.filename.endswith(".ogg") else MPEG4CompressionCodec()
23+
24+
25+
class BitrateReader:
26+
@staticmethod
27+
def read(filename: str, codec):
28+
print(f"[BitrateReader] Reading from {filename} with codec {codec}")
29+
return f"Buffered_data_from_{filename}"
30+
31+
@staticmethod
32+
def convert(buffer: str, codec):
33+
print(f"[BitrateReader] Converting buffer with {codec}")
34+
return f"converted_data_to_{codec}"
35+
36+
37+
class AudioMixer:
38+
def fix(self, result: str):
39+
print(f"[AudioMixer] Fixing audio in result")
40+
return f"audio_fixed_{result}"
41+
42+
43+
# Facade
44+
45+
class VideoConverter:
46+
def convert(self, filename: str, format: str):
47+
print(f"\n[VideoConverter] Starting conversion of {filename} to {format}")
48+
49+
file = VideoFile(filename)
50+
source_codec = CodecFactory().extract(file)
51+
52+
if format == "mp4":
53+
destination_codec = MPEG4CompressionCodec()
54+
else:
55+
destination_codec = OggCompressionCodec()
56+
57+
buffer = BitrateReader.read(filename, source_codec)
58+
result = BitrateReader.convert(buffer, destination_codec)
59+
result = AudioMixer().fix(result)
60+
61+
print(f"[VideoConverter] Conversion finished: {result}")
62+
return result
63+
64+
65+
# Client Code
66+
67+
if __name__ == "__main__":
68+
converter = VideoConverter()
69+
output = converter.convert("funny_cat.ogg", "mp4")
70+
print(f"[Application] Final Output: {output}")

0 commit comments

Comments
 (0)