11# 18.07.25
22
33import os
4- import platform
5- import logging
64import shutil
75import zipfile
6+ import logging
87
98
109# External library
1312from rich .progress import Progress , SpinnerColumn , BarColumn , TextColumn , TimeRemainingColumn
1413
1514
15+ # Internal utilities
16+ from .binary_paths import binary_paths
17+
18+
1619# Variable
1720console = Console ()
1821
1922BENTO4_CONFIGURATION = {
2023 'windows' : {
21- 'base_dir' : lambda home : os .path .join (os .path .splitdrive (home )[0 ] + os .sep , 'binary' ),
2224 'download_url' : 'https://www.bok.net/Bento4/binaries/Bento4-SDK-{version}.{platform}.zip' ,
2325 'versions' : {
2426 'x64' : 'x86_64-microsoft-win32' ,
2729 'executables' : ['mp4decrypt.exe' ]
2830 },
2931 'darwin' : {
30- 'base_dir' : lambda home : os .path .join (home , 'Applications' , 'binary' ),
3132 'download_url' : 'https://www.bok.net/Bento4/binaries/Bento4-SDK-{version}.{platform}.zip' ,
3233 'versions' : {
3334 'x64' : 'universal-apple-macosx' ,
3637 'executables' : ['mp4decrypt' ]
3738 },
3839 'linux' : {
39- 'base_dir' : lambda home : os .path .join (home , '.local' , 'bin' , 'binary' ),
4040 'download_url' : 'https://www.bok.net/Bento4/binaries/Bento4-SDK-{version}.{platform}.zip' ,
4141 'versions' : {
4242 'x64' : 'x86_64-unknown-linux' ,
5050
5151class Bento4Downloader :
5252 def __init__ (self ):
53- self .os_name = platform .system (). lower ()
54- self .arch = self . _detect_arch ()
55- self .home_dir = os . path . expanduser ( '~' )
56- self .base_dir = BENTO4_CONFIGURATION [ self . os_name ][ 'base_dir' ]( self . home_dir )
53+ self .os_name = binary_paths .system
54+ self .arch = binary_paths . arch
55+ self .home_dir = binary_paths . home_dir
56+ self .base_dir = binary_paths . ensure_binary_directory ( )
5757 self .version = "1-6-0-641" # Latest stable version as of Nov 2023
58- os .makedirs (self .base_dir , exist_ok = True )
59-
60- def _detect_arch (self ) -> str :
61- machine = platform .machine ().lower ()
62- arch_map = {
63- 'amd64' : 'x64' ,
64- 'x86_64' : 'x64' ,
65- 'x64' : 'x64' ,
66- 'arm64' : 'arm64' ,
67- 'aarch64' : 'arm64' ,
68- 'x86' : 'x86' ,
69- 'i386' : 'x86' ,
70- 'i686' : 'x86'
71- }
72- return arch_map .get (machine , machine )
7358
7459 def _download_file (self , url : str , destination : str ) -> bool :
7560 try :
@@ -160,32 +145,29 @@ def download(self) -> list:
160145 console .print (f"[bold red]Error downloading Bento4: { str (e )} [/]" )
161146 return []
162147
148+
163149def check_mp4decrypt () -> str :
164150 """Check for mp4decrypt in the system and download if not found."""
165151 try :
166152 # First check if mp4decrypt is in PATH
167- mp4decrypt = "mp4decrypt.exe" if platform .system (). lower () == "windows" else "mp4decrypt"
153+ mp4decrypt = "mp4decrypt.exe" if binary_paths .system == "windows" else "mp4decrypt"
168154 mp4decrypt_path = shutil .which (mp4decrypt )
169155
170156 if mp4decrypt_path :
171157 return mp4decrypt_path
172158
173159 # If not found, check in binary directory
174- downloader = Bento4Downloader ()
175- base_dir = downloader .base_dir
176- local_path = os .path .join (base_dir , mp4decrypt )
160+ binary_dir = binary_paths .get_binary_directory ()
161+ local_path = os .path .join (binary_dir , mp4decrypt )
177162
178163 if os .path .exists (local_path ):
179164 return local_path
180165
181166 # Download if not found
167+ downloader = Bento4Downloader ()
182168 extracted_files = downloader .download ()
183169 return extracted_files [0 ] if extracted_files else None
184170
185171 except Exception as e :
186172 logging .error (f"Error checking or downloading mp4decrypt: { e } " )
187- return None
188-
189- except Exception as e :
190- logging .error (f"Error checking or downloading mp4decrypt: { e } " )
191- return None
173+ return None
0 commit comments